-- 查询所有的 数据库
-- show databases;
-- 创建数据库
-- create database if not exists db02;
-- DDL : 表结构
-- 创建:基本语法
/* create table tb_user(
id int comment 'ID 唯一标识',
username varchar(20) comment '用户名',
name varchar(10) comment '姓名',
age int comment '年龄',
gender char(1) comment '姓别'
) comment '用户';*/
-- 创建:基础语法 (约束)
/*create table tb_user(
id int primary key auto_increment comment 'ID 唯一标识(主键 且 自动自增)',
username varchar(20) not null unique comment '用户名(非空且唯一)',
name varchar(10) not null comment '姓名(非空)',
age int comment '年龄',
gender char(1) default '男' comment '姓别(默认男)'
) comment '用户';*/
-- 查看数据库下的表
show tables;
-- 查询指定表的 表结构
desc tb_emp;
-- 查询 表的建表语句
show create table tb_emp;
-- 添加字段
alter table tb_emp add qq varchar(11) comment 'QQ';
-- 修改字段类型
alter table tb_emp modify qq varchar(13) comment 'QQ';
-- 修改字段名和字段类型
alter table tb_emp change qq qq_num varchar(13) comment 'QQ';
-- 删除字段
alter table tb_emp drop column qq_num;
-- 修改表名
rename table tb_emp to emp;
-- 删除表结构 (删除表结构 表中的数据 会被全部删除)
drop table if exists tb_user;