Experiments six index and data integrity constraints

 

   Experiments six index and data integrity constraints

First, the  Experiment:

1, to create an index

2, data integrity constraints created

Second, the  pilot project: staff management database

Staff management for enterprise database management, database named YGGL in, YGGL database consists of three tables: Employees (employee information table), Departments (department information table), Salary (staff salaries Fact Sheet).

Third, the  experimental procedures required to complete the following :( command)

1, create index create an index:

1) Create a regular index depart_index employee number column in the Employees table;

 

 

2) create composite index ad_index on the Employees table column names and addresses;

 

 

3) create a unique index on Departmentname columns in the Departments table;

 

 

4) Use the Employees table to see the show index and Departments in the index.

 

 

 

2, using alter table index added

1) of the Employees table of time of birth column add a unique index date_index, add a column name and sex composite index name_sex_index;

 

 

2) to see if there is a primary key index Departments table, if there is, please delete the primary key index;

 

 

 

 

 

3) create a primary key index number for the Departments table department;

 

 

4) number column to create a foreign key index on the Employees table in the department.

 

 

3, to create the index while creating the table

1) Create a cpk (product number, product name, price, inventory) (each column of data type and length, and other custom), and create a primary key product number column, create composite index cpk_fh_index in stocks and unit price columns.

 

 

4, the index display

1) using the show index to see the index on the Employees table

 

 

5, remove the index

1)       使用drop index删除索引depart_index、ad_index和date_index;

 

 

 

 

 

 

2)       使用alter table删除Employees表上的主键索引和外键索引。

 

 

6、 数据完整性约束

1)       创建一个员工奖金发放表jj(employeid,je),其中employeid为主键,其值必须是Employees表中已有的员工编号,并且档删除和修改Employees表中员工编号列时,要求jj表中的员工编号列的数据也随着变化。

 

 

2)       创建雇员表emp,只考虑员工编号、姓名和性别3列,姓名列满足唯一约束,性别只能包括男或女;

 

 

3)       创建雇员表emp_1,只考虑员工编号和出生时间2列,要求出生时间必须大于1980年1月1日,并将该约束命名为birthdate_id;

 

 

4)       创建雇员表emp_2,只考虑员工编号和性别2列,并且确认性别中所有的值都来自于emp表的性别列中;

 

 

5)       创建雇员表emp_3,有员工编号、工资和扣款3列,要求工资必须大于扣款,并为该约束命名为last_salary;

 

 

四、  实验报告要求

1、 实验报告格式要求

包括内容:标题、实验内容、实验步骤、实验中遇到的问题及解决方案

2、 实验报告内容要求

(1)     标题参看实验指导标题+“实验报告”,如“实验一 MySQL的安装与命令初步实验报告”;

(2)     实验内容与实验指导中相同;

(3)     实验步骤中将自己实验中的每个步骤的命令和操作结果显示界面进行截图完善。

(4)     实验中遇到的问题及解决方案中如实地将自己的问题的解决过程记录出来。

3、 实验报告提交要求

每次实验课结束之后,每个人需要提交实验报告,实验报告命名为:学号姓名

五、  补充说明

实验报告的提交和完成情况将作为期末考评的一部分,希望每位同学认真完成每次安排的实验,并按要求按时提交实验报告。

 

 

Guess you like

Origin www.cnblogs.com/lvwuwa/p/11128361.html