用于添加列的简单按钮

发布于 2024-09-28 23:24:11 字数 214 浏览 7 评论 0原文

我右键单击 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

陌上芳菲 2024-10-05 23:24:12

删除和创建生成脚本的要点正是您所想的 - 它为您提供了一种简单的方法来编写删除和重新创建表的脚本。但是,如果其他表通过外键约束引用该表,则您无法删除该表,这就是您收到错误消息的原因。

如果您只是尝试添加列,则可以右键单击企业管理器中的表,然后单击“修改”,然后在设计视图中添加该列。不需要仅仅为了添加列而删除表。 (如果表中有数据,这尤其是一种糟糕的方法。)

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.)

各自安好 2024-10-05 23:24:12

向现有表添加列的最简单方法是什么?自己编写 ALTER TABLE 语句,而不是依赖 SQL Server Management Studio 为您执行此操作:

ALTER TABLE YourTableName
ADD ColumnName int

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:

ALTER TABLE YourTableName
ADD ColumnName int
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文