Mysql database experiment report--experiment four indexes and integrity constraints

In this series, I will update some experimental reports that the teacher asked to write recently~
Please try to make a reference to my article, don’t blindly cv, after all, this is still very important for our future work and study.

Experiment content:

First, create three tables in the database: Employees (employee information table), Departments (department information table), Salary (employee salary table). Then complete the following operations

1. Use create index to create an index:

  1. Create a common index depart_index on the employee number column in the Employees table;

insert image description here
insert image description here

  1. Create a composite index ad_index on the name and address columns in the Employees table;

insert image description here

  1. Create a unique index on the Departmentname column in the Departments table;

insert image description here

  1. Use show index to see the indexes in the Employees table and Departments.

insert image description here

2. Use alter table to add index

  1. Add a unique index date_index to the birth time column in the Employees table, and add a composite index name_sex_index to the name and gender columns;

insert image description here

2) Create a primary key index for the department number in the Departments table;

insert image description here

3) Create a foreign key index on the department number column in the Employees table.

insert image description here

3. Create the index while creating the table

  1. Create cpk (product number, product name, unit price, inventory) (the data type and length of each column can be customized), and create a primary key for the product number column, and create a composite index cpk_fh_index in the inventory and unit price columns.
    insert image description here

4. Display index

  1. Use show index to see the indexes on the Employees table
    insert image description here

5. Delete the index

  1. Use drop index to delete the indexes depart_index, ad_index and date_index;

insert image description here

  1. Use alter table to drop the primary key and foreign key indexes on the Employees table.
    insert image description here

6. Data integrity constraints

  1. Create an employee bonus distribution table jj (employeid, je), where employeeid is the primary key, and its value must be the existing employee number in the Employees table, and when deleting and modifying the employee number column in the Employees table, the employee in the jj table is required The data in the numbered column also changes accordingly.
    insert image description here

  2. Create the employee table emp, only consider the 3 columns of employee number, name and gender, the name column satisfies the unique constraint, and the gender can only include male or female;
    insert image description here

  3. Create the employee table emp_1, only consider the 2 columns of employee number and birth time, require that the birth time must be greater than January 1, 1980, and name the constraint birthdate_id;

insert image description here

  1. Create the employee table emp_2, only consider the employee number and gender 2 columns, and confirm that all the values ​​​​in gender come from the gender column of the emp table;

insert image description here

Subsequent experimental reports will be updated one after another. Please leave a message in the comment area if you don’t understand or make mistakes~
Your likes and attention are my biggest motivation for updating!

Guess you like

Origin blog.csdn.net/A779929/article/details/127852337