Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Trigger help with 2 tables

Author  Topic 

diablokicks
Starting Member

5 Posts

Posted - 2009-11-18 : 16:29:56
Hey i was wondering if you guys could help me. I need to create a trigger for a view. I had two tables which i mixed together with a view, and now i need to create a INSTEAD OF INSERT trigger which puts the data back into both tables. Here is what i have so far....

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TRIGGER RowInsert
ON Combined
INSTEAD OF INSERT
AS
Declare @NewWorkid char(4), @NewTitle char(25), @NewDescription varchar(1000), @NewCopy char(8), @NewArtistId char(3)
Declare @NewTransactionId char(4), @NewDateAcquired datetime, @NewPurchaseDate datetime, @NewSalesPrice numeric(8,2), @NewAskingPrice numeric(8,2) @NewCustomerId char(3)
Declare @OldWorkid char(4), @OldTitle char(25), @OldDescription varchar(1000), @OldCopy char(8), @OldArtistId char(3)
Declare @OldTransactionId char(4), @OldDateAcquired datetime, @OldPurchaseDate datetime, @OldSalesPrice numeric(8,2), @OldAskingPrice numeric(8,2) @OldCustomerId char(3)

Select @NewWorkid = WorkId, @NewTitle = Title, @NewDescription = Description, @NewCopy = Copy, @NewArtistId = ArtistId, @NewTransactionId = TransactionId, @NewDateAcquired = DateAcquired, @NewAcquisitionPrice= AcquisitionPrice, @NewPurchaseDate = PurchaseDate, @NewSalesPrice = SalesPrice, @NewAskingPrice = AskingPrice, @NewCustomerId = CustomerId
from inserted

Select @OldWorkid = WorkId, @OldTitle = Title, @OldDescription = Description, @OldCopy = Copy, @OldArtistId = ArtistId, @OldTransactionId = TransactionId, @OldDateAcquired = DateAcquired, @OldAcquisitionPrice= AcquisitionPrice, @OldPurchaseDate = PurchaseDate, @OldSalesPrice = SalesPrice, @OldAskingPrice = AskingPrice, @OldCustomerId = CustomerId
from deleted

BEGIN


END
GO


I don't quite know the syntax which would put the two forms of data back in. Any help would be greatly appreciated.

X002548
Not Just a Number

15586 Posts

Posted - 2009-11-18 : 16:33:10
I didn't think you could create a trigger on a view



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

prakum
Starting Member

16 Posts

Posted - 2009-11-19 : 06:26:33
hi.. diablokicks......

we can create trigger on VIEW.....below is the link where you can found
the approriate syntax for the trigger creation

http://msdn.microsoft.com/en-us/library/aa258254(SQL.80).aspx

Praveen Kumar
Go to Top of Page
   

- Advertisement -