当前位置:网站首页>数据库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数据库的语法 |
边栏推荐
- 2006 translation
- [source code analysis] model parallel distributed training Megatron (5) -- pipestream flush
- 基於.NetCore開發博客項目 StarBlog - (14) 實現主題切換功能
- 7 * 24-hour business without interruption! Practice of applying multiple live landing in rookie villages
- Safety tips - seat belt suddenly fails to pull? High speed police remind you how to use safety belts in a standardized way
- JVM family -- heap analysis
- 2022 Guangxi provincial safety officer a certificate examination materials and Guangxi provincial safety officer a certificate simulation test questions
- Lichuang EDA learning notes 14: PCB board canvas settings
- Talking about custom conditions and handling errors in MySQL Foundation
- Monitoring - Prometheus introduction
猜你喜欢

JVM family -- monitoring tools

Jenkins configures IP address access

PID of sunflower classic

Session learning diary 1

Redis notes (I) Linux installation process of redis

Problems and solutions of several concurrent scenarios of redis

What kind of experience is it when the Institute earns 20000 yuan a month!

What is cloud primordial?

There is no need to authorize the automatic dream weaving collection plug-in for dream weaving collection

WP collection plug-in free WordPress collection hang up plug-in
随机推荐
[database I] database overview, common commands, view the table structure of 'demo data', simple query, condition query, sorting data, data processing function (single row processing function), groupi
I stepped on a foundation pit today
PMP 考試常見工具與技術點總結
JSON string conversion in unity
warning: LF will be replaced by CRLF in XXXXXX
No clue about the data analysis report? After reading this introduction of smartbi, you will understand!
Short math guide for latex by Michael downs
Contest3145 - the 37th game of 2021 freshman individual training match_ G: Score
Johnson–Lindenstrauss Lemma
CSCI 2134
Optimization theory: definition of convex function + generalized convex function
[latex] production of complex tables: excel2latex and detail adjustment
Webhook triggers Jenkins for sonar detection
Contest3145 - the 37th game of 2021 freshman individual training match_ D: Ranking
[Valentine's Day confession code] - Valentine's Day is approaching, and more than 10 romantic love effects are given to the one you love
static hostname; transient hostname; pretty hostname
PHP database connection succeeded, but data cannot be inserted
What is cloud primordial?
2022 examination summary of quality controller - Equipment direction - general basis (quality controller) and examination questions and analysis of quality controller - Equipment direction - general b
Audio and video technology development weekly | 232