创建数据库,创建数据表

 

 

#课本P78实验4.2-3
#(1)创建数据库stuexpm
#(2)创建studentinfo表,显示studentinfo表的基本结构
use stuexpm; 
desc studentinfo;
show databases;
show create table studentinfo;
#(3)由studentinfo表使用复制方式创建studentinfo1表
create table studentinfo1 like studentinfo;
select * from studentinfo;
select * from studentinfo1;
#将studentinfo的数据添加到studentinfo1
insert into studentinfo1
    select * from studentinfo;
select * from studentinfo1;

#(4)在studentinfo1表中增加一列stuno,添加到表的第1列,不为空,取值唯一并自动增加,显示studentinfo1表的基本结构
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 city city char(50) null default '北京';
desc studentinfo1;
#(6)将studentinfo1表的speciality 列修改为school,将数据类型改为char,可为空,默认值为"计算机学院"
alter table studentinfo1
    change column speciality  school char(50) null default'计算机学院'; 
desc studentinfo1;
#(7)将studentinfo1表的city列的默认值修改为"上海"
alter table studentinfo1
    alter column city set default'上海';
desc studentinfo1;
#(8)将studentinfo1表的city列的类型修改为varchar(20),并移到列Name之后
alter table studentinfo1
    modify city varchar(50) after Name;
desc studentinfo1;
#(9)在studentinfo1表中删除stuno列
alter table studentinfo1
    drop stuno;
desc studentinfo1;
#(10)将studentinfo1表更名为studentinfo2表
alter table studentinfo1
    rename to studentinfo2;
#(11)删除studentinfo2表
drop table studentinfo2;
desc studentinfo2;

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值