#创建数据库a1
#创建表项aa
#表项:id name age info
#添加表项值
#1 a 10 空
#2 b 11 空
#3 c 12 空
#4 d 13 空
#将表名改为bb
#添加表项time
#修改表项time为times
#删除表项times
#将表项id设为主键约束
#将表项age设为唯一约束
#将表项info设为默认值约束(‘空’)
#将表项name设为非空约束
#将表项id设为自增约束
#删id为3的行
#将数据库安全模式关闭
#将id为3的行中,id值改为2
#将数据库安全模式打开
#删除age的唯一约束
#删除info的默认值约束
#删除name的非空约束
#删除id的自增约束
#删除id的主键约束
#删除表bb
#删除数据库a1
#########################################################
答案:
#创建数据库a1
create database a1;
use a1;
#创建表项aa
#表项:id name age info
create table aa(
id int,name varchar(50),age int,info varchar(50));
#添加表项值
#1 a 10 空
#2 b 11 空
#3 c 12 空
#4 d 13 空
insert into aa
values(1,‘a’,10,null), (2,‘b’,11,null),(3,‘c’,12,null);
#将表名改为bb
rename table aa to bb;
#添加表项time
alter table bb
add time varchar(50);
#修改表项time为times
alter table bb
change time times varchar(50);
#删除表项times
alter table bb
drop times;
#将表项id设为主键约束
alter table bb
add constraint pk_bb_id
primary key(id);
#将表项age设为唯一约束
alter table bb
add constraint uq_bb_age
unique(age);
#将表项info设为默认值约束(‘空’)
alter table bb
alter info set default ‘null’;
#将表项name设为非空约束
alter table bb
modify name varchar(50) not null;
#将表项id设为自增约束
alter table bb
modify id int auto_increment;
#删id为3的行
delete from bb
where id=3;
#将数据库安全模式关闭
set sql_safe_updates=off;
#将id为3的行中,id值改为2
update bb
set id =3
where id=2;
#将数据库安全模式打开
set sql_safe_updates=on;
#删除age的唯一约束
alter table bb
drop index uq_bb_age;
#删除info的默认值约束
alter table bb
alter info drop default;
#删除name的非空约束
alter table bb
modify name varchar(50);
#删除id的自增约束
alter table bb
change id id int;
#删除id的主键约束
alter table bb
drop primary key;
#删除表bb
drop table bb;
#删除数据库a1
drop database a1;