当前位置:网站首页>mysql数据库基础:DDL数据定义语言
mysql数据库基础:DDL数据定义语言
2022-06-29 15:37:00 【持久的棒棒君】
DDL数据定义语言
1、库的管理
1.1 创建库
- 语法
create database 库名;
# 创建前判断是不是存在这个库
create database 【if not exists】 库名;
1.2 修改库
- 一般不会更改库的名字,因为会导致数据不安全,出问题
- 但可以修改库的字符集
alter database 库名 character set gbk;
1.3 库的删除
- 语法
drop database 库名;
# 删除前检测是不是存在该库
drop database 【if exists】 库名
2、表的管理
2.1 表的创建
- 语法
create table 表名(
列名 列的类型【(长度) 约束】
列名 列的类型【(长度) 约束】
...
列名 列的类型【(长度) 约束】
)
- 例题
# 创建表book
create table book(
id INT,#编号
bName varchar(20),#图书名
price double,#价格
authorId INT,#作者编号
publishDate datetime #出版日期
);
2.2 表的修改(添加列,删除列,修改列名或列的类型)
- 语法
alter table 表名 add|drop|modify|change column
(1)修改列名
alter table 表名
change column 列名 新列名 [类型];
(2)修改列的类型或约束
# 修改pubdate的类型为timestamp
alter table 表名
modify column 列名 类型/约束;
(3)添加新列
alter table 表名
add column 新列 类型;
(4)删除列
alter table 表名
drop column 列名;
(5)修改表名
alter table 表名
rename to 新表名;
2.3 表的删除
- 语法
drop table 表名
2.4 表的复制
仅仅复制表的结构
- 语法
create table 新表
like 复制对象(表);
仅仅复制某些字段
- 语法
create table 新表
select 列1,列2,...
from 复制对象(表)
where 0; # 0代表false,1代表true
# where省略也行
复制表的结构外加数据
- 语法
create table 新表
select *
from 复制对象(表)
复制部分数据
- 语法
create table 新表
select 列1,列2...
from 复制对象(表)
where 条件
补充:通过库名.表名可以实现跨库复制
边栏推荐
- 89.(cesium篇)cesium聚合图(自定义图片)
- Development and application of NFT chain Games: Six noteworthy NFT trends in 2022
- It is expected to significantly improve the computational performance of integrated photonic circuits. The Tsinghua team proposed a diffraction pattern neural network framework
- 《网络是怎么样连接的》读书笔记 - 服务器端的局域网中(四)
- Training mode of deep learning network
- taro3.*中使用 dva 入门级别的哦
- Paging SQL (rownum, row_number, deny_rank, rank)
- LeetCode-470-用Rand7()实现Rand10()
- DataKit 作为本地获取数据的 API 服务器
- Polarimetric SAR surface classification
猜你喜欢

Business Intelligence BI and business management decision-making thinking No. 3: business quality analysis

13.TCP-bite

Interviewer: tell me about the MySQL transaction isolation level?

C#学习一:值类型与引用类型

mysql XA 分布式事务

Autodesk Revit 2023软件安装包下载及安装教程

Middle order and post order traversal to construct binary tree [recursive partition interval and backtracking splicing subtree + similarity and difference between middle post order and middle pre orde

The way of enterprise transformation and upgrading: digital transformation, thinking first

wallys/m.2/Adapter card(one pcie1x to 4 x Mini PCIE)

动作捕捉系统用于苹果采摘机器人
随机推荐
wallys/m.2/Adapter card(one pcie1x to 4 x Mini PCIE)
Introduction to radar related contents
Neural network for remote sensing image processing
"Game engine shallow in shallow out" 98 Substancepainer plug-in development
Several imaging modes of polarimetric SAR
Swoole TCP distributed implementation
Volcano engine was selected into the first "panorama of edge computing industry" in China
Daily / June 29, 2022: where is Li Feifei's focus on "embodied intelligence"?
PostgreSQL source code learning (23) -- transaction log ④ - log assembly
面试官:说一下MySQL事务隔离级别?
GWD: rotating target detection based on Gaussian Wasserstein distance | ICML 2021
Google software version experience cycle
Three development trends of enterprise application viewed from the third technological revolution
GWD:基于高斯Wasserstein距离的旋转目标检测 | ICML 2021
cmake学习-2
等保测评结论为差,是不是表示等保工作白做了?
CSDN无法复制问题
swift JSONSerialization
three. JS and Gaode map are combined to introduce obj format model - effect demonstration
A. Marathon