实验4.2-3

#(2)显示studentinfo表的基本结构 

show databases;

use stuexpm;

desc student;

show create table student;

#(3)由studentinfo表使用复制方式创建studentinfo1表

use stuexpm;

create table studentinfo1 like student;

#(4)在studentinfo1表中增加一列stuno,添加到表的第1列,不为空,取值唯一并自动增加,显示studentinfo表的基本结构

alter  table studentinfo1

     add column StuNo int not null unique auto_increment first;

desc studentinfo1;

     

#(5)将studentinfo1表的address 列修改 为city ,将数据类型改为char,可为空,默认值为"北京",显示studentinfo1表的基本结构

alter table studentinfo1

     change column tc city char(20) null default '北京';

desc studentinfo1;

desc student;

#(6)将studentinfo1表的speciality 列修改为school,将数据类型改为char,可为空,默认值为"计算机学院"

alter table studentinfo1 

      change column speciality school char(20) null default '计算机学院';

desc studentinfo1;

desc student;

#(7)将studentinfo1表的city列的默认值修改为"上海"

alter table studentinfo1

      alter column city set default '上海';

desc studentinfo1;

desc student;

#(8)将studentinfo1表的city列的类型修改为varchar(20),并移到列Name之后

alter table studentinfo1

       modify city varchar(50) after sname;

       desc studentinfo1;

       

#(9)在studentinfo1表中删除stuno列

alter table studentinfo1

       drop column stuno;

       desc studentinfo1;

       

#(10)将studentinfo1表更名为studentinfo2表

alter table studentinfo1

       rename to studentinfo2;

         desc studentinfo2;

#(11)删除studentinfo2表

drop table studentinfo2;

猜你喜欢

转载自blog.csdn.net/weixin_72075654/article/details/130588742
4.2