2014-12-04 views, triggers

Source: Internet
Author: User

View : Treat a query result set as a table

Example: SELECT * FROM (SELECT * from Score,grade where score.degree between Low and UPP) as Jieguotable

where rank= ' A '

as a virtual table after as

CREATE VIEW SHITU1

As

SELECT * FROM Student,score where Student.sno=score.sno

Go

As and go are actually tables connected, the columns in the table cannot be coincident

View can only query use, can not delete data, the equivalent of saving a piece of data in

Trigger: A special stored procedure that is raised by adding or deleting a database.

Mouse actions: a database → programmability → database triggers

Example: Create TRIGGER Tr_student_insert---(Naming rules: TR is a trigger, which table is student, Insert is triggered when a new action is added)

On student---which table is acting on

For inserts------for is a new trigger, and for can also be written after

As

Begin

SELECT * FROM Student

End

Go

INSERT into student values (' 303 ', ' xiaoming ', ' Male ', ' 1992-07-21 ', ' 95033 ')

-----After adding the above data, trigger the query

Replace:

Create Trigger Tr_student_delete
On student
Instead of delete
As
Begin
DECLARE @sno int
Select @sno =sno from deleted
Delete from score where [email protected]
Delete from student where [email protected]
End
Go
Delete from Student where sno=304
Select *from Student
INSERT into score values (304, ' 3-105 ', 98)

Deleted is temporarily deleted, containing the contents of the delete action you will be performing

Insert for temporary increase

Create Trigger Tr_student_inserted
On student
Instead of insert
As
Begin
declare @sno int, @sname varchar, @ssex varchar (20),
@sbirthday datetime, @class varchar (20)
Select @sno =sno, @sname =sname, @ssex =ssex, @sbirthday =sbirthday, @class =class from inserted
If @ssex = ' Male '
Begin
Set @ssex = ' 1 '
End
INSERT into student values (@sno, @sname, @ssex, @sbirthday, @class)
End
Go
INSERT into student values (303, ' Billiton ', ' Male ', ' 1992-07-21 ', ' 95033 ')
Select *from Student

2014-12-04 views, triggers

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.