【MySQL】:表操作语法大全
创建表:
CREATE TABLE IF NOT EXISTS table_name(
column1 datatype,
column2 datatype,
column3 datatype,
....
);
删除表:
DROP TABLE IF EXISTS table_name;
插入数据:
INSERT INTO table_name (column1, column2, column3, ...)
VALUES (value1, value2, value3, ...);
查询数据:
SELECT column1, column2, ...
FROM table_name
WHERE condition;
更新数据:
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;
删除数据:
DELETE FROM table_name
WHERE condition;
创建索引:
CREATE INDEX index_name ON table_name (column1, column2, ...);
删除索引:
DROP INDEX index_name ON table_name;
创建视图:
CREATE VIEW view_name AS
SELECT column1, column2, ...
FROM table_name
WHERE condition;
删除视图:
DROP VIEW IF EXISTS view_name;
创建外键约束:
ALTER TABLE table_name
ADD CONSTRAINT fk_constraint_name
FOREIGN KEY (column1)
REFERENCES parent_table_name(parent_column1);
删除外键约束:
ALTER TABLE table_name
DROP FOREIGN KEY fk_constraint_name;
请根据具体需求选择和修改以上语句。
评论已关闭