473,432 Members | 1,717 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,432 software developers and data experts.

How to find the trigger that is changing a particular column. Any suggestions?

2
Large DB, I have manually checked all of the triggers that I can think of. Is there anyway to search for what trigger is affecting a specific column. SQL SERVER 2005.
THanks
Jul 29 '10 #1

✓ answered by Jerry Winston

99% of this kind of information is in the meta data in the sys.* views and tables. If you're in the SQL business it's definitely worth learning your sys meta data.

Try this:
Expand|Select|Wrap|Line Numbers
  1. SELECT S.name as [Schema] ,T.name as [Table] ,trg.name as [Trigger], definition FROM sys.triggers trg
  2. INNER JOIN sys.objects T
  3. ON
  4. trg.parent_id = T.object_id
  5. INNER JOIN sys.schemas S
  6. ON
  7. T.schema_id=S.schema_id
  8. INNER JOIN sys.sql_modules SQ
  9. ON
  10. SQ.object_id=trg.object_id
  11. ORDER BY T.name,trg.name
Or the long version:
Expand|Select|Wrap|Line Numbers
  1. SELECT
  2. SCHEMA_NAME(tbl.schema_id) AS [Table_Schema],
  3. tbl.name AS [Table_Name],
  4. tr.name AS [Name],
  5. trr.is_instead_of_trigger AS [InsteadOf],
  6. CAST(ISNULL(tei.object_id,0) AS bit) AS [Insert],
  7. CAST(ISNULL(ted.object_id,0) AS bit) AS [Delete],
  8. CAST(ISNULL(teu.object_id,0) AS bit) AS [Update],
  9. CASE WHEN tr.type = N'TR' THEN 1 WHEN tr.type = N'TA' THEN 2 ELSE 1 END AS [ImplementationType],
  10. CAST(OBJECTPROPERTYEX(tr.object_id,N'ExecIsAnsiNullsOn') AS bit) AS [AnsiNullsStatus],
  11. CAST(OBJECTPROPERTYEX(tr.object_id,N'ExecIsQuotedIdentOn') AS bit) AS [QuotedIdentifierStatus],
  12. NULL AS [Text],
  13. CAST(
  14.                 tr.is_ms_shipped
  15.             AS bit) AS [IsSystemObject],
  16. CASE WHEN ted.is_first = 1 THEN 0 WHEN ted.is_last = 1 THEN 2    ELSE 1 END AS [DeleteOrder],
  17. CASE WHEN tei.is_first = 1 THEN 0 WHEN tei.is_last = 1 THEN 2 ELSE 1 END AS [InsertOrder],
  18. CASE WHEN teu.is_first = 1 THEN 0 WHEN teu.is_last = 1 THEN 2    ELSE 1 END AS [UpdateOrder],
  19. ISNULL(smtr.definition, ssmtr.definition) AS [Definition]
  20. FROM
  21. sys.tables AS tbl
  22. INNER JOIN sys.objects AS tr ON (tr.type in ('TR', 'TA')) AND (tr.parent_object_id=tbl.object_id)
  23. LEFT OUTER JOIN sys.assembly_modules AS mod ON mod.object_id = tr.object_id
  24. INNER JOIN sys.triggers AS trr ON trr.object_id = tr.object_id
  25. LEFT OUTER JOIN sys.trigger_events AS tei ON tei.object_id = tr.object_id and tei.type=1
  26. LEFT OUTER JOIN sys.trigger_events AS ted ON ted.object_id = tr.object_id and ted.type=3
  27. LEFT OUTER JOIN sys.trigger_events AS teu ON teu.object_id = tr.object_id and teu.type=2
  28. LEFT OUTER JOIN sys.sql_modules AS smtr ON smtr.object_id = tr.object_id
  29. LEFT OUTER JOIN sys.system_sql_modules AS ssmtr ON ssmtr.object_id = tr.object_id
  30. WHERE
  31. (tbl.name=N'CurrentProfiles' and SCHEMA_NAME(tbl.schema_id)=N'PharmCAS2008')
  32. ORDER BY
  33. [Table_Schema] ASC,[Table_Name] ASC,[Name] ASC

3 2471
Jerry Winston
145 Expert 100+
99% of this kind of information is in the meta data in the sys.* views and tables. If you're in the SQL business it's definitely worth learning your sys meta data.

Try this:
Expand|Select|Wrap|Line Numbers
  1. SELECT S.name as [Schema] ,T.name as [Table] ,trg.name as [Trigger], definition FROM sys.triggers trg
  2. INNER JOIN sys.objects T
  3. ON
  4. trg.parent_id = T.object_id
  5. INNER JOIN sys.schemas S
  6. ON
  7. T.schema_id=S.schema_id
  8. INNER JOIN sys.sql_modules SQ
  9. ON
  10. SQ.object_id=trg.object_id
  11. ORDER BY T.name,trg.name
