Hi All,
I created a new database and 2 tables inside but one of the tables has foreign key which can not be created as I'm getting error on the foreign key...
Can we set foreign key constarint to a table in another database? This is what I've done:
use new_database
go
create table Sample(
sample_id varchar(30) not null,
sample_type char(1) not null,
update datetime not null,
primary key(sample_id, sample_type)
foreign key (sample_id) Refrences Different_DB.table_name(Sample_id)) /* This is not working. */
I want to link the "sample_id" here in Sample table to another table in a different database which has "sample_id" as PK there.
Should I link this new database to the other databases? If so, how can I create that link?
Thanks a lot for all your comments!
I created a new database and 2 tables inside but one of the tables has foreign key which can not be created as I'm getting error on the foreign key...
Can we set foreign key constarint to a table in another database? This is what I've done:
use new_database
go
create table Sample(
sample_id varchar(30) not null,
sample_type char(1) not null,
update datetime not null,
primary key(sample_id, sample_type)
foreign key (sample_id) Refrences Different_DB.table_name(Sample_id)) /* This is not working. */
I want to link the "sample_id" here in Sample table to another table in a different database which has "sample_id" as PK there.
Should I link this new database to the other databases? If so, how can I create that link?
Thanks a lot for all your comments!