From 715fd4e4481b60d0227e0888255dd670b9773ba6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=B6=E6=A6=95=E9=94=8B?= <2094447637@qq.com> Date: Sat, 18 Feb 2023 12:55:00 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AC=AC=E4=B8=80=E6=AC=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\347\254\254\344\270\200\346\254\241.md" | 105 ++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 "23.2.18/\347\254\254\344\270\200\346\254\241.md" diff --git "a/23.2.18/\347\254\254\344\270\200\346\254\241.md" "b/23.2.18/\347\254\254\344\270\200\346\254\241.md" new file mode 100644 index 0000000..481e0be --- /dev/null +++ "b/23.2.18/\347\254\254\344\270\200\346\254\241.md" @@ -0,0 +1,105 @@ +###### 查询所有数据库 + +show databases; + +###### 查询当前数据库 + +select database(); + +###### 创建数据库 + +create database 数据库名字; + +###### 严谨创建数据库 + + create database [ if not exists] 数据库名字 [default charset 字符集] [collate 排序规则]; + +###### 删除 + +drop database [if exists] 数据库名字; + +###### 使用数据库 + +use 数据库名字; + +###### 查询当前数据库所有表 + +show tables; + +###### 查询表结构 + +desc 表名; + +###### 查询指定表的建表语句 + + show create table 表名; + +### 关于表的创建 + +create table 表名( + +字段1 字段1类型(int varchar char 等)[comment 字段1注释], + +字段2 字段2类型(int varchar char 等)[comment 字段2注释], + +字段3 字段3类型(int varchar char 等)[comment 字段3注释], + +......................... + +字段n 字段n类型(int varchar char 等)[comment 字段n注释], + +)[comment 表注释]; + + +###### 添加字段 + +alter table 表名 add 字段名 类型(长度) [comment 注释] [约束]; + +###### 修改数据类型 + +alter table 表名 modify 字段名 新数据类型(长度); + +###### 修改字段名和字段类型 + +alter table 表名 change 旧字段名 新字段名 类型(长度) [comment 注释] [约束]; + +###### 删除字段 + +alter table 表名 drop 字段名; + +###### 修改表名 + +alter table 表名 rename to 新表名; + +###### 删除表 + +drop table[if exists] 表名; + +###### 删除指定表,并重新创建该表 + +truncate table 表名; + +``` mysql +show databases; +create database class3; +use class3; +select database(); +create table student( +xuehao varchar(5) comment '学号', +name varchar(5) comment '姓名', +gender char(1) comment '性别', +hobby set('打电动','play','原'), +adgress varchar(15) comment '地址', +phone varchar(11) comment '联系方式', +email varchar(15) comment '邮箱', +qqnunber varchar(15) comment 'qq号码' +); +alter database class3 charset utf8; +select * from student; +insert into student values('22','锋','男',7,'闽西职业技术监狱',13338296732,'2094447637@qq.com',13338296732); +alter table student change phone phone char(11); +alter table student change qqnumber qqnumber char(15); +alter table student change xuehao xuehao varchar(3); +alter table student change email email varchar(20); + +``` \ No newline at end of file -- Gitee