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

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

问题描述

我正在使用 SQL Server 2008 及其 Management Studio.我正在做一个网络项目,它有一个工具可以自动创建表/关系.

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:

不成功:alter table Tester 添加约束 FK_c6c4bf4s2rvp56a32nnruww2b 外键(游戏)引用游戏

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

列Game.id"与外键FK_c6c4bf4s2rvp56a32nnruww2b"中引用列Tester.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

我得到以下信息:

消息 3728,第 16 级,状态 1,第 1 行
'FK_c6c4bf4s2rvp56a32nnruww2b' 不是约束.
消息 3727,第 16 级,状态 0,第 1 行
无法删除约束.查看以前的错误.

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.

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

I am confused. What type of constraint is FK_c6c4bf4s2rvp56a32nnruww2b?

我怎样才能删除它?

感谢和问候.

推荐答案

没有这个限制

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

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.

您应该做的是检查您是如何创建导致第一个错误的 FK 约束 - 并明确为该 FK 约束指定一个有意义的名称!

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天全站免登陆