Solved

How can I view the code on a trigger?

Posted on 2007-12-04
7
202 Views
Last Modified: 2010-04-21
Lest asume that I have used the following syntax to find the name of a trigger in Computers DB and  I need to modify it.
Select * From [Computers].dbo.sysobjects Where xtype = 'TR'

Also, asume that I don't know were the code file resides for the trigger.

How can I get to view the code on this trigger? Is there a sql syntax for this?

I am using SQL Server Express.
0
Comment
Question by:vielkacarolina1239
  • 3
  • 2
  • 2
7 Comments
 
LVL 3

Expert Comment

by:Martin-Smith
ID: 20402802
sp_help 'triggername'
0
 
LVL 3

Assisted Solution

by:Martin-Smith
Martin-Smith earned 125 total points
ID: 20402846
Sorry that doesn't work.

select text from syscomments where id = object_id('triggerName') does but you may need to concatenate if multipe rows are returned
0
 
LVL 7

Accepted Solution

by:
bungHoc earned 375 total points
ID: 20402871
sp_helptext 'dbo.nameOfTrigger' -- assuming you know the name.

If you don't know the name..  well.. this will help you find all  related to one table.
SELECT DISTINCT so.name
FROM syscomments sc
INNER JOIN sysobjects so on sc.id=so.id
WHERE sc.text LIKE '%tablename%'
0
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 

Author Comment

by:vielkacarolina1239
ID: 20402905

I ran the syntax:  sp_help 'myTrgger'

The Result pane returns the Name of the trigger, Woner, Type, Create_Date.

However, I need to see the code on this trigger. When I run the above syntax, is there a pane I need to open to view and alter the code on this trigger?

Thanks
0
 
LVL 7

Assisted Solution

by:bungHoc
bungHoc earned 375 total points
ID: 20402961
Anyway.. for every table, when you click to expand, you'll see a bunch of folders Columns, Keys, Constraints, Indexes, Statistics and..... Triggers.

If you have right permissions, you should see triggers.
If they're not encrypted.. view it..
0
 
LVL 3

Expert Comment

by:Martin-Smith
ID: 20402981
I told you wrong . bungHoc got it right with sp_helptext
0
 

Author Closing Comment

by:vielkacarolina1239
ID: 31412579
Thanks guys, you are great. Both solutions work. buhgHoc solution is a little cleaner than marting. But, both work.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now