以下是经常用到的SQL增删改语句(适用于MySQL):
插入数据:
INSERT INTO table_name <col_name> VALUES (...)
插入单行数据:INSERT INTO ... VALUES (...)
插入多行数据:INSERT INTO ... VALUES (...), (...)
更新数据:
UPDATE table_name SET col_name=... WHERE ...
更新单行数据:UPDATE ... SET ... WHERE ...
更新多行数据:UPDATE ... SET ..., ... WHERE ...
删除数据:
DELETE FROM table_name WHERE ...
变更表(增加或删除某列):
ALTER TABLE table_name ADD COLUMN ...
ALTER TABLE table_name DROP COLUMN ...
变更表(变更某列的数据类型等):
ALTER TABLE table_name MODIFY COLUMN ...
变更表(增加或删除外键):
ALTER TABLE table_name ADD FOREIGN KEY ...
ALTER TABLE table_name DROP FOREIGN KEY ...
更改表名:
RENAME TABLE ... TO ...
拷贝表内容:
INSERT INTO table_name2 (col_name) SELECT col_name FROM table_name1
更改视图:
CREATE OR REPLACE VIEW view_name SELECT ...