1.创建数据库,创建英雄表
2. 添加对应的约束条件
3.插入80条数据
4.通过alter添加两个新的字段
5.通过alter删除一个字段
6.重命名一张表
1.创建数据库
命令:create database db_classic;
创建英雄表,添加对应约束条件
命令:create table t_hero(
id int primary key auto_increment,
nickname varchar(50) unique not null,
age int not null default 1000,
address varchar(100) not null,
job char(30) not null,
weapon char(30) not null,
graoup varchar(50) not null
);
3.插入80数据
命令:insert into t_hero(nickname,age,address,job,weapon,graoup) values("猪八戒",1001,"高老庄","取经","九齿钉耙","四人帮");
insert into t_hero(nickname,address,job,weapon,graoup) values("沙悟净","流沙河","取经","降妖宝杖","四人帮");
insert into t_hero(nickname,address,job,weapon,graoup) values("唐僧","西土大唐","取经","九环锡杖","四人帮");
insert into t_hero(nickname,address,job,weapon,graoup) values("宋江","山东郓城","造反","大刀","108好汉");
insert into t_hero(nickname,address,job,weapon,graoup) values("卢俊义","河北大名府","造反","剑","108好汉");
insert into t_hero(nickname,address,job,weapon,graoup) values("花荣","清风寨","造反","银枪","108好汉");
............
4.增加两个列名
命令:
alter table t_hero add family varchar(30) not null;
alter table t_hero add gender varchar(30) not null;
5.删除一个字段列名;修改表名
命令:alter table t_hero drop family;
rename table t_hero to t_heros;