当前位置:网站首页>数据库SQL语句汇总,持续更新......
数据库SQL语句汇总,持续更新......
2022-07-04 03:32:00 【反内卷大官人】
目录
1 SQL语句 数据库相关操作
目标:
会使用SQL语句实现数据库的新建、使用、编辑、删除、关闭操作。
1.1 新建和打开数据库
新建数据库
| 语法格式 | 基本用法 create database <数据库名> | 带参数的语法格式: create database [if not exists] <数据库名> [charset 字符集] [collate 排序规则] |
|---|---|---|
| 回响 | ||
| 参数说明 | if not exists —— 如果数据库不存在的话就创建,存在的话也不会报错; charset 字符集 —— 默认值为utf8mb4; collate 排序规则 —— 默认值为utf8mb4_0900_ai_ci; | |
| 举例说明 | # 创建一个叫 student 的数据库 create database student; | # 创建一个叫 teacher 的数据库,重复输入命令不出错 create database if not exists teacher; # 创建一个叫 school 的数据库,指定字符集和排序规则 create database if not exists school charset utf8mb4 collate utf8_general_ci; |
| 备注 | 重复输入命令会报错 | 字符集即是为了兼容各国的文字而做的编码,比如GB2312、GBK等,通用的编码我们用utf8; |
打开数据库
| 语法格式 | 基本语法 use 数据库名 |
|---|---|
| 回响 | |
| 参数说明 | |
| 举例说明 | # 打开 student 数据库 use student; |
| 备注 |
1.2 删除数据库
| 语法格式 | # 基本语法 drop database <数据库名> | # 带参数的语法 drop database [if exists] <数据库名> |
|---|---|---|
| 回响 | ||
| 参数说明 | ||
| 举例说明 | # 删除 student 数据库 drop database student; | # 删除 student 数据库 drop database if exists student; |
| 备注 |
1.3 编辑数据库
| 语法格式 | alter database <数据库名> [default character set 字符集] [default collate 排序规则] |
|---|---|
| 回响 | |
| 参数说明 | |
| 举例说明 | # 创建一个叫test的数据库,字符集为gb2132 create database test charset gb2312; # 修改test指定字符集为utf8mb4,排序规则为utf8mb4_general_ci; alter database test default character set utf8mb4 default collate utf8mb4_general_cli; |
| 备注 | [default character set 字符集]也可以写错[default charset 字符集] |
1.4 查询数据库
| 命令 | 说明 |
|---|---|
| show databases; | 查看全部数据库 |
| select database(); | 查看当前使用的数据库 |
| show create database 数据库名; | 查看创建xxx数据库的语法 |
边栏推荐
- Li Chuang EDA learning notes IX: layers
- 2022 registration examination for safety production management personnel of fireworks and firecracker production units and examination skills for safety production management personnel of fireworks an
- Backpropagation formula derivation [Li Hongyi deep learning version]
- Constantly changing harmonyos custom JS components during the Spring Festival - Smart Koi
- JVM family -- heap analysis
- Base d'apprentissage de la machine: sélection de fonctionnalités avec lasso
- Enhanced for loop
- Unity knapsack system (code to center and exchange items)
- Which product is better if you want to go abroad to insure Xinguan?
- Day05 錶格
猜你喜欢

Don't disagree, this is the most powerful "language" of the Internet

Résumé: entropie, énergie libre, symétrie et dynamique dans le cerveau

National standard gb28181 protocol platform easygbs fails to start after replacing MySQL database. How to deal with it?

Add token validation in swagger

1day vulnerability pushback skills practice (3)

JVM family -- heap analysis

@Scheduled scheduled tasks

Is it really so difficult to learn redis? Today, a fan will share his personal learning materials!

MySQL query

Johnson–Lindenstrauss Lemma
随机推荐
super_ Subclass object memory structure_ Inheritance tree traceability
Zhihu million hot discussion: why can we only rely on job hopping for salary increase? Bosses would rather hire outsiders with a high salary than get a raise?
[Valentine's Day confession code] - Valentine's Day is approaching, and more than 10 romantic love effects are given to the one you love
Have you entered the workplace since the first 00???
The property of judging odd or even numbers about XOR.
Is online futures account opening safe and reliable? Which domestic futures company is better?
Base d'apprentissage de la machine: sélection de fonctionnalités avec lasso
logistic regression
Dare to climb here, you're not far from prison, reptile reverse actual combat case
JVM family -- heap analysis
Www 2022 | taxoenrich: self supervised taxonomy complemented by Structural Semantics
Why is it recommended that technologists write blogs?
Li Chuang EDA learning notes IX: layers
7 * 24-hour business without interruption! Practice of applying multiple live landing in rookie villages
Solve the problem that the tabbar navigation at the bottom of vantui does not correspond to the page (window.loading.hash)
MySQL backup notes
Experience summary of the 12th Blue Bridge Cup (written for the first time)
Eh, the log time of MySQL server is less than 8h?
How much does it cost to open a futures account in China? Where is it safe to open an account at present?
The first spring of the new year | a full set of property management application templates are presented, and Bi construction is "out of the box"