Solved

How can I view the code on a trigger?

Posted on 2007-12-04
7
204 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
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 

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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

832 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