DDL操作

发布时间 2023-08-29 20:25:34作者: 迭起兴衰

DDL操作

1、show databases;查询数据库。

2、create database (if not exists) itcase(default charset utf8mb4);如果数据库内不存在itcase则创建字符为4字节

3、drop database (if exists)+数据库名;删除数据库

4、select database()查询当前数据库

5、use +数据库名 使用数据库

6、show tables;查询当前数据库所有表

7、创建表:

create table 表名(

类型名1 (id) 类型1(int) 【comment ‘’】(注释),(最后一个不加,)

类型名2(id) 类型2(int) 【comment ‘’】(注释)

)comment‘’(注释)

8、desc +表名 查询表结构

9、show create 表名 查询详细表

10、alter table 表名 add 字段名 类型(长度)[comment (注释)] [约束]

添加字段

11、alter table 表名 modify 字段名新数据 类型(长度)修改数据类型

12、alter table 表名 change 旧字段名 新字段名新数据 类型(长度)[comment (注释)] [约束] 修改字段名和字段类型

13、alter table 表名 drop 字段名 字段删除

14、alter table 表名 rename to 新表名 表名修改

15、 drop table[if exists]表名 删除表

16、truncate table 表名 删除指定表,并重新创建该表(删除表数据)