.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> SQL Query >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Trigger for insert

Posted By:Abhisek Panda       Posted Date: November 30, 2009    Points: 10    Category: SQL Query    URL: http://www.dotnetspark.com  
 

CREATE TRIGGER ti1 ON Student FOR INSERT AS Print 'Record inserted successfully'

It will create a trigger for insert operation in the student table. The database and table must exists and the trigger should be unique.

INSERT Student VALUES("Abhisek", 108)

The output will be the following:

Record inserted successfully
1 row(s) affected

Let us see another trigger,
CREATE TRIGGER ti2 ON Student FOR INSERT AS select*from inserted


Here inserted is a logical table and structure is similar to the table on which the trigger is defined. That is the table on which the user action is attempted, and new values of the rows that may be changed by the user action.

Now fire this trigger, and see the output. It will display the data we just entered.
INSERT Student VALUES("Abinash", 107)

Name Roll
Abinash 107
1 row(s) affected

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend