数据库实验报告.doc
《数据库实验报告.doc》由会员分享,可在线阅读,更多相关《数据库实验报告.doc(36页珍藏版)》请在三一办公上搜索。
1、数据库原理实验报告学 号:4110115姓 名:王善斌提交日期:2013-06-20成 绩:东北大学秦皇岛分校【实验内容】2在企业管理器中创建一个数据库,要求如下:(1) 数据库名称 Test1。(2) 主要数据文件:逻辑文件名为Test1_data1,物理文件名为Test1_data1.mdf,初始容量为1MB,最大容量为10MB,增幅为1MB。(3) 次要数据文件:逻辑文件名为Test1_data2,物理文件名为Test1_data2.ndf,初始容量为1MB,最大容量为10MB,增幅为1MB。(4) 事务日志文件:逻辑文件名为Test1_log1,物理文件名为Test1_log1.ldf
2、,初始容量为1MB,最大容量为5MB,增幅为512KB。3在查询分析器中创建一个数据库,要求如下:(1) 数据库名称 Test2。(2) 主要数据文件:逻辑文件名为Test2_data1,物理文件名为Test2_data1.mdf,初始容量为1MB,最大容量为10MB,增幅为1MB。(3) 次要数据文件:逻辑文件名为Test2_data2,物理文件名为Test2_data2.ndf,初始容量为1MB,最大容量为10MB,增幅为1MB。(4) 事务日志文件:逻辑文件名为Test2_log1,物理文件名为Test2_log1.ldf,初始容量为1MB,最大容量为5MB,增幅为1MB。create
3、database test2on primary (name =test2_data1,filename =d:sqlextest2_data1.mdf,size=1,maxsize=10,filegrowth=1),(name=test2_data2,filename=d:sqlextest2_data2.ndf,size =1,maxsize=10,filegrowth=1)log on(name=test2_log,filename=d:sqlexstu_log1.ndf,size=1,maxsize=5,filegrowth=2)4.在查询分析器中按照下列要求修改第3题中创建的数据库t
4、est2(1) 主要数据文件的容量为2MB,最大容量为20MB,增幅为2MB。(2) 次要数据文件的容量为2MB,最大容量为20MB,增幅为2MB。事务日志文件的容量为1MB,最大容量为10MB,增幅为2MBalter database test3modify name=test2alter database test2modify file (name=test2_data2,filename=d:sqlextest2_data2.ndf,size =2,maxsize =20,filegrowth=2)alter database test2modify file (name=test2_
5、log,filename=d:sqlextest2_log.ldf,size =1,maxsize =10,filegrowth=1)alter database test2modify file (name=test2_data1,size=2,maxsize=20,filegrowth =2)4.数据库更名:把test1数据库更名为new_test1alter database test1modify name=new_test15.在企业管理器中删除new_test1数据库,在查询分析器中删除test2数据库。在企业管理器中删除new_test1前在企业管理器中删除new_test1后在
6、查询分析器中删除test3前 在查询分析器中删除test3后drop database test36.为sql示例数据库northwind创建一个备份:northwindBK,并使用该备份文件恢复northwind数据库。exec sp_addumpdevice disk,northwindBK,d:数据库备份MyNwind-1.datBACKUP DATABASE northwind TO northwindBK实验二 创建并管理表1. 创建数据库,包含如下表,创建这些表并按要求定义约束use studentinfo gocreate table student (student_id ch
7、ar (10) primary key,student_name char (10) not null,sex char (1) not null,age int null,department char (15) default 电子信息系)use studentinfo gocreate table course (course_id char (6) primary key,course_name char (20) not null,precould char (6) null,credits numeric (3,1) not null)use studentinfo gocreat
8、e table score (student_id char (10), course_id char (6) not null,grade numeric (3,1) null,primary key (student_id,course_id),foreign key (student_id) references student (student_id),foreign key (course_id) references course (course_id)以下为各个表的数据Students表数据Student_idStudent_namesexagedepartment2001010
9、1JoneM19Computer20010102SueF20Computer20010103SmithM19Math20030101AllenM18Automation20030102deepaF21ArtCourse表数据Course_idCourse_namePreCouIdCreditsC1English4C2MathC52C3databaseC22Score表数据Student_idCourse_idGrade20010101C19020010103C18820010102C29420010102C2622.增加,修改,删除字段,要求 (1)为表student增加一个memo(备注)字
10、段,类型为varchar(200)代码: use yzwgoalter table student add memo varchar (200)(2).将MEMO字段的数据类型更改为varchar(300) 代码:use yzwgoalter table student alter column memo varchar (300)(3)删除memo字段use yzwgoalter table student drop column memo3.向表中插入数据验证约束use yzwgoalter table score add constraint grade check (grade 0 a
11、nd grade 805. 查询年龄在20到30之间的学生学号,姓名,所在系select student.student_id,student.student_name,student.department,student.agefrom studentwhere age between 20 and 306.查询数学系、电子信息系、艺术系的学生学号,姓名。select student.student_id,student.student_namefrom studentwhere department in (math,电子信息系,Art)7. 查询姓名第二个字符为u并且只有3个字符的学生学
12、号,姓名select student.student_id,student.student_namefrom studentwhere student_name like _u_8. 查询所有以S开头的学生。select student.student_id,student.student_namefrom studentwhere student_name like S%9. 查询姓名不以S、D、或J开头的学生select student.student_id,student.student_namefrom studentwhere student_name not like S% and
13、 student_name not like D%and student_name not like J%10查询没有考试成绩的学生和相应课程号(成绩值为空)select student_id,course_idfrom scorewhere grade is null11. 求年龄大于19岁的学生的总人数select count (*) 总数from studentwhere age 1912 别求选修了c1语言课程的学生平均成绩、最高分、最低分学生。select AVG (grade)平均成绩,max(grade)最高分,min(grade)最低分from scorewhere cours
14、e_id=c113.求学号为20010101的学生总成绩select sum (grade)总成绩from scorewhere student_id=2001010114求每个选课学生的学号,姓名,总成绩select student.student_id,student_name,score.gradefrom student,scorewhere student.student_id=score.student_id15.查询所有姓李且全名为3个汉字的学生姓名,学号,性别select student_id,student_name,sexfrom studentwhere student_
15、name=李_16.求课程号及相应课程的所有的选课人数select course_id,count(*)Sumfrom score,studentwhere student.student_id=score.student_idgroup by course_id17查询选修了3门以上课程的学生姓名学号select student_id,student_namefrom studentwhere EXISTS (select *from scorewhere score.student_id=student.student_id group by student_id having count
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 数据库 实验 报告

链接地址:https://www.31ppt.com/p-2395470.html