- 1、本文档共20页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
mysql数据库实验答案
实验一 创建、修改数据库和表结构
1、用create建立教学数据库的五个基本表:
学生表(学号,姓名,性别,年龄),student((Sno, sname, ssex,sage) ;
(2)课程表(课程号,课程名,学分),Course (Cno, Cname, credit) ;
(3)选课表(学号,课程号,成绩),SC (Sno,, Cno, grade ) ;
(4) 教师表(教师号,姓名,性别,出生年月,系部,职称,地址),
T(Tno,Tname,ssex,birthday,dept,title,address) ;
(5) 工资表(教师号,基本工资,职务工资,合计),Salary(Tno,jbgz,zwgz,hj);
Create Database Student default character set utf8 default COLLATE utf8_bin;
Use Student;
Create Table Student(
SNo char(20) primary key,
SName char(20) ,
SSex char(4) default 男,
SAge int
) ENGINE=InnoDB;
Create Table Course(
CNo char(20) primary key,
CName char(20) NOT NULL,
CRedit float
) ENGINE=InnoDB;
Create Table SC(
SNo char(20) NOT NULL,
CNo char(20) NOT NULL,
Grade float,
Primary Key(SNo, CNo),
Foreign Key(SNo) References Student(SNo) On Delete Cascade,
Foreign Key(CNo) References Course(CNo)
) ENGINE=InnoDB;
Create Table T(
TNo char(20) Primary Key,
TName char(20) NOT NULL,
TSex char(4) default 男,
birthday DateTime,
dept char(20),
title char(20),
address char(20)
) ENGINE=InnoDB;
Create Table Salary(
TNo char(20) NOT NULL,
jbgz float,
zwgz float,
hj float,
Foreign Key(TNo) References T(TNo) On Delete Cascade
) ENGINE=InnoDB;
2、用alter修改基本表
(1)在已存在的学生表student中增加一个sdept(系)的新的属性列;
alter table Student add Dept char(20);
(2)将学生表student中sname属性列的数据类型修改为变长字符串varchar(10)。
alter able Student modify colum sname varchar(10)
3、建立一个临时表,然后将其删除
Create Table temp (
ANo char(20) NOT NULL,B float, C char(10) )
Drop table temp
实验二 建立与删除索引
1、用create index在学生表student的学号sno上建立聚簇索引。
Create Clustered Index SNo_Index On Student(SNo);
2、在学生表student中,为姓名sname建立非聚簇索引。
Create Index SName_Index On Student(SName);
3、在课程表的课程号Cno上建立唯一索引。
Create Unique Index CNo_Index On Course(CNo);
4、在选课表的学号sno、成绩Grade上建立复合索引,要求学号为升序,学号相同时成绩为
降序。
Create Index SCNo_Index On SC(SNo ASC, Grade DESC);
5、用drop删除学生表student的索引。
Drop Index Student.SNo_Index;
6、增加学生表student中姓名唯一约束。
Alter Table Student Add Unique(SName);
7、增加学生表s
文档评论(0)