Or the long version:
Expand|Select|Wrap|Line Numbers
  1. SELECT
  2. SCHEMA_NAME(tbl.schema_id) AS [Table_Schema],
  3. tbl.name AS [Table_Name],
  4. tr.name AS [Name],
  5. trr.is_instead_of_trigger AS [InsteadOf],
  6. CAST(ISNULL(tei.object_id,0) AS bit) AS [Insert],
  7. CAST(ISNULL(ted.object_id,0) AS bit) AS [Delete],
  8. CAST(ISNULL(teu.object_id,0) AS bit) AS [Update],
  9. CASE WHEN tr.type = N'TR' THEN 1 WHEN tr.type = N'TA' THEN 2 ELSE 1 END AS [ImplementationType],
  10. CAST(OBJECTPROPERTYEX(tr.object_id,N'ExecIsAnsiNullsOn') AS bit) AS [AnsiNullsStatus],
  11. CAST(OBJECTPROPERTYEX(tr.object_id,N'ExecIsQuotedIdentOn') AS bit) AS [QuotedIdentifierStatus],
  12. NULL AS [Text],
  13. CAST(
  14.                 tr.is_ms_shipped
  15.             AS bit) AS [IsSystemObject],
  16. CASE WHEN ted.is_first = 1 THEN 0 WHEN ted.is_last = 1 THEN 2    ELSE 1 END AS [DeleteOrder],
  17. CASE WHEN tei.is_first = 1 THEN 0 WHEN tei.is_last = 1 THEN 2 ELSE 1 END AS [InsertOrder],
  18. CASE WHEN teu.is_first = 1 THEN 0 WHEN teu.is_last = 1 THEN 2    ELSE 1 END AS [UpdateOrder],
  19. ISNULL(smtr.definition, ssmtr.definition) AS [Definition]
  20. FROM
  21. sys.tables AS tbl
  22. INNER JOIN sys.objects AS tr ON (tr.type in ('TR', 'TA')) AND (tr.parent_object_id=tbl.object_id)
  23. LEFT OUTER JOIN sys.assembly_modules AS mod ON mod.object_id = tr.object_id
  24. INNER JOIN sys.triggers AS trr ON trr.object_id = tr.object_id
  25. LEFT OUTER JOIN sys.trigger_events AS tei ON tei.object_id = tr.object_id and tei.type=1
  26. LEFT OUTER JOIN sys.trigger_events AS ted ON ted.object_id = tr.object_id and ted.type=3
  27. LEFT OUTER JOIN sys.trigger_events AS teu ON teu.object_id = tr.object_id and teu.type=2
  28. LEFT OUTER JOIN sys.sql_modules AS smtr ON smtr.object_id = tr.object_id
  29. LEFT OUTER JOIN sys.system_sql_modules AS ssmtr ON ssmtr.object_id = tr.object_id
  30. WHERE
  31. (tbl.name=N'CurrentProfiles' and SCHEMA_NAME(tbl.schema_id)=N'PharmCAS2008')
  32. ORDER BY
  33. [Table_Schema] ASC,[Table_Name] ASC,[Name] ASC
Jul 30 '10 #2
tanner
2
Thank You very much, that is exactly what I needed.
Jul 30 '10 #3
NeoPa
32,556 Expert Mod 16PB
Thanks for responding Tanner.

I'll take that to mean you are happy for the post to be selected as Best Answer ;)
Aug 2 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Amos | last post by:
Can I add a column to the datagrid and also resize it? I add them like this: DataTableAddress.Columns.Add("Col1", typeof(string)); DataTableAddress.Columns.Add("Col2", typeof(string));...
1
by: VenuGopal | last post by:
Hii!! I have a datagrid which i am using for both dispaly and as well as taking input from the user. Noe there is a particular column which i need to lock, so that the user cannot enter...
5
by: hourlie | last post by:
I wrote a simple Web Service. It Consumes a single String, writes it to a text file on the hard drive, and returns a success. Now I need a trigger that will start the program that processes the...
2
by: redalpha | last post by:
Hi friends, I am facing problem in finding a code which should read particular column in text file.My code opens a file split it into an array & search the string but it search that...
4
by: ranjithgopalan | last post by:
Please help me to delete particular column by keeping primary key
1
by: Charls | last post by:
Hi, I need to be able to change individual column's colour in a series in bar charts, i.e. IF Column Value > Target THEN Column Colour = Green ELSEIF Column Value = Target THEN ...
1
kiss07
by: kiss07 | last post by:
Hi, I want to create a trigger in my applications. my recruitment is following: In a table emp every month particular(example 5th of every month) date is execute a trigger. How can i...
2
by: BSB | last post by:
Hi, I'm executing Excel macros with VB as my front end In my excel sheet... i have pivot tables... I need a macro that would change the particular column in the pivot table (say col K of the...
1
by: vinodkus | last post by:
dear sir/madam I have displayed data in gridview. after display of data i want some particular data from gridview by using index of that data in gridview. please tell me how it is possible like...
3
by: siva125 | last post by:
I use this query for my table but it retrives the value for each row. It does not retrieve the size of the column name. I need to know the number of characters occupied in particular column. How...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.