個人總結:Sql(二:增&刪&改|I&D&U)
阿新 • • 發佈:2018-12-19
Insert
insert into TNAME value(V1,V2,V3);
或
insert into TNAME values(V1,V2,V3);
或
insert into TNAME(C1,C2,C3…) value(V1,V2,V3…);
或
insert into TNAME(C1,C2,C3…) values(V1,V2,V3…);
一次插入多個值得時候:
insert into TNAME(C1,C2,C3…) value(V1_1,V1_2,V1_3…), (V2_1,V2_2,V2_3…);
或
insert into TNAME(C1,C2,C3…) values(V1_1,V1_2,V1_3…), (V2_1,V2_2,V2_3…);
關於value 和values,事實上都是可以混用的,具體區別,請參照部落格:
https://blog.csdn.net/qq_26683009/article/details/52526834
Delete
Delete from TNAME where CONDITION; 刪除所有記錄 delete from TNAME; delete * from TNAME; (MariaDB報錯) 刪除所有記錄時,delete from TNAME和truncate TNAME區別 delete是逐條刪除,效率低;truncate是整體刪除,效率高 如果有自增長的id列: delete不重置id;truncate重置id
Update
update TNAME set CNAME = V1 where CONDITION;