当前位置:网站首页>数据库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数据库的语法 |
边栏推荐
- The difference between MCU serial communication and parallel communication and the understanding of UART
- What are the virtual machine software? What are their respective functions?
- logistic regression
- Stm32bug [the project references devices, files or libraries that are not installed appear in keilmdk]
- Unity writes a character controller. The mouse controls the screen to shake and the mouse controls the shooting
- Aperçu du code source futur - série juc
- Ningde times and BYD have refuted rumors one after another. Why does someone always want to harm domestic brands?
- If you have just joined a new company, don't be fired because of your mistakes
- Practical multifunctional toolbox wechat applet source code / support traffic master
- Add token validation in swagger
猜你喜欢

No clue about the data analysis report? After reading this introduction of smartbi, you will understand!

Consul of distributed service registration discovery and unified configuration management

Code Execution Vulnerability - no alphanumeric rce create_ function()

JVM family -- monitoring tools

The difference between MCU serial communication and parallel communication and the understanding of UART

Redis notes (I) Linux installation process of redis

false sharing

JVM family -- heap analysis
![Stm32bug [stlink forced update prompt appears in keilmdk, but it cannot be updated]](/img/ad/b675364fcaf5d874397fd0cbfec11b.jpg)
Stm32bug [stlink forced update prompt appears in keilmdk, but it cannot be updated]

Third party login initial version
随机推荐
@Scheduled scheduled tasks
Handler source code analysis
[latex] production of complex tables: excel2latex and detail adjustment
Jenkins configures IP address access
(column 23) typical C language problem: find the minimum common multiple and maximum common divisor of two numbers. (two solutions)
JSON string conversion in unity
Practical multifunctional toolbox wechat applet source code / support traffic master
What is cloud primordial?
Optimization theory: definition of convex function + generalized convex function
Audio and video technology development weekly | 232
Zigzag scan
JVM family -- heap analysis
Ningde times and BYD have refuted rumors one after another. Why does someone always want to harm domestic brands?
Webhook triggers Jenkins for sonar detection
Www 2022 | taxoenrich: self supervised taxonomy complemented by Structural Semantics
Stm32bug [the project references devices, files or libraries that are not installed appear in keilmdk]
Which product is better for 2022 annual gold insurance?
Dare to climb here, you're not far from prison, reptile reverse actual combat case
Contest3145 - the 37th game of 2021 freshman individual training match_ F: Smallest ball
Easy to win insert sort