View Creation and Manage Experiments

(1) In the job database, there is an employee information table: Worklnfo table, and its table structure is shown in the following table:
insert image description here
create table workinfo(
id int(4) not null unique primary key,
name varchar(20) not null,
sex varchar (4) not null,
age int(4),
address varchar(50),
tel varchar(20));
the exercise data in the table are as follows:
1.'Zhang Ming','Male',19,'Chaoyang District, Beijing ','1234567'
2.'Li Guang','Male',21,'Changping District, Beijing','2345678' 3.'Wang
Dan','Female',18,'Yongzhou City, Hunan Province','3456789 '
4.'Zhao Yimei','female',24,'Zhejiang Ningbo','4567890'
insert into workinfo
(id,name,sex,age,address,tel)
values(1001,'Zhang Ming',' Male',19,'Chaoyang District, Beijing','1234567'),
(1002,'Li Guang','Male',21,'Changping District, Beijing','2345678'), (
1003,'Wang Dan' ,'Female',18,'Yongzhou City, Hunan Province','3456789'),
(1004,'Zhao Yimei','Female',24,'Ningbo City, Zhejiang','4567890');
operate according to the following requirements :
1. Create a view info_view to display the id, name, sex, and address information of hired personnel who are older than 20.
CREATE VIEW info_view(id,name,sex,address) AS SELECT id,name,sex,address FROM workinfo WHERE age>20 WITH LOCAL CHECK OPTION; 2
insert image description here
See the basic structure and detailed structure of the view info_view.
View the basic structure:
DESC info_view;
insert image description here
view the detailed structure:
SHOW CREATE VIEW info_view;
insert image description here
3. View all records of view info_view.
SELECT * FROM info_view;
insert image description here
4.Modify the view info_view to meet the id, name, sex, and address information of recruiters who are younger than 20 years old.
ALTER VIEW info_view(id,name,sex,address) AS SELECT id,name,sex,address FROM work_info WHERE age<20 WITH LOCAL CHECK OPTION;

5. Update the view to change the gender of the recruiter with id 3 from "Male" to "Female".
UPDATE info_view SET sex='female' WHERE id=3;

6. Delete the info_view view.
DROP VIEW info_view;

3. Design experiment
In the student management system, there is a student information table studentinfo table, the table structure is as follows:
insert image description here
create table studentinfo(Number int(4) not null UNIQUE primary key,Name varchar(20) not null,Major varchar(20 ), age int(4));
Please complete the following operations:
1. Use the CREATE VIEW statement to create the view college_view, display the number, name, age, major in the studentinfo table, and display the field names as: student_num, student_name, student_age ,department.
create view college_view(student_num,student_name,student_age,department) as select number,name,age,major from studentinfo;

2. Execute the SHOW CREATE VIEW statement to view the detailed structure of the view.
show create view college_view;
insert image description here
3. Update the view. Insert the following 3 records into the view:
0901,'Zhang San',20,'Foreign Language'
0902,'Li Si',22,'Computer'
0903,'Wang Wu',19,'Computer'
insert into college_view() values
​​(0901,'Zhang San',20,'foreign language'),
(0902,'Li Si',22,'computer'),
(0903,'Wang Wu',19,'computer');

insert image description here
3. Modify the view so that only the information whose specialty is "Computer" is displayed in the view.
Create or replace view college_view(student_num, student_name, student_age,department) as select number,name,age, major from studentinfo where major='computer' with local check option; 4. Delete the view
insert image description here
.
drop view college_view;
insert image description here

Guess you like

Origin blog.csdn.net/m0_55726741/article/details/129248528