暂无图片
暂无图片
暂无图片
暂无图片
暂无图片
数据库索引实验.pdf
13
4页
4次
2025-04-12
免费下载
6 综合型实验项目索引和数据完整性
(一)建立索引
1、对YGGL数据库的Employees表中的DepartmentID列建立
索引。
create index ind_dep on Employees(DepartmentID);
2 Employees表的Name列和Address列上建立复合索引。
create index ind_Name_Add on Employees(Name,Address);
3 Departments表上的DepartmentName列建立唯一非聚集索
引。
create unique index ind_depName on
Departments(DepartmentName);
(二)重建索引
1、重建表Employees中的所有索引。
alter index all on Employees rebuild;
(三)删除索引。
1、使用DROP INDEX语句删除表Employees上的索引
Depart_ind
drop index ind_dep on Employees;
2 使用DROP INDEX一次删除Employees表上的多个索引。
drop index Employees.ind_Name_Add,Employees.ind_depName;
(四)数据完整性操作
1、创建一个表Employees5,只含EmployeesIDName,Sex
Education列。将Name,设为主键,作为列Name的约束。对
EmployeesID列进行UNIQUE约束,并作为表的约束。
create table Employees5
(
EmployeesID char(6) not null,
Name char(6) not null primary key ,
Sex char(2) not null,
Education char(60) not null,
constraint UK_id unique(EmployeesID)
)
2 删除上题中创建的UNIQUE约束。
alter table Employees5
drop constraint UK_id;
3 使用T-SQL命令创建一个新表,使用一个复合列作为主
键,作为表的约束,并为其命名。
create table Employees6
(
EmployeesID char(6) not null,
Name char(6) not null ,
Sex char(2) not null,
Education char(60) not null,
constraint PK_id_name primary key(EmployeesID,Name)
)
4 使用语句为表ALTER TABLEEmployees5添加一个新列
Address,并为该列定义UNIQUE约束,并了解如何使用图形向导
方式删除主键和UNIOQUE约束。
alter table TABLEEmployees5
add Address char(60)
constraint UK_ad unique (Address)
5 创建新表student,只考虑号码性别两列,性别只能
包含男或女。向该表插入数据,性别列插入以外
的字符,查看会发生什么情况。
create table student
(
XH char(8) not null,
XB char(2) not null check(XB = '男' or XB = '女')
)
6 创建新表Salary2,结构与Salary相同,但Salary2表不可以
OutCome列大于Income列。向表中插入数据,查看OUTCOME
值比INCOME值大是会有什么情况。
create table Salary2
(
EmployeeID char(6) NOT NULL,
InCome float NOT NULL,
OutCome float NOT NULL,
check (Income>OutCome)
)
7 创建一个表Employees6,只考虑学号出生日期
列,出生日期必须晚于198011日。
create table Employees6
(
XH char(8) not null,
CSRQ date not null check(CSRQ>'1980-01-01')
)
8 YGGL数据库中的Employees表进行修改,为其增
“DepartmentID”字段的CHECK约束。约束条件为
of 4
免费下载
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文档的来源(墨天轮),文档链接,文档作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。