当前位置:网站首页>MySQL-数据定义语言-DDLdatebase define language
MySQL-数据定义语言-DDLdatebase define language
2022-08-01 04:39:00 【LXMXHJ】
文章目录
库的增改删
库创建create database
语法
create database [ is not exists] 库名
[character set 字符集名];
理解
is not exists 如果不存在就创建;
案例
库修改alter database
语法:修改字符集
alter database 库名 character set 字符集名;
修改库名
rename database 旧库名 to 新库名;
# 一般都是在mysql中的data文件中找到数据库文件夹直接修改名字。
库删除 trop database
语法
drop database [if exists] 库名;
案例
字符集、字符序
概念
在数据存储上,MySQL提供了不同的字符集支持;
在数据的对比操作上,提供了不同的字符序支持;
字符集 = 定义了字符以及字符的编码
字符序 = 字符的比较规则
MySQL 支持多种字符集 与 字符序。
一个字符集至少对应一个字符序(一般为一对多);
两个不同的字符集不能有相同字符序;
每个字符集都有默认的字符序;
常见sql命令
查看支持的字符集
show character set;
use information_schema;
select * from character_sets;
显示字段有:character_set_name 、 default_collate_name、description、maxlen
查看支持的字符序
show collation
use information_schema;
select * from collations;
备注
information_schema 用于保存源数据的信息;
表的增改删
表创建create table
语法
create table [is not exists] 表名(
字段名 字段类型【长度 约束】,
字段名 字段类型【长度 约束】,
.....
字段名 字段类型【长度 约束】,
);
案例
一个字符是一个字符,一个汉字也是一个字符;
表修改alter table
语法
要求 | sql语句 |
---|---|
添加新的列 | alter table 表名 add column 列名 列类型 [约束]; alter table 表名 add column 列名 列类型 [ first / later 字段名] ; fisrt表示新字段添加到第一列;later字段名表示添加新字段到字段名后 |
删除列 | alter table 表名 drop column 列名; |
修改列名 | alter table 表名 change column 旧列名 新列名 类型; |
修改列类型 或 约束 | alter table 表名 modify column 列名 新类型 新约束; |
修改字段默认数据 | alter table 表名 alter column 列名 set default 默认值; |
修改表名 | alter table 表名 rename [to] 新表名; |
案例
表删除drop table
语法
drop table [if exists] 表名;
# if exists 容错需求。
案例
表的复制
语法
需求 | sql语句 |
---|---|
仅仅复制表结构 | create table 新表名 like 旧表名 |
复制结构 + 全部数据 | create table 新表名 select * from 旧表 |
复制部分结构 + 部分数据 | create table 新表名 select 部分字段 from 旧表 where 筛选条件 |
仅仅复制某些字段 没有数据 | create table 新表 select 某些字段 from 旧表 where false |
备注
可以跨库复制,需要使用的是库名.表的形式。
案例
库表常见写法
drop database [is exists] 库名;
drop table [is exists] 表名;
create database 库名;
create table 表名;
练习
边栏推荐
- Make your Lottie support word wrapping in text fields
- Li Chi's work and life summary in July 2022
- RSA主要攻击方法
- Visual Studio提供的 Command Prompt 到底有啥用
- Simulation of Active anti-islanding-AFD Active Anti-islanding Model Based on Simulink
- leetcode6132. Make all elements in an array equal to zero (simple, weekly)
- 解决ffmpeg使用screen-capture-recorder录屏,有屏幕缩放的情况下录不全的问题
- /etc/fstab
- PMP子过程定义总结
- Mysql基础篇(约束)
猜你喜欢
UE4 制作遇到的问题
基于STM32设计的UNO卡牌游戏(双人、多人对战)
typescript22-接口继承
Progressive Reconstruction of Visual Structure for Image Inpainting 论文笔记
软件测试周刊(第82期):其实所有纠结做选择的人心里早就有了答案,咨询只是想得到内心所倾向的选择。
button remove black frame
leetcode6132. Make all elements in an array equal to zero (simple, weekly)
数组问题之《两数之和》以及《三数之和 》
C# | 使用Json序列化对象时忽略只读的属性
typescript28 - value of enumeration type and data enumeration
随机推荐
MLP neural network, GRNN neural network, SVM neural network and deep learning neural network compare and identify human health and non-health data
UE4 制作遇到的问题
【kali-信息收集】枚举——DNS枚举:DNSenum、fierce
软件测试基础理论知识—用例篇
typescript28-枚举类型的值以及数据枚举
leetcode6132. Make all elements in an array equal to zero (simple, weekly)
lambda
Visual Studio提供的 Command Prompt 到底有啥用
lambda
Hackers can how bad to what degree?
Flutter Tutorial 02 Introduction to Flutter Desktop Program Development Tutorial Run hello world (tutorial includes source code)
typescript26-字面量类型
ICML2022 | Deep Dive into Permutation-Sensitive Graph Neural Networks
动态规划 01背包
【愚公系列】2022年07月 Go教学课程 023-Go容器之列表
Dart named parameter syntax
Introduction to the Elastic Stack
云服务器下载安装mongo数据库并远程连接详细图文版本(全)
PMP 相关方管理必背总结
Basic Theoretical Knowledge of Software Testing - Use Cases