当前位置:网站首页>MySQL-Data Definition Language-DDLdatebase define language
MySQL-Data Definition Language-DDLdatebase define language
2022-08-01 05:02:00 【LXMXHJ】
文章目录
Libraries to add to delete
库创建create database
语法
create database [ is not exists] 库名
[character set 字符集名];
理解
is not exists 如果不存在就创建;
案例
库修改alter database
语法:修改字符集
alter database 库名 character set 字符集名;
修改库名
rename database 旧库名 to 新库名;
# 一般都是在mysql中的dataDirectly modified files found in the database folder name.
库删除 trop database
语法
drop database [if exists] 库名;
案例
字符集、字符序
概念
在数据存储上,MySQL提供了不同的字符集支持;
On the data comparison operation,Provides a different character sequence support;
字符集 = 定义了字符以及字符的编码
字符序 = 字符的比较规则
MySQL 支持多种字符集 与 字符序.
A character set corresponding to at least one character sequence(Generally more for a pair of);
Two different character sets don't have the same character sequence;
每个字符集都有默认的字符序;
常见sql命令
查看支持的字符集
show character set;
use information_schema;
select * from character_sets;
According to field a:character_set_name 、 default_collate_name、description、maxlen
查看支持的字符序
show collation
use information_schema;
select * from collations;
备注
information_schema Used to save the source data of information;
Table to add to delete
表创建create table
语法
create table [is not exists] 表名(
字段名 字段类型【长度 约束】,
字段名 字段类型【长度 约束】,
.....
字段名 字段类型【长度 约束】,
);
案例
A character is a character,一个汉字也是一个字符;
表修改alter table
语法
要求 | sql语句 |
---|---|
添加新的列 | alter table 表名 add column 列名 列类型 [约束]; alter table 表名 add column 列名 列类型 [ first / later 字段名] ; fisrtSaid the new fields added to the first column;laterThe field name said after adding new fields to the field name |
删除列 | alter table 表名 drop column 列名; |
修改列名 | alter table 表名 change column 旧列名 新列名 类型; |
修改列类型 或 约束 | alter table 表名 modify column 列名 新类型 新约束; |
Modify the field default data | alter table 表名 alter column 列名 set default 默认值; |
修改表名 | alter table 表名 rename [to] 新表名; |
案例
表删除drop table
语法
drop table [if exists] 表名;
# if exists Fault tolerance requirements.
案例
表的复制
语法
需求 | sql语句 |
---|---|
仅仅复制表结构 | create table 新表名 like 旧表名 |
复制结构 + 全部数据 | create table 新表名 select * from 旧表 |
复制部分结构 + 部分数据 | create table 新表名 select 部分字段 from 旧表 where 筛选条件 |
仅仅复制某些字段 没有数据 | create table 新表 select 某些字段 from 旧表 where false |
备注
Can replicate across the library,You need to use the library name is.表的形式.
案例
Library table common writing
drop database [is exists] 库名;
drop table [is exists] 表名;
create database 库名;
create table 表名;
练习
边栏推荐
- (Codeforce 757) E. Bash Plays with Functions
- Pyspark机器学习:向量及其常用操作
- 程序员代码面试指南 CD15 生成窗口最大值数组
- Immutable
- Selenium:操作JS
- 万字逐行解析与实现Transformer,并进行德译英实战(一)
- 4D line-by-line analysis and implementation of Transformer, and German translation into English (3)
- Progressive Reconstruction of Visual Structure for Image Inpainting 论文笔记
- pytroch、tensorflow对比学习—功能组件(数据管道、回调函数、特征列处理)
- Visual Studio提供的 Command Prompt 到底有啥用
猜你喜欢
力扣(LeetCode)212. 单词搜索 II(2022.07.31)
Typescript22 - interface inheritance
II. Binary tree to Offer 68 - recent common ancestor
零序电流继电器器JL-8C-12-2-2
备战金九银十,如何顺利通过互联网大厂Android的笔面试?
typescript23-tuple
(2022 Nioke Duo School IV) H-Wall Builder II (Thinking)
typescript21 - Comparison of Interfaces and Type Aliases
罗技鼠标体验记录
基于Arduino制作非接触式测温仪
随机推荐
基于ProXmoX VE的虚拟化家庭服务器(篇一)—ProXmoX VE 安装及基础配置
Selenium:操作JS
Dry goods!How to Construct SRv6-TE Performance Test Environment Using Instrumentation
Progressive Reconstruction of Visual Structure for Image Inpainting 论文笔记
UE4 从鼠标位置射出射线检测
「以云为核,无感极速」顶象第五代验证码
pytroch、tensorflow对比学习—搭建模型范式(构建模型方法、训练模型范式)
vim配置+ctag像source insight一样方便阅读代码
II. Binary tree to Offer 68 - recent common ancestor
备战金九银十,如何顺利通过互联网大厂Android的笔面试?
typescript25 - type assertion
LeetCode 1189. “气球” 的最大数量
在互联网时代,有诸多「互联网+」模式的诞生
律师解读 | 枪炮还是玫瑰?从大厂之争谈元宇宙互操作性
PMP 80个输入输出总结
云服务器下载安装mongo数据库并远程连接详细图文版本(全)
25. Have you been asked these three common interview questions?
API设计笔记:pimpl技巧
李迟2022年7月工作生活总结
华为Android开发面试后得出的面试秘诀