MySQL增删改查基本语法
时间: 2024-10-15 16:06:32 浏览: 36
MySQL是一种关系型数据库管理系统,其SQL(Structured Query Language)用于对数据进行增删改查操作。以下是四个基本的SQL语句:
1. **插入(INSERT)**:
```
INSERT INTO table_name (column1, column2,...)
VALUES (value1, value2,...);
```
示例:向名为`users`的表添加新用户记录
```sql
INSERT INTO users (username, password) VALUES ('john', 'pass123');
```
2. **删除(DELETE)**:
```
DELETE FROM table_name WHERE condition;
```
示例:删除`users`表中用户名为'john'的记录
```sql
DELETE FROM users WHERE username = 'john';
```
3. **更新(UPDATE)**:
```
UPDATE table_name SET column1 = value1, column2 = value2 WHERE condition;
```
示例:将`users`表中username为'john'的密码修改为'newpass'
```sql
UPDATE users SET password = 'newpass' WHERE username = 'john';
```
4. **查询(SELECT)**:
```
SELECT column1, column2,... FROM table_name WHERE condition;
```
示例:获取`users`表所有字段的信息
```sql
SELECT * FROM users;
```
阅读全文