View (virtual table)
The result set queried by select can be used as an alias as a virtual table
Views can only be added using cannot add modifications
Views cannot be built on other views, only one other entity table as the basis
Depending on the chart, the data will change with the entity table.
The role of the view:
Skip the process of writing table links
Two three tables can be linked together to make the query more visual.
/*============================ Code Demo =========================*/
--Code Creation view
CREATE VIEW SHITU2
As
Select *from Score,grade where score.degree between low and UPP
Go
Select *from shitu2 --Query the data inside the view
--Modify View
Alter VIEW Shitu--Modifying the view is equivalent to creating this
As
Select *from Student
Go
--Delete View
Drop View Shitu
--Triggers---Special stored procedures, which are automatically triggered by adding or deleting database tables.
Create Trigger Tr_student_insert
On student--Create a trigger on that table
For insert--insect is added meaning
As
Begin
Select *from Student
End
Go
INSERT into Student values (303, ' Yang ', ' Male ', ' 19901115 ', ' 95033 ')--Automatically triggers select *from Student query statements when adding data to the table
Create Trigger Tr_student_delete
On student
instead of delete --delete is the meaning of the deletion
As
Begin
print ' cannot be deleted '
End
Go
Delete from Student --Delete the Student table (not deleted due to the cause of the trigger)
Create Trigger Tr_student_inseted
On student
Instead of update--update is modified
As
Begin
--It's not a very similar story here, excuse me
End
Go
Inserted--Just a data table that can temporarily store data
Deleted--Just a data table that can temporarily store data
Insteadof--is triggered before the command
for--is triggered after the command, and for can also be written after
SQL views and triggers