mysql语句大全及用法
时间: 2023-09-25 20:15:24 浏览: 49
mysql语句大全
这里提供一些常用的 MySQL 语句及其用法:
1. 创建数据库
```
CREATE DATABASE database_name;
```
2. 删除数据库
```
DROP DATABASE database_name;
```
3. 切换数据库
```
USE database_name;
```
4. 显示所有数据库
```
SHOW DATABASES;
```
5. 创建表
```
CREATE TABLE table_name (
column1 datatype,
column2 datatype,
column3 datatype,
....
);
```
6. 删除表
```
DROP TABLE table_name;
```
7. 显示表结构
```
DESCRIBE table_name;
```
8. 插入数据
```
INSERT INTO table_name (column1, column2, column3, ...)
VALUES (value1, value2, value3, ...);
```
9. 更新数据
```
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE some_column = some_value;
```
10. 删除数据
```
DELETE FROM table_name
WHERE some_column = some_value;
```
11. 查询数据
```
SELECT column1, column2, ...
FROM table_name
WHERE some_column = some_value;
```
12. 模糊查询
```
SELECT column1, column2, ...
FROM table_name
WHERE columnN LIKE pattern;
```
13. 排序
```
SELECT column1, column2, ...
FROM table_name
ORDER BY column1 ASC/DESC, column2 ASC/DESC, ...;
```
14. 分组
```
SELECT column1, COUNT(column2)
FROM table_name
GROUP BY column1;
```
15. 连接
```
SELECT column1, column2, ...
FROM table1
JOIN table2 ON table1.column = table2.column;
```
这些语句只是 MySQL 语言的冰山一角,MySQL 还有很多其他的用法和细节需要学习。
阅读全文