数据库增删改查sql语句示例
时间: 2024-08-12 16:06:06 浏览: 25
数据库操作通常使用SQL(Structured Query Language)语言来实现。下面是一些基本的增删改查(CRUD)操作的SQL示例:
1. **增加数据(Insert)**:
```sql
INSERT INTO table_name (column1, column2, ...)
VALUES (value1, value2, ...);
```
例如,在用户表`users`中添加新用户:
```sql
INSERT INTO users (username, password) VALUES ('JohnDoe', 'password123');
```
2. **删除数据(Delete)**:
```sql
DELETE FROM table_name WHERE condition;
```
删除用户名为'JohnDoe'的用户:
```sql
DELETE FROM users WHERE username = 'JohnDoe';
```
3. **更新数据(Update)**:
```sql
UPDATE table_name SET column1 = new_value, column2 = new_value WHERE condition;
```
更新'JohnDoe'的密码为'newPassword':
```sql
UPDATE users SET password = 'newPassword' WHERE username = 'JohnDoe';
```
4. **查询数据(Select)**:
```sql
SELECT column1, column2,... FROM table_name WHERE condition;
```
获取所有信息的用户列表:
```sql
SELECT * FROM users;
```
或者获取特定条件下的用户:
```sql
SELECT * FROM users WHERE username LIKE '%John%';
```
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)