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 2005 Forums
 Transact-SQL (2005)
 Foreign key reference issue

Author  Topic 

zion99
Posting Yak Master

141 Posts

Posted - 2008-06-12 : 02:12:26
Hi All,

Table FACT1 is located on SERVER1 & Database - DBS1 (SQL Server 2000) with a column 'Date_fk'
Table DIM1 is located on SERVER2 & Database - DBS2 (SQL Server 2005) with a column 'Date_pk'.

I m trying to create a foreign key relation ship as follows:

ALTER TABLE [dbo].[FACT1] WITH CHECK ADD
CONSTRAINT [FK_Issue] FOREIGN KEY([Date_fk])
REFERENCES [SERVER2].[DBS2].[DIM1] ([Date_pk])

but it throws the foll. error
Foreign key 'FK_Issue' references invalid table 'SERVER2.DBS2.DIM1'.

Please let me know if i m missing anything.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-06-12 : 02:24:48
You cant create foreign key references across databases. the referring table and referred table should be in same db.
You can however have a Trigger which checks the does job of foreign key i.e check if data to be inserted is a valid value in parent table and then perform insert.
Go to Top of Page
   

- Advertisement -