May 16, 2011 at 5:49 pm
Hello, I'm trying to know how to check if my database triggers and other objects are invoking tables that it's not exist.
The problem begin cause I have a database from an ERP software with a lot of tables that we don't need. I'm dropping 200 tables at least, and this work it's really easy. the system have 323 tables after de cleaning.
All the referential integrity work with triggers not forean keys!!!! I know that bad, but that is that we have.:w00t:
The problem is that many triggers refers to tables that were dropped. Instead of a manual check, how can I check my triggers, UDF, SP_ ?
There's a software tool?, some script?:cool:
I thanks in advance!;-)
May 16, 2011 at 6:45 pm
The advertising above has been reported. Now, to the OP's question...
Earl Downs (5/16/2011)
Hello, I'm trying to know how to check if my database triggers and other objects are invoking tables that it's not exist.The problem begin cause I have a database from an ERP software with a lot of tables that we don't need. I'm dropping 200 tables at least, and this work it's really easy. the system have 323 tables after de cleaning.
All the referential integrity work with triggers not forean keys!!!! I know that bad, but that is that we have.:w00t:
The problem is that many triggers refers to tables that were dropped. Instead of a manual check, how can I check my triggers, UDF, SP_ ?
There's a software tool?, some script?:cool:
I thanks in advance!;-)
The easiest way to do this is to use the DMVs and search for those table names in the triggers.
For example (this is the oldschool way but will work in 08)
DECLARE @tablename VARCHAR(500)
SET @tablename = 'MyTableHere'
select
o.name
from
sys.sysobjects as o
join
sys.syscomments as c
ono.id = c.id
where
c.text like '%' + @tablename + '%'
AND o.type = 'tr'
sys.syscomments.text holds the actual declaration of the create trigger statement in it. There's a few new dmvs that let you get there too but I can't remember them off the top of my head...
EDIT: TR, not T, whoops.
Never stop learning, even if it hurts. Ego bruises are practically mandatory as you learn unless you've never risked enough to make a mistake.
For better assistance in answering your questions[/url] | Forum Netiquette
For index/tuning help, follow these directions.[/url] |Tally Tables[/url]
Twitter: @AnyWayDBA
May 16, 2011 at 11:35 pm
sysobjects and syscomments are deprecated, are included only for backward compatibility, will be removed in a future version of SQL and should not be used any longer.
Use sys.objects and sys.sql_modules instead.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
May 17, 2011 at 12:21 am
select object_definition(object_id),name from sys.all_objects
where type = 'TR' and object_definition(object_id) like '%your table name%'
you have to create a table of tables list which those you have dropped then create a loop and replace [your table name] with your tables list
sys.triggers also available for this
Regards,
Syed Jahanzaib Bin Hassan
BSCS | MCTS | MCITP | OCA | OCP | OCE | SCJP | IBMCDBA
My Blog
www.aureus-salah.com
May 17, 2011 at 10:18 am
Thanks, we really need to thinks in the future.
Regards.
May 17, 2011 at 10:20 am
Thanks very much, the script is very practical and functional.
Best Regards
May 17, 2011 at 10:39 am
What's the point of removing those tables? I've never seen anyone do such a project in those circumstances that anything else than headaches.
May 17, 2011 at 2:52 pm
Our ERP software was provided for someone that now not exists. And this tables don't matter to us because we don't have the respective application modules. Simply are garbage for our programmers and DBA's.
Regards!
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply