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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Accessing tables in other databases in triggers

Author  Topic 

Utpal
Posting Yak Master

179 Posts

Posted - 2002-04-06 : 01:16:56
Hi everybody,
Is it possible to access a table in another database in a database trigger? Something like a statement in an Update trigger of Purchase_Orders table in InvMEDI2001 database :

SELECT @LastDate = LastDate
FROM InvCommon.Company
WHERE Year(FirstDate) = 2001

where InvCommon is the name of another database and Company is a table in it ?



smccreadie
Aged Yak Warrior

505 Posts

Posted - 2002-04-06 : 07:16:19
According to BOL,

You can create a trigger only in the current database, although a trigger can reference objects outside of the current database.

I'd recommend caution because if the reference database is down, the trigger will fail.


Go to Top of Page

Utpal
Posting Yak Master

179 Posts

Posted - 2002-04-07 : 00:09:49
Thanks ! How is a table in an outside database to be referenced ? The table name I want to reference is "Company" and the name of the outside database is "InvCommon".

Go to Top of Page

Nazim
A custom title

1408 Posts

Posted - 2002-04-07 : 01:00:13
by using four part naming convention.

servername.databasename.owner.tablename

if the server is same . you can reference your table by using
invCommon.dbo.company

HTH

--------------------------------------------------------------
Go to Top of Page

Utpal
Posting Yak Master

179 Posts

Posted - 2002-04-08 : 02:09:39
Thanks a lot Nazim !

Go to Top of Page
   

- Advertisement -