Sunday, June 27, 2010

Cross-database foreign keys

What will be the output of the following scripts?

CREATE DATABASE db1;
CREATE DATABASE db2;
USE db1;
CREATE TABLE tb1
(
 AutoID INT NOT NULL PRIMARY KEY IDENTITY(1,1),
 FKID INT NOT NULL
);
USE db2;
CREATE TABLE tb2
(
 AutoID INT NOT NULL PRIMARY KEY IDENTITY(1,1),
 FKID INT NOT NULL,
 FOREIGN KEY (FKID) REFERENCES db1.dbo.tb1(AutoID)
);
A. The scripts run successfully
B. Error occurs and mean that wrong referrer: db1.dbo.tb1
C. Error occurs and mean that cross database foreign key references are not supported
D. Error shows that wrong syntax when creating foreign key

Answer:[C]
Highlight to find out the answer.

No comments:

Post a Comment