Solved

How can I view the code on a trigger?

Posted on 2007-12-04
7
205 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
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 

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

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

809 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