p77页关于表的操作的练习

(1)创建数据库stuexpm1。
create database stuexpm1;


(2)创建StudentInfo表,显示StudentInfo表的基本结构。
create table studentinfo
(
StudentID varchar(6) not null  primary key  comment '学号',
Name varchar(8) not null  comment '姓名',
Sex  varchar(2) not null  default '男' comment '性别',
Birthday date not null  comment '出生日期',
Speciality varchar(12)   null  comment '专业',
Address varchar(20)   null  comment '家庭地址'
);


(3)由StudentInfo使用复制方式创建StudentInfo1表。
create table StudentInfo1 like studentinfo;


(4)由StudentInfo表中增加一列StuNo,添加到表的第1列,不为空,取值唯一并自动增加,显示StudentInfo表的基本结构。
alter table StudentInfo
add column StuNo int null unique auto_increment first;
Desc StudentInfo;


(5)将StudentInfo1表的Address列修改为City,将数据类型改为char,可为空,默认值为“北京”,显示StudentInfo1表的基本结构。
alter table StudentInfo1
change column Address City char(20) null default '北京';
desc StudentInfo1;


(6)将StudentInfo1表的Speciality列修改为School,将数据类型改为char,可为空,默认值为“计算机学院”。
alter table StudentInfo1
change column Speciality School char(12) 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 column City varchar(20) after Name;
desc StudentInfo1;

(9)在StudentInfo表中删除Studo。
alter table StudentInfo
drop column StuNo;
desc StudentInfo;


(10)将StudentInfo1表更名为StudentInfo2表。
alter table StudentInfo1
rename to StudnetInfo2;


(11)删除StudentInfo2表。
drop table StudnetInfo2;

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值