网站大量收购独家精品文档,联系QQ:2885784924

数据库技术实五.doc

  1. 1、本文档共9页,可阅读全部内容。
  2. 2、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
数据库技术实五

课程名称 数据库技术 实验 成绩 实验名称 索引和数据完整性的使用 学号 姓名 班级 日期 实验目的: 掌握索引的使用方法; 掌握数据完整性的实现方法; 实验平台: 利用RDBMS(SQL Server 2008)use yggl go create index depart_ind on employees(departmentid) go 图形方式: 展开数据库yggl,展开employees,右击“索引”,选择“新建索引”选项。在新建索引的窗口中填写索引的名称和类型,单机“添加”按钮,列表中选择要创建的列。选择单机“确定“按钮完成创建。 分别用图形方式和T-SQL语句为Employees表的name列和address列上建立复合索引。 T-SQL语句: create index ad_ind on employees(name,address) 图形方式: 分别用图形方式和T-SQL语句为Departments表的departmentname列建立唯一非聚集索引。 T-SQL语句: create unique index Dep_ind on departments(departmentname) 图形方式: 重建Employees表中的所有索引。 use yggl go alter index all on employees rebuild 删除Employees和Departments表中建立过的所有索引。 drop index employees.ad_ind,departments.Dep_ind,employees.depart_ind 2. 数据完整性 (1)使用T-SQL命令创建一个新表,使用一个复合列为主键,作为表的约束,并为其命名。 create table Employees6 ( EmployeeID char(6) not null, Name char(10) not null, Education char(4) not null, Birthday date not null, Sex bit not null default 1, WorkYear tinyint null, Address varchar(40) null, PhoneNumber char(12) null, DepartmentID char(3) not null, primary key (EmployeeID,DepartmentID), constraint ED_UK unique(EmployeeID,DepartmentID) ) go (2)使用T-SQL语句为表Employees表添加一个新列shenfenzheng,并为该列定义UNIQUE约束。 alter table Employees add shenfenzheng varchar(40) constraint AD_UK unique (shenfenzheng) go (3)创建新表student,只有号码和性别两列,性别只能包含男和女。 create table student (号码 char(6) not null, 性别 char(2) not null check(性别 in(男,女)) ) (4)向student表插入数据,性别列插入男和女以为的字符,查看发生的情况。 (5)创建Salary2,结构与Salary相同,但Salary2表不允许outcome列大于income列。 create table Salary2 (EmployeeID char(6) not null, InCome float not null, OutCome float not null, check(InCome=OutCome) ) (6)创建一个表Employees2表,只考虑学号、出生日期和部门号字段,出生日期必须晚于1980年1月1号,部门号只能在1~5之间。 create table Employees2 ( 学号 char(6) not null, 出生日期 date not null check(出生日期 1980-01-01), 部门号 char(8) not null check(部门号=1 and 部门号=5) ) create rule time_rule as @time like [0-2][0-9] go exec sp_bindrule time_rule,Employees.WorkYear Go (8)删除上面建立的规则对象。 exec sp_unbindruleEmployees.WorkYear exec sp_unbindruletim

文档评论(0)

173****7830 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档