SunQuest
           Database Management
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesDatabase Management

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
AT&T devCentral & BlackBerry(r) Webcast Series: BlackBerry and GPS -Build Location Awareness into your BlackBerry Applications, July 10th-1:00PM EST. Register Today!
  #1  
Old August 14th, 2003, 12:30 PM
klyn klyn is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 1 klyn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
SQL trigger

I'm new to using triggers and have an assignment to add triggers to my database tables. Of coarse the person who asked me to do this is out of town, so I'm hoping someone can help.

This is what needs to be saved as the trigger (called trg_jrn_Org.sql):

if exists (select * from dbo.sysobjects where id = object_id('dbo.trg_jrn_Org') and OBJECTPROPERTY(id, 'IsTrigger') = 1)
drop trigger dbo.trg_jrn_Org
GO

CREATE TRIGGER trg_jrn_Org ON dbo.Org
FOR UPDATE
AS
BEGIN
UPDATE org
SET jrn_dt = GETDATE()
, jrn_host_nm = HOST_NAME()
, jrn_app_nm = APP_NAME()
WHERE org_id IN (SELECT org_id FROM INSERTED)
END

GO

So do I save this as a sep. file? or does all of this go directly into the trigger properties text area and replaces this:

CREATE TRIGGER [TRIGGER NAME] ON [dbo].[Wkly_Rprt]
FOR INSERT, UPDATE, DELETE
AS


or something else?

Reply With Quote
  #2  
Old August 14th, 2003, 01:18 PM
WineIsGood's Avatar
WineIsGood WineIsGood is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: New York
Posts: 49 WineIsGood User rank is Private First Class (20 - 50 Reputation Level)WineIsGood User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 7 m 51 sec
Reputation Power: 6
That's the whole code. It will create the trigger. Just go into iSQL and paste it and run it. You can see all your triggers by using Enterprise Manager. Right-click the table and choose All Tasks -> Triggers, then choose the type of trigger from the drop-down menu... there are only three: delete, insert, and update.
-Dave

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesDatabase Management > SQL trigger


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway