1.創建一個員工表
字段 屬性
id 整形(int)
name 字符串(varchar)(長度為20)
gender 字符串(長度為2)
birthday 日期型(date)
email 字符串(長度為10)
remark 字符串(長度為50)
CREATE TABLE workers(
sid INT,
sname VARCHAR(20),
gender VARCHAR(2),
birthday DATE,
email VARCHAR(10),
remark VARCHAR(50)
);
2.修改表練習
2.1 在員工表基礎上增加age列
2.2 修改email列長度為50
2.3 刪除remark列
2.4 列名name修改為username
ALTER TABLE workers ADD COLUMN age INT; ALTER TABLE workers MODIFY COLUMN email VARCHAR(50); ALTER TABLE workers DROP COLUMN remark; ALTER TABLE workers CHANGE COLUMN sname username VARCHAR(20);
3 在員工表上練習數據的增刪改操作
/*查看員工表格的所有數據*/ SELECT * FROM workers; /*查看員工表格的sid,username,age數據*/ SELECT sid,username,age FROM workers; /*查看員工表格的username,age數據*/ SELECT username,age FROM workers; /* 將以下數據填入表格*/ INSERT INTO workers VALUES(1,'張三豐','男','1367-10-21','12321222@qq.com',102); INSERT INTO workers VALUES(2,'達摩','男','1227-4-15','1121213242@126.com',54); INSERT INTO workers VALUES(3,'梅超風','女','1547-6-1','232442@163.com',44); INSERT INTO workers VALUES(4,'三體星人','未知','3012-8-15','12345678@fly.com',2000); INSERT INTO workers VALUES(5,'超級賽亞人','男','1985-2-3','whosyourdaday@sina.com',25); /*將sid為4的那一行的username改為“弗利薩”*/ UPDATE workers SET username = '弗利薩' WHERE sid = 4; /*刪除age為2000的那一行*/ DELETE FROM workers WHERE age = 2000; /*將sid為4的那一行的age設為250*/ UPDATE workers SET age = 250 WHERE sid =4; /*將sid為5的那一行的username改為“孫悟空”,年齡改為26*/ UPDATE workers SET username = '孫悟空',age = '26' WHERE sid = 5;
