MySQL:数据的增删改查
MySQL中的数据操作主要涉及到增加(Create)、检索(Read)、更新(Update)和删除(Delete),简称CRUD操作。以下是每个操作的基本SQL语句示例:
- 插入数据(Create)
INSERT INTO table_name (column1, column2, column3, ...)
VALUES (value1, value2, value3, ...);
- 查询数据(Read)
-- 查询所有数据
SELECT * FROM table_name;
-- 查询特定列
SELECT column1, column2 FROM table_name;
-- 带条件查询
SELECT * FROM table_name WHERE condition;
-- 排序查询
SELECT * FROM table_name ORDER BY column1, column2 DESC;
-- 限制查询结果数量
SELECT * FROM table_name LIMIT number;
- 更新数据(Update)
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;
- 删除数据(Delete)
DELETE FROM table_name WHERE condition;
请根据实际需求替换table_name
、column1
, column2
, ...
、value1
, value2
, ...
和condition
。
评论已关闭