Solved

How can I view the code on a trigger?

Posted on 2007-12-04
7
201 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
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…

747 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

12 Experts available now in Live!

Get 1:1 Help Now