CREATE TABLE #TableTest1 (
ID INT NOT NULL,
CONSTRAINT PK_ID1 PRIMARY KEY(ID)
CREATE TABLE TableTest2 (
ID INT NOT NULL
CONSTRAINT FK_TableTest1_ID FOREIGN KEY (ID) REFERENCES #TableTest1(ID)
INSERT INTO #TableTest1 (ID)
INSERT INTO TableTest2 (ID)
select * from #TableTest1
select * from TableTest2
The query will complete successfully
The query will complete successfully and insert a row into both tables regardless of the foreign key constraint. SQL Server does not enforce foreign key constraints on temporary tables.
I got the following errors:
Msg 1766, Level 16, State 0, Line 6
Foreign key references to temporary tables are not supported. Foreign key 'FK_TableTest1_ID'.
Msg 1750, Level 16, State 0, Line 6
Could not create constraint. See previous errors.
Neither table was created.