SQL Server Performance

  • Home
  • Articles
  • Forums
  • Tips
  • Training
  • FAQ's
  • Blogs
  • Software
  • Books
  • About Us
RSS Feeds
Sign in | Join


Article Topics

All Articles
Performance Tuning
Audit
Business Intelligence
Clustering
Reporting Services
SQL Azure
Developer
General DBA
ASP.NET / ADO.NET
SQL Azure

USEFUL SITES :

ASP.NET Tutorials
Windows and SQL Azure Tutorials
Cloud Hosting Magazine
SharePoint Tutorials
Windows Server Help

Write for Us

Share your SQL Server knowledge with others and raise your profile in the community More...
Latest Articles

A High Level Comparison Between Oracle and SQL Server - Part ...
A High Level Comparison Between Oracle and SQL Server - Part ...
A High Level Comparison Between Oracle and SQL Server - Part ...
A High Level Comparison Between Oracle and SQL Server

More     
 
Latest FAQ's

Add Node to A SQL Server failover Cluster failed with invalid ...
SQL Server Destination remote server error
Setting Up Data And Log Files For SQL Server
Will Check Constraints Improve Database Performance?

More     
   
Latest Software Reviews

dbForge Review
Spotlight on ApexSQL Diff - Server-based database comparison tool ...
Spotlight on ApexSQL Data Diff - Server-based database comparison tool ...
Spotlight on ApexSQL Doc 2008

More     

articles >> developer >> Implementing Triggers in SQL Server 2000 ...

Implementing Triggers in SQL Server 2000

By : Navneeth Diwaker Naik
Aug 31, 2004

Page 3 / 6

From the output we can conclude that when the user tries to insert data in the table USER_MASTER, three triggers are executed automatically. That is, you can write several AFTER triggers on one table for each of the three triggering actions.

Similarly, we can write several AFTER triggers on DELETE and UPDATE triggering actions.

Note: If a table has multiple AFTER triggers, then you can specify which trigger should be executed first and which trigger should be executed last using the stored procedure sp_settriggerorder. All the other triggers are in an undefined order which you cannot control.

An AFTER trigger can be created only on tables, not on views.

Using the script below, first we shall create a simple view [vwUserMaster] which will fetch the Username and Password from the table USER_MASTER.

 

Create View vwUserMaster

as

SELECT USERNAME, PASSWORD FROM USER_MASTER

GO

 

CREATE TRIGGER trgOnView

ON vwUserMaster

FOR INSERT

AS

BEGIN

        Print ('AFTER Trigger [trgOnView]  – vwUserMaster !!')

END

GO

 

Output

Server: Msg 208, Level 16, State 4, Procedure trgOnView, Line 2

Invalid object name 'vwUserMaster'.

From the Output we can conclude that we cannot create an AFTER trigger on views.

Like stored procedures and views, triggers can also be encrypted. The trigger definition is then stored in an unreadable form. Once encrypted, the definition of the trigger cannot be decrypted and cannot be viewed by anyone, including the owner of the trigger or the system administrator.

 

CREATE TRIGGER trgEncrypted

ON User_Master WITH ENCRYPTION

FOR INSERT 

AS

BEGIN

      Print ('AFTER Trigger [trgEncrypted] Encrypted  – Trigger executed !!')

END

GO

 

SELECT    

             sysobjects.name AS [Trigger Name],

             SUBSTRING(syscomments.text, 0, 26) AS [Trigger Definition],

             OBJECT_NAME(sysobjects.parent_obj) AS [Table Name],

             syscomments.encrypted AS [IsEncrpted]

 

FROM

             sysobjects INNER JOIN syscomments ON sysobjects.id = syscomments.id

WHERE   

             (sysobjects.xtype = 'TR')

 

Output

Trigger Name  Trigger Definition          Table Name   IsEncrpted

-----------------------------------------------------------------

trgInsert      CREATE TRIGGER trgInsert    User_Master      0

trgInsert1     CREATE TRIGGER trgInsert1   User_Master      0

trgInsert2     CREATE TRIGGER trgInsert2   User_Master      0

trgEncrypted   ???????????????            User_Master      1


<< Prev Page     Next Page>>    








C# Help and Tutorials | PHP MySQL Tutorial | Sharepoint Tutorial | Azure Tutorial | Cloud Hosting Magazine | ASP.NET Tutorials | Windows Server Help | Windows Phone Pro | Silverlight Ace | Visual Studio Tutorials | Home | Peformance Articles | Audit Articles | Business Intelligence Articles | Clustering Articles | Developer Articles | Reporting Services Articles | DBA Articles | ASP.NET / ADO.NET Articles | SQL Server Training Videos | DBA FAQ's | Developer Peformance FAQ's | DBA Peformance FAQ's | Developer FAQ's | Clustering FAQ's | Error Messages | Audit Tool Reviews | Backup Tool Reviews | Coding Tool Reviews | Compare Tool Reviews | Documentation Tool Reviews | Design Tool Reviews | Monitoring Tool Reviews | Log Tool Reviews | Reporting Tool Reviews | Clustering Tool Reviews | Security Tool Reviews | Change Management Tool Reviews | Remote Access Tool Reviews | Book Reviews | Security Tool Reviews | ADO.NET / ASP.NET | Administration | Analysis/OLAP Services | Application Development | Configuration | Components | ETL | Hardware | High Availability | Hints | Index | Misc | Operating Systems | Performance Tuning | Replication | T-SQL | Views


              © 2010 Jude O'Kelly. All rights reserved