1.查看当前数据库中的数据表
show tables;
2.创建数据表-students
字段包括(id,name,age,gender,cls_id)
create table students(id int unsigned primary key auto_increment,
name varchar(10) not null,
age tinyint unsigned default 0,
gender enum('男',''女,'保密') default '保密',
cls_id int unsigned not null);
3.查看表结构
desc students
4.修改表结构
- [1] 增加字段-birthday
- alter table 表名 add 列名 类型/约束;
alter table students add birthday datetime default 2019-08-20 12:00;
- [2] 修改字段 -不重命名
- alter table 表名 modify 列名 类型及约束;
alter table students modify birthday date default 2019-08-20;
- [3] 修改字段 -重命名
- -alter table 表名 change 原列名 新列名 类型及约束;
alter table students change birthday birth date default 2019-08-20;
- [4] 修改表—删除字段
alter table students drop birth;
5.删除表
drop table students;