数据操作
SELECT
- 功能:用于从数据库表中检索数据行和列。
- 基本语法:
SELECT column_name(s) FROM table_name WHERE condition;
- 示例:
- 检索所有列:
SELECT * FROM table_name;
- 根据条件筛选:
SELECT column_name FROM table_name WHERE condition;
- 使用逻辑运算符:
SELECT column_name FROM table_name WHERE condition1 AND/OR condition2;
INSERT
INSERT INTO table_name (column1, column2, column3,...) VALUES (value1, value2, value3,...);
- 示例:
- 插入单行记录:
INSERT INTO table_name (column1, column2) VALUES ('value1', 'value2');
- 插入多行记录:
INSERT INTO table_name (column1, column2) VALUES ('value1', 'value2'), ('value3', 'value4');
DELETE
DELETE FROM table_name [WHERE condition];
- 示例:
- 删除所有记录:
DELETE FROM table_name;
- 根据条件删除记录:
DELETE FROM table_name WHERE condition;
UPDATE
UPDATE table_name SET column1 = value1, column2 = value2 WHERE condition;
- 示例:
- 更新特定记录:
UPDATE table_name SET column1 = 'new_value' WHERE condition;