1. The purpose of the experiment:
-
Familiar with SQL statements for adding, deleting, and modifying data, combining with nested SQL sub-queries, designing several different forms of statements for inserting, modifying and deleting data, and debugging successfully;
-
Understand the view to achieve database security control;
-
Understand view resolution and be able to create and query views.
2. Experimental content:
-
Use the student elective database to implement SQL statements such as unit group insertion, batch data insertion, data modification and data deletion;
-
According to application requirements, create a basic view and a view with WITH CHECK OPTION, and verify the validity of the view WITH CHECK OPTION.
3. Experimental process:
1. Addition, deletion and modification of data:
Add a student:
insert into Student(Sno,Sname,Ssex,Sdept,Sage) values('201215128','TheShy','男','IS',18);
Change the age of student 201215121 to 22:
update student set Sage=22 where Sno='201215121';
Increase the age of all students by one year:
update student set Sage = Sage+1;
Delete student record with student number 201215128:
delete from Student where Sno='201215128';
2. View:
Create a view of information students:
create view IS_Student as select Sno,Sname,Sage from Student where Sdept='IS';
Establish a view of information department students, and still need to keep this view when editing and inserting operations are required. Only information department students:
create view IS_Student as select Sno,Sname,Sage from Student where Sdept='IS' with check option;
After the check option be coupled with the definition of the view the view to insert, delete, modify the deletion, the condition will automatically add Sdept='IS'
conditions.
Four, summary:
-
The view is a virtual table, which just provides a window for users to observe the underlying data. The data seen through the view will change with the change of the relational table.
-
The user can operate the view like a relational table, but the success of the operation depends on whether the operation on the view can be transformed by the DBMS into the operation on the corresponding base table.