用于添加列的简单按钮
我右键单击 ssms 2008 中的表,然后选择将表脚本脚本为/删除并创建表到新窗口,我尝试运行该脚本,但收到错误:
Could not drop table because it is referenced by a foreign key constraint
那么删除并创建生成脚本的意义何在?
谢谢,
杆。
I right click on my table in ssms 2008 and select Script Table as / Drop and Create Table to new window and I try to run the script but get an error:
Could not drop table because it is referenced by a foreign key constraint
What was the point of the Drop and Create generate script then?
Thanks,
rod.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
删除和创建生成脚本的要点正是您所想的 - 它为您提供了一种简单的方法来编写删除和重新创建表的脚本。但是,如果其他表通过外键约束引用该表,则您无法删除该表,这就是您收到错误消息的原因。
如果您只是尝试添加列,则可以右键单击企业管理器中的表,然后单击“修改”,然后在设计视图中添加该列。不需要仅仅为了添加列而删除表。 (如果表中有数据,这尤其是一种糟糕的方法。)
The point of the Drop and Create generate script is exactly what you'd think - it gives you an easy way to script out dropping and re-creating a table. However you can't drop a table if other tables reference it via foreign key constraints, which is why you're getting the error message.
If you're just trying to add a column, you can right-click the table in Enterprise Manager and click Modify and just add the column in design view. There's no need to drop the table just to add a column. (And it's especially an awful approach if the table has data in it.)
向现有表添加列的最简单方法是什么?自己编写 ALTER TABLE 语句,而不是依赖 SQL Server Management Studio 为您执行此操作:
The easiest way to add a column to an existing table? Write the ALTER TABLE statement yourself instead of relying on SQL Server Management Studio to do it for you: