一次插入操做只插入一行數據code
insert into [tablename](listname1,listname2,......) values (value1,value2,......); /* 插入一條數據 */ insert into t_students(id,name,age) values(10,'敏敏',24); /* 插入多條數據MySQL特有的 */ insert into t_students(id,name,age) values(10,'YY',24),(10,'MM',24),(10,'HH',24); /* 插入查詢結果 */ insert into t_students(name) select name from t_students;
不能更改主鍵!!!table
update [tablename] set [listname]=value where [條件]; /* 將年齡大於25的改成18 */ update t_students set age=18 where age >= 25;
若是 省略where,則整個表的數據都會被修改
delete from [tablename] where [條件]; /* 刪除年齡爲18的數據 */
若是 省略where,則整個表的數據都會被刪除!!!
alter table [tablename] add [listname] [數據類型] after [listname插入位置] /* 在表的最後追加列 address */ alter table students add address char(60); /* 在名爲 age 的列後插入列 birthday */ alter table students add birthday date after age;
alter table [tablename] change [listname] [newlistname] [新數據類型]; /* 將表 tel 列更名爲 telphone */ alter table students change tel telphone char(13) default "-"; /*將 name 列的數據類型改成 char(16) */ alter table students change name name char(16) not null; /* 當字段只包含空值時,類型大小均可以修改 */ alter table [tablename] modify [listname] [數據類型];
alter table [tablename] drop [listname]; /* 刪除 birthday 列 */ alter table students drop birthday;
alter table [tablename] rename [newtablename]; /* 重命名 students 表爲 workmates */ alter table students rename workmates;