Link to home
Start Free TrialLog in
Avatar of VIVEKANANDHAN_PERIASAMY
VIVEKANANDHAN_PERIASAMY

asked on

Need a sample SQL Trigger for DDL statement that are execute on database

Need a sample SQL Trigger for DDL statement that are execute on database
Avatar of TempDBA
TempDBA
Flag of India image

Avatar of VIVEKANANDHAN_PERIASAMY
VIVEKANANDHAN_PERIASAMY

ASKER

sorry i missed to mention "truncate" statement. I want to capture only truncate statement exceute on my database.
Avatar of Tony303
Isn't a truncate statement a DML Statement
http://msdn.microsoft.com/en-us/library/ms189599(v=sql.105).aspx

The "truncation" trigger may not be possible...
see
http://msdn.microsoft.com/en-us/library/ms189799.aspx

specifically....

Although a TRUNCATE TABLE statement is in effect a DELETE statement, it does not activate a trigger because the operation does not log individual row deletions. However, only those users with permissions to execute a TRUNCATE TABLE statement need be concerned about inadvertently circumventing a DELETE trigger this way.
ASKER CERTIFIED SOLUTION
Avatar of TempDBA
TempDBA
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Temp
I see you are right DDL for Truncate.
I think that is incorrect...but hey... bigger brains than mine have decreed it so.

The way I see it... Truncate is manipulating the data, not changing the structure of the table. Hence DML not DDL.

T
Check out the msdn for truncate in the following link. You will find the command under DDL (on your left hand side panel)
http://msdn.microsoft.com/en-us/library/ms177570.aspx