|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Wednesday, March 27, 2013 3:34 AM
Points: 165,
Visits: 405
|
|
Then, is there any way to fire the Trigger upon this Truncate action, as well?
In ' Thoughts ', Lonely Vampire
--In 'thoughts'... Lonely Rogue
|
|
|
|
|
Mr or Mrs. 500
      
Group: General Forum Members
Last Login: Wednesday, April 03, 2013 10:05 PM
Points: 584,
Visits: 1,571
|
|
Triggers are for INSERT, UPDATE, or DELETE only.
That is true, but not (I think) the purpose of today's QotD.
DELETE operates on the individual rows of a table, whereas TRUNCATE operates on the data pages. As each is logged differently there is no information about individual rows for the trigger to reference upon a TRUNCATE statement.
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Friday, September 02, 2011 3:22 AM
Points: 1,227,
Visits: 154
|
|
"TRUE or FASLE" - good question but in need of a spell check!
A simple experiment with "fasle" shows that the spell check ignores words in capitals!
|
|
|
|
|
Old Hand
      
Group: General Forum Members
Last Login: Friday, December 21, 2012 5:24 AM
Points: 366,
Visits: 436
|
|
hey Clive...good catch..
|
|
|
|
|
Hall of Fame
       
Group: General Forum Members
Last Login: Yesterday @ 6:30 AM
Points: 3,192,
Visits: 4,151
|
|
SanjayAttray (2/6/2010) Triggers are for INSERT, UPDATE, or DELETE only. Correction: DML triggers are for INSERT, UPDATE, or DELETE only.
There are also DDL triggers for a wide variety of DDL events. I answered wrong because I thought that TRUNCATE could generate a DDL event  Actually TRUNCATE looks like a DDL statement, because it requests a schema modification lock:
CREATE TABLE test (a INT)
BEGIN TRANSACTION
TRUNCATE TABLE test
SELECT * FROM sys.dm_tran_locks WHERE request_session_id = @@SPID AND resource_type = 'OBJECT' AND resource_associated_entity_id = OBJECT_ID('test')
ROLLBACK
DROP TABLE test In the example above, we will see request_mode = Sch-M (schema modification). This is specific to DDL events.
|
|
|
|
|
Mr or Mrs. 500
      
Group: General Forum Members
Last Login: Friday, March 15, 2013 10:35 AM
Points: 594,
Visits: 654
|
|
Christian Buettner-167247 (2/5/2010) I wonder why there is no DDL trigger available to capture this of event...
Because it is a DML event, the structure of the table is not changing, just the data in it? Sound right experts?
Peter Trast Microsoft Certified ...(insert many literal strings here) Microsoft Design Architect with Alexander Open Systems
|
|
|
|
|
Mr or Mrs. 500
      
Group: General Forum Members
Last Login: Friday, March 15, 2013 10:35 AM
Points: 594,
Visits: 654
|
|
SanjayAttray (2/6/2010) Back to basics. Most of the time I select wrong answer for basic and simple question. Triggers are for INSERT, UPDATE, or DELETE only.
For DML, yes...
Or... CREATE, ALTER, etc.... for DDL...
Peter Trast Microsoft Certified ...(insert many literal strings here) Microsoft Design Architect with Alexander Open Systems
|
|
|
|
|
Mr or Mrs. 500
      
Group: General Forum Members
Last Login: Friday, March 15, 2013 10:35 AM
Points: 594,
Visits: 654
|
|
petertrast (3/3/2010)
SanjayAttray (2/6/2010) Back to basics. Most of the time I select wrong answer for basic and simple question. Triggers are for INSERT, UPDATE, or DELETE only.For DML, yes... Or... CREATE, ALTER, etc.... for DDL...
OK, I promise to read all posts before replying
Peter Trast Microsoft Certified ...(insert many literal strings here) Microsoft Design Architect with Alexander Open Systems
|
|
|
|
|
Hall of Fame
       
Group: General Forum Members
Last Login: Yesterday @ 6:30 AM
Points: 3,192,
Visits: 4,151
|
|
petertrast (3/3/2010)
Christian Buettner-167247 (2/5/2010) I wonder why there is no DDL trigger available to capture this of event...Because it is a DML event, the structure of the table is not changing, just the data in it? By the way, Oracle documentation contains an explicit list of DDL statements: http://download.oracle.com/docs/cd/E11882_01/server.112/e10592/statements_1001.htm#sthref2301. TRUNCATE is in that list. So, at least in Oracle it is not a DML event.
Unfortunately, I didn't find the similar list for MSSQL. However, these two quotes from BOL implicitly say that TRUNCATE belongs to DDL: http://msdn.microsoft.com/en-us/library/ms177570.aspx
TRUNCATE TABLE (Transact-SQL)
Permissions -------------------------------------------------------------------------------- The minimum permission required is ALTER on table_name. TRUNCATE TABLE permissions default to the table owner, members of the sysadmin fixed server role, and the db_owner and db_ddladmin fixed database roles
OK, who's that guy with db_ddladmin permissions? http://msdn.microsoft.com/en-us/library/ms189121.aspx
Database-level role name: db_ddladmin Description: Members of the db_ddladmin fixed database role can run any Data Definition Language (DDL) command in a database.
So, db_ddladmin can run any DDL command; db_ddladmin can run TRUNCATE TABLE. This means TRUNCATE is a DDL command, I believe
|
|
|
|
|
SSChampion
        
Group: General Forum Members
Last Login: Today @ 5:01 PM
Points: 10,990,
Visits: 10,545
|
|
vk-kirov (3/3/2010)
So, db_ddladmin can run any DDL command; db_ddladmin can run TRUNCATE TABLE. This means TRUNCATE is a DDL command, I believe  Crows are birds. All crows are black. Therefore, all birds are black.
Oh dear.
Paul White SQL Server MVP SQLblog.com @SQL_Kiwi
|
|
|
|