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
 Adding Triggers to Databases

Author  Topic 

DavidChel
Constraint Violating Yak Guru

474 Posts

Posted - 2008-09-17 : 15:05:51
So, if I run the following trigger, it works when using the query analyzer and the database name selected in the toolbar.

CREATE TRIGGER SOMAddExtras
ON M2MData01.dbo.SOitem
AFTER INSERT
AS
SET NOCOUNT ON

IF EXISTS (SELECT dbo.somast.fsono
FROM dbo.somast
INNER JOIN
inserted
ON dbo.somast.fsono = inserted.fsono
WHERE somast.fstatus = 'Open')
BEGIN

UPDATE SOM
SET SOM.fprodcl = I.fprodcl,
SOM.fpartno = I.fpartno,
SOM.fgroup = I.fgroup
FROM [CheltonCustomizations].[dbo].[soMods] SOM
INNER JOIN
inserted I
ON SOM.FSONO = I.FSONO AND SOM.FENUMBER = I.FENUMBER
END
GO


However, when I try to add various items to various databases, I don't know the proper syntax to change the "assigned" database between scripts.

Does that make sense? Do I assign the database to be affected with the USE statement?

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2008-09-17 : 15:13:14
use dbName
GO
create trigger ...

_______________________________________________
Causing trouble since 1980
Blog: http://weblogs.sqlteam.com/mladenp
Speed up SSMS development: www.ssmstoolspack.com <- version 1.0 out!
Go to Top of Page

DavidChel
Constraint Violating Yak Guru

474 Posts

Posted - 2008-09-17 : 15:37:36
Thanks Spirit.
Go to Top of Page
   

- Advertisement -