使用SQL语句创建学生实验数据库

1、创建数据库stuexpm

首先使用命令提示符输入mysql -u root -p进入mysql

输入create database stuexpm;创建数据库

2、创建StudentInfo表,显示StudentInfo表的基本结构。

(1.use stuexpm;进入stuexpm数据库

(2.使用create table StudentInfo;创建表

(3.输入表中存在的相关数据

(4.使用desc StudentInfo显示表。

3、由StudentInfo表使用复制方法创建StudentInfo1表。

create table StudentInfo1 like StudentInfo;

4、在 StudentInfo 表中增加一列 StuNo,添加到表的第1列,不为空,取值唯一并自动增加,显示StudentInfo 表的基本结构。

alter table StudentInfo

add column StuNo int not null unique auto_increment first;

5、将 StudentInfo表的 Address 列修改为 City,将数据型改为 char,可为空,默认

值为“北京”,显示StudentInfo1表的基本结构。

(1修改内容

alter table StudentInfo

change column Adress City char(20) null default '北京';

(2显示基本结构

desc StudentInfo;

6、将 StudentInfo表的 Speciality 列修改为School,将数据类型改为 char,可为空,默认值为“计算机学院”。

alter table StudentInfo

change column Speciality School char(12) null default '计算机学院';

7、将 StudentInfo表的 City 列的默认值修改为“上海”。

alter table StudentInfo

alter column City set default '上海';

8、将 StudentInfo 表的 City 列的类型修改为 varchar(20),并移到列 Name 之后。

alter table StudentInfo

modify column City varchar(20) after Name;

9、在 StudentInfo 表中删除 StuNo 列。

alter table StudentInfo

drop column StuNo;

10、将 StudentInfo表更名为 StudentInfo1 表。

alter table StudentInfo

rename to StudentInfo1;

11、删除 StudentInfo2 表。

drop table StudentInfo2;

12、显示最后的表

desc StudentInfo;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

向来缘浅,奈何情深711

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值