简体   繁体   English

SQL Server 2008不允许我添加外键

[英]SQL Server 2008 won't let me add foreign keys

I've been using SQL Server for years, so I'm not a noob. 我已经使用SQL Server多年了,所以我不是菜鸟。 I've recently been having problems where I can't add a foreign key to certain tables in my database using SQL Management Studio and SQL Server 2008 Express. 我最近遇到了一些问题,我无法使用SQL Management Studio和SQL Server 2008 Express向数据库中的某些表添加外键。 The table I'm trying to reference is there and it has a primary key (with the primary key constraint created), but it doesn't show up in the list of tables that I can choose from when I'm trying to add the FK. 我正在尝试引用的表是存在的,它有一个主键(创建了主键约束),但是当我尝试添加时,它不会显示在我可以选择的表列表中FK。

If I try and add the FK through plain old T-SQL, the query succeeds, but if I view the new FK using the UI, the primary key table dropdown is empty. 如果我尝试通过普通的旧T-SQL添加FK,查询会成功,但如果我使用UI查看新的FK,则主键表下拉列表为空。 The FK is there and it actually does work if I try to insert some data that would violate the constraint. FK就在那里,如果我尝试插入一些违反约束的数据,它确实有效。

Anyone know why this would be happening? 任何人都知道为什么会发生这种情况?

This sounds like a tool issue (SSMS), not an engine issue 这听起来像工具问题(SSMS),而不是引擎问题

Thoughts: 思考:

  • close/reopen SSMS (caching?) 关闭/重新打开SSMS(缓存?)
  • patched to same version as server install? 修补到与服务器安装相同的版本?
  • different schema etc? 不同的架构等?

Edit, after comment and it's SSMS caching: 在评论之后编辑它的SSMS缓存:

You can also right-click on the table node and refresh so SSMS updates the cache. 您还可以右键单击表节点并刷新,以便SSMS更新缓存。 This problem goes back to SQL Enterprise Manager and SQL 2000. No known fix after 10 years... 这个问题可以追溯到SQL企业管理器和SQL 2000. 10年后没有已知的修复...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM