可能是您的外键正在表中查找的不是默认模式(可能是
dbo)。在这种情况下,
object_id直到您指定架构,您才能看到以下内容:
SELECT OBJECT_ID(N'<schema>.FK_Name', N'F')
实际上,您的数据库中可能有多个具有相同名称的对象,但它们位于不同的模式中。
OBJECT_ID(N'FK_Name',N'F')将在默认架构中返回对象的ID。
您可以像这样测试它:
create schema testcreate table test.temp1 (id int primary key)create table test.temp2 (id int)goalter table test.temp2 add constraint FK_temp foreign key(id) references test.temp1(id)select object_id('FK_temp', 'F') -- returns nullselect object_id('test.FK_temp', 'F') -- returns object iddrop table test.temp2drop table test.temp1drop schema test
[sql fiddle demo](http://sqlfiddle.com/#!6/c0059/1)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)