(精品word)数据库系统概论实验二.doc
上传人:17****21 上传时间:2024-09-09 格式:DOC 页数:9 大小:32KB 金币:5 举报 版权申诉
预览加载中,请您耐心等待几秒...

(精品word)数据库系统概论实验二.doc

(精品word)数据库系统概论实验二.doc

预览

在线预览结束,喜欢就下载吧,查找使用更方便

5 金币

下载此文档

如果您无法下载资料,请参考说明:

1、部分资料下载需要金币,请确保您的账户上有足够的金币

2、已购买过的文档,再次下载不重复扣费

3、资料包下载后请先用软件解压,在使用对应软件打开

(精品word)数据库系统概论实验二(精品word)数据库系统概论实验二(精品word)数据库系统概论实验二实验内容一、数据定义(一)基本表操作1。建立基本表在数据库test中建立3章基本表:Student、Course和SC(1).创建学生表Student(Sno,Sname,Ssex,deptno)(2)创建课程表Course(cno,cname,tno,credit)(3).创建学生选课表SC(sno,cno,grade),(4)。创建教师表teacher(tno,tname,deptno)(5).创建系表dept(deptno,dname)Sql语言如下:createtablestudent(snointprimarykey,snamechar(8)unique,ssexchar(2),deptnoint);createtablecourse(cnointprimarykey,cnamechar(20)notNULL,tnoint,creditint,foreignkey(tno)referencesteacher(tno));createtablesc(snoint,cnoint,gradeint,primarykey(sno,cno),foreignkey(sno)referencesstudent(sno),foreignkey(cno)referencescourse(cno));createtableteacher(tnointprimarykey,tnamechar(8)notNULL,deptnoint);createtabledept(deptnointprimarykey,dnamechar(20)notNULL);2.修改基本表在student表中加入属性年龄age(int型)Sql语言如下:altertablestudentaddsageint;3.删除基本表(不作)注意:要在后面的所有操作结束后删除基本表(1)删除student表(2)在所有操作结束后删除Course表(3)在所有操作结束后删除SC表(4)在所有操作结束后删除Teacher表(5)在所有操作结束后删除Dept表Sql语言如下:Droptablestudent;Droptablecourse;Droptableteacher;Droptabledept;Droptablesc;(二)建立索引1。建立索引(1)在student表上建立关于属性的sno的唯一索引stusno。(2)在Course表上建立关于cno的唯一索引coucno。2.删除索引(1)删除student表上的索引stutno。(2)删除course表上的索引coucno。Sql语言如下:createuniqueindexstusnoonstudent(sno);createuniqueindexcoucnooncourse(cno);dropindexstusnoonstudentdropindexcoucnooncourse(三)视图操作1.建立视图在插入数据的student基本表上为计算机学生的记录建立一个视图cs_student。2.删除视图在操作结束后,删除视图cs_studentSql语言如下:createviewcs_studentasselect*fromStudentwheredeptnoin(selectdeptnofromdeptwheredept.deptno=Student.deptnoanddeptname='计算机科学与技术’);dropviewcs_student二、数据操作(一)更新数据Sql语言如下:-—向Dept表中插入下列数据:insertintodept(deptno,deptname)values(10,’计算机科学与技术’);insertintodept(deptno,deptname)values(20,’信息’);—-向teacher表中插入下列数据:insertintoteacher(tno,tname,deptno)values(101,'张星',10);insertintoteacher(tno,tname,deptno)values(102,'李珊’,10);insertintoteacher(tno,tname,deptno)values(103,’赵应天’,10);insertintoteacher(tno,tnam