当前位置:网站首页>数据库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数据库的语法 |
边栏推荐
- Learning video website
- CUDA basic knowledge
- Basé sur... Netcore Development blog Project Starblog - (14) Implementation of theme switching function
- Www 2022 | taxoenrich: self supervised taxonomy complemented by Structural Semantics
- Résumé des outils communs et des points techniques de l'examen PMP
- 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"
- New year's first race, submit bug reward more!
- 150 ppt! The most complete "fair perception machine learning and data mining" tutorial, Dr. AIST Toshihiro kamishima, Japan
- 1day vulnerability pushback skills practice (3)
- Have you entered the workplace since the first 00???
猜你喜欢
Li Chuang EDA learning notes IX: layers
JVM family -- heap analysis
1day vulnerability pushback skills practice (3)
Management and thesis of job management system based on SSM
7 * 24-hour business without interruption! Practice of applying multiple live landing in rookie villages
Is it really so difficult to learn redis? Today, a fan will share his personal learning materials!
Jenkins configures IP address access
Rhcsa day 3
96% of the collected traffic is prevented by bubble mart of cloud hosting
What is cloud primordial?
随机推荐
XSS prevention
Teach you how to optimize SQL
Add token validation in swagger
96% of the collected traffic is prevented by bubble mart of cloud hosting
Jenkins continuous integration environment construction V (Jenkins common construction triggers)
Webhook triggers Jenkins for sonar detection
(practice C language every day) pointer sorting problem
what does ctrl + d do?
How about the ratings of 2022 Spring Festival Gala in all provinces? Map analysis helps you show clearly!
Contest3145 - the 37th game of 2021 freshman individual training match_ F: Smallest ball
The property of judging odd or even numbers about XOR.
Record a problem that soft deletion fails due to warehouse level error
Basé sur... Netcore Development blog Project Starblog - (14) Implementation of theme switching function
JS object definition
Defensive programming skills
@Scheduled scheduled tasks
WordPress collection WordPress hang up collection plug-in
Ningde times and BYD have refuted rumors one after another. Why does someone always want to harm domestic brands?
Add IDM to Google browser
[Wu Enda deep learning] beginner learning record 3 (regularization / error reduction)