SQL Server:删除FK约束,这不是外键 [英] SQL Server: drop a FK constraint, which is not foreign key

查看:1032
本文介绍了SQL Server:删除FK约束,这不是外键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用SQL Server 2008及其管理工作室。我正在做一个Web项目,它有一个工具来自动化表/关系创建。



我的web项目显示这个错误:

lockquote

不成功:alter table Tester add约束FK_c6c4bf4s2rvp56a32nnruww2b外键(游戏)引用Game $ p
$ b列'Game.id'与外键FK_c6c4bf4s2rvp56a32nnruww2b'中引用列Tester.game的数据类型不同


然而,当我在管理工作室中运行以下代码:

  ALTER TABLE dbo.Tester DROP CONSTRAINT FK_c6c4bf4s2rvp56a32nnruww2b 




消息3728,级别16,状态1,行1

'FK_c6c4bf4s2rvp56a32nnruww2b'不是一个约束。

b
3727级,16级,状态0,行1

无法删除约束。查看以前的错误。


我很困惑。什么类型的约束是 FK_c6c4bf4s2rvp56a32nnruww2b



如何删除它?



感谢和问候。

解决方案

没有这样的约束

第一个错误清楚地表明它不能创建该约束,因为涉及到这两列的数据类型( Game .Id Tester.Game )不匹配。



你应该做的是检查你是如何创建你的FK约束导致第一个错误 - 明确地给FK约束有意义的名字!


I am using SQL Server 2008 and its Management Studio. I am doing a web project, which has a tool to automate the tables/relationships creation.

My web project reveals this error:

Unsuccessful: alter table Tester add constraint FK_c6c4bf4s2rvp56a32nnruww2b foreign key (game) references Game

Column 'Game.id' is not the same data type as referencing column 'Tester.game' in foreign key 'FK_c6c4bf4s2rvp56a32nnruww2b'

However, when I ran the following in the management studio:

ALTER TABLE dbo.Tester DROP CONSTRAINT FK_c6c4bf4s2rvp56a32nnruww2b

I get the following:

Msg 3728, Level 16, State 1, Line 1
'FK_c6c4bf4s2rvp56a32nnruww2b' is not a constraint.
Msg 3727, Level 16, State 0, Line 1
Could not drop constraint. See previous errors.

I am confused. What type of constraint is FK_c6c4bf4s2rvp56a32nnruww2b?

How can I remove it?

Thanks and regards.

解决方案

There is no such constraint!

The first error clearly says that it could NOT create that constraint since the datatypes of those two columns involved (Game.Id and Tester.Game) do not match.

What you should do is check how you're creating your FK constraint that leads to that first error - and explicitly give that FK constraint a meaningful name!

这篇关于SQL Server:删除FK约束,这不是外键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