




免费预览已结束,剩余26页可下载查看
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
西南石油大学实验报告精品资料课程名称:数据库原理实验项目名称:实验3 sql 数据定义语言专业年级班级、姓名、学号:电子邮件地址:实验所用机器名:实验时间地点: 2015.12.11明理楼实验指导教师:孙瑜成绩批改人批改日期插入你的照片注意:在粘贴截图时请保留窗口完整标题,但只需保留关键界面,多余的空白界面请删除。一、实验课时: 4二、实验目的(1) 掌握使用 t-sql 语句创建、删除数据库的方法。(2) 掌握使用 t-sql 语句创建、修改、删除表的方法。(3) 掌握使用 t-sql 语句创建、删除数据库完整性约束条件的方法。(4) 掌握使用 t-sql 语句对表添加、修改、删除数据的方法。(5) 掌握使用 t-sql 语句创建、修改、删除、查询视图的方法。三、实验要求(1) 使用 sql server 2008查询分析器。(2) 严格依照操作步骤进行。(3) 在本地服务器中创建和管理数据库。四、实验环境(1) pc 机。(2) sql server 2008。五、实验内容及步骤(请特别注意实验步骤:第 6 项的第 1 小项,即“插入数据”操作必须在第 4 项以前执行)1. 使用 transact-sql语句创建 jobs 数据库,数据库名格式为jobs_sunyu( 即 jobs_ 你的中文名字拼音 )create database jobs_dengzhipeng;2. 使用 transact-sql语句创建 jobs 数据库包含的所有表employeecreate table employee( empno smallint not null,supname varchar(50) not null, forenames varchar(50) not null, dob date not null,address varchar(50) not null,telno char(10) not null, depno smallint not null);jobhistorycreate table jobhistory( empno smallint not null,position varchar(50) not null, stardate date not null,enddate date null, salary int not null);coursecreate table course(courseno smallint not null, cname varchar(50) not null, cdate date not null);departmentcreate table department( depno smallint not null, dname varchar(50) not null,location varchar(10) not null,head smallint not null);empcoursecreate table empcourse( empno smallint not null,courseno smallint not null);3使用 transact-sql语句创建 jobs 数据库包含表的主键、外键约束条件创建每个表的主键:alter table employeeadd constraint pk_employee primary key (empno);alter table jobhistoryadd constraint pk_jobhistoryprimary key (empno,position,stardate);alter table courseadd constraint pk_course primary key (courseno);alter table departmentadd constraint pk_department primary key (depno);alter table empcourse创建关系:alter table jobhistoryadd constraint fk_jobhistory_employee foreign key (empno)references employee (empno);add constraint pk_emcourse primary key (empno,courseno);alter table empcourseadd constraintalter table empcourseadd constraint fk_empcourse_course foreign key (courseno)references course (courseno);fk_empcourse_employee foreign key (empno) references employee (empno);alter table employeefk_employee_department foreign key (depno)references department (depno);alter table department add constraint fk_department_employee foreign key (head)referencesemployee(empno);具体关系:execute sp_helpconstraint department;execute sp_helpconstraint empcourse;execute sp_helpconstraint jobhistory;execute sp_helpconstraint employee;(所有 jobs 中表的约束图。注意:必须如上图所示清楚完整显示约束的constraint_type 、constraint_name 、constraint_keys等信息。 ) 4备份 jobs 数据库5. 使用 transact-sql语句在 jobs 数据库里创建视图 (注意:在以下各个小题中,后续题目可以利用前面题目创建的视图)(1) 创建一个名为“ firstview ”的视图,列出不重复的所有选修了课程的empno(插入定义该视图的sql 窗口)create view firstview(empno) asselect distinct empnofrom empcourse;(插入查询该视图的sql 窗口及结果 )(2) 创建一个名为“secondview ”的视图,列出所有 empno小于 5 的员工信息(插入定义该视图的sql 窗口)create view secondview(empno,supname, forenames,dob,address,telno,depno) asselect *from employee where empno 1960-01-01;select * from employee;(分别附上修改以前和修改之后的数据图)(3) 删除数据删除所有员工以前的工作历史。修改以前:修改以后:delete from jobhistory where enddate is not null;select * from jobhistory;(分别附上删除以前和删除之后的数据图)六、收获,体会及问题(请详细书写,写得越详细、越个性化、越真实越好,否则我不知道你做这个实验的心路历程,也就无法充分地判断你是否是独立完成的这个实验、你是否在做这个实验时进行了认真仔细地思考、通过这个实验你是否在实践能力上得到了提高)通过对 sql 的 ddl 的学习让我更加明白如何用sql 语言来实现一个数据库的创建,给创建的数据库进行添加数据,更新数据,删除数据。在添加数据以前要先添加关系,避免自己录入的是垃圾数据。在录入数据时, 可能因为刚才录入了关系而不准
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 【正版授权】 ISO/IEC TR 27599:2025 EN Information technology - Brain-computer interfaces - Use cases
- 【正版授权】 ISO 21347:2025 EN Space systems - Fracture and damage control
- 【正版授权】 IEC 61850-10:2012/AMD1:2025 FR Amendment 1 - Communication networks and systems for power utility automation - Part 10: Conformance testing
- 校园超市消防知识培训课件
- 2026届湖南省衡阳二十六中高二化学第一学期期末学业质量监测试题含答案
- 铸造造型试题及答案
- 街道特勤考试试题及答案
- 饥荒家园测试题及答案
- 校园安全知识培训课件专题
- 会议工作试题及答案
- 标签印刷工艺流程
- JB T 6527-2006组合冷库用隔热夹芯板
- 沙漠学全套课件
- 浪潮入职测评题库
- 《外国人来华工作许可证》聘用合同或任职证明正规范本(通用版)
- 生活质量综合评定问卷-74(成人用)
- 慢病健康管理中国专家共识
- GB/T 36935-2018鞋类鞋号对照表
- GB/T 34186-2017耐火材料高温动态杨氏模量试验方法(脉冲激振法)
- 840DSL内部培训教案课件
- 2022年高校教师资格证《高校教师职业道德》考试题库(全真题库)
评论
0/150
提交评论