This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JDBC and the fly likes How to check if triggers are enabled in MS SQL Server database? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "How to check if triggers are enabled in MS SQL Server database?" Watch "How to check if triggers are enabled in MS SQL Server database?" New topic
Author

How to check if triggers are enabled in MS SQL Server database?

tom chansky
Greenhorn

Joined: Nov 01, 2004
Posts: 28
Does anyone know how to use JDBC to programmatically check if triggers are enabled in a SQL Server database?
Omar Al Kababji
Ranch Hand

Joined: Jan 13, 2009
Posts: 357
Hi Tom I am not sure but try executing this query using your favourite SQL query browser

SELECT T.[name] as TableName, TR.[Name] as TriggerName,
CASE WHEN 1=OBJECTPROPERTY(TR.[id], 'ExecIsTriggerDisabled')THEN 'Disabled' ELSE 'Enabled' END Status
FROM sysobjects T INNER JOIN sysobjects TR on t.[ID] = TR.parent_obj WHERE (T.xtype = 'U' or T.XType = 'V')
AND (TR.xtype = 'TR') ORDER BY T.[name], TR.[name]


this should give you a list of the triggers in your DB and their status.

if the query is ok then you can use java to play with the result and do your busniss logic. for example if they are all disabled then it means that triggers are disabbled.


hope it helps

(peace)


Omar Al Kababji - Electrical & Computer Engineer
[SCJP - 90% - Story] [SCWCD - 94% - Story] [SCBCD - 80% - Story] | My Blog
tom chansky
Greenhorn

Joined: Nov 01, 2004
Posts: 28
thank you for the solution. I think that select query would be very helpful.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

If this is MS SQL 2005 or newer the easier approach is to use the sys.triggers view.

This:

will give you a count of all enabled triggers in your schema.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to check if triggers are enabled in MS SQL Server database?
 
Similar Threads
Prolem in connection to Microsoft sql SErver
Commit problem
Notifiying EJB when database table changes
java event on sql insert
what are procedures in sql ?