删除SQL Server Compact 3.5中的ForeignKey约束 [英] Delete ForeignKey Constraint in SQL Server Compact 3.5

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

问题描述





我现在正在寻找解决方案几个小时。我在sql_ce中创建了一个包含以下查询的表:

Hi,

i am searching for a solution for a few hours now. I created a table in sql_ce with the follwoing query:

CREATE TABLE [Customer]
([_id] int NOT NULL  IDENTITY (1,1),
[firstName] nvarchar(4000) NULL,
[lastName] nvarchar(4000) NULL,
[sex] nvarchar(4000) NULL,
[orderAddress_fk] int NULL,
[deliveryAddress_fk] int NULL,
[paymendMethod_fk] int NULL,
[emailAddress] nvarchar(4000) NULL,
[phone] nvarchar(4000) NULL,
[mobilePhone] nvarchar(4000) NULL,
[company] nvarchar(4000) NULL);



并添加了一个foreignkeyconstraint。它是成功创建的,因为我无法放弃那张桌子。我使用了以下查询:


and added a foreignkeyconstraint. it was created succesfully, because i am not able to drop that table. i used the following query:

ALTER TABLE Customer
ADD CONSTRAINT orderAddress_fk
FOREIGN KEY (orderAddress_fk) REFERENCES Address(_id)



所以我想放弃约束并尝试以下命令:




so i want to drop the constraint and tried the follwing commands:

ALTER TABLE [Customer]
ALTER COLUMN orderAddress_fk
DROP DEFAULT




ALTER TABLE [Customer]
DROP CONSTRAINT orderAddress_fk



查询执行成功但执行后,我仍然无法删除表,并且UI显示约束仍然存在...



i不知道该怎么办...:(


the query executes with succes but after executing, i am still not able to drop the table, and the UI shows that the constraint still exists...

i dont know what to try else... :(

推荐答案

I找到解决方案:



如果要通过查询删除外键,请确保已命名约束并使用此名称删除它。所以我将创建外键查询更改为:

I found the solution:

if you want to delete a foreignkey via query, make sure that you have named your constraint and delete it by this name. so i changed my create foreign key query to:
ALTER TABLE [Customer]
ADD CONSTRAINT FK_deliveryAddress FOREIGN KEY (deliveryAddress_fk)
REFERENCES [Address](_id)
GO



现在我可以使用此查询删除它:


And now i can delete it with this query:

ALTER TABLE[Customer]
DROP CONSTRAINT FK_deliveryAddress



感谢ZoltánZörgő他的帮助......


Thanks to Zoltán Zörgő for his help...


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

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