Microsoft sql triggers tutorial


















Bulk Merge. Introduction A trigger is a special type of stored procedure, which is executed automatically after an event occurs. It is usually bound to a table and fires automatically. You cannot explicitly call any trigger. Previous Next. These triggers are created to prevent unauthorized access to the database and hence enhance its security. In the above example, we have simply printed a message after login. But we can use logon triggers to perform more complex operations such it can be used to limit the number of login events a user can perform, keeping a count of the number of logins on a daily basis, etc.

SQL triggers are scheduled procedures that get triggered or executed when a specified event occurs. They are primarily used to enhance the security and integrity of databases. This is a guide to Triggers in SQL. You can also go through our other suggested articles to learn more —. Submit Next Question. By signing up, you agree to our Terms of Use and Privacy Policy. We will use the employees table in the sample database for the demonstration.

Suppose we want to log the changes of values in the salary column. To do this, we create a separate table for storing the changes and use a trigger to insert the changes into this table. In the body of the trigger, we insert the changes if the new salary is different from the old one. Note that within the trigger body, we use the OLD and NEW keywords to access columns in the rows affected by a trigger.



0コメント

  • 1000 / 1000