gpt4 book ai didi

visual-studio-2013 - Visual Studio 2013 数据库项目放置列

转载 作者:行者123 更新时间:2023-12-03 07:47:03 30 4
gpt4 key购买 nike

当数据表中有数据行时,有谁知道从数据库中删除现有列的最佳方法。

我尝试过的似乎不起作用。我在数据库项目中包含了一个预部署脚本

GO
if exists(select * from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME = 'Mercury.dbo.Discounts' and COLUMN_NAME = 'ColumnToRemove')
BEGIN
ALTER TABLE Database.dbo.Table1 Drop Column ColumnToRemove
END
GO

然后,在首先创建表的脚本中,我从创建表脚本中删除了相关列

当 dacpac 执行完成后,我得到以下信息

Initializing deployment (Start)
*** The column [dbo].[Table1].[ColumnToRemove] is being dropped, data loss could occur.
Initializing deployment (Complete)
Analyzing deployment plan (Start)
Analyzing deployment plan (Complete)
Updating database (Start)
An error occurred while the batch was being executed.
Updating database (Failed)
*** Could not deploy package.
Warning SQL72015: The column [dbo].[Table1].[ColumnToRemove] is being dropped, data loss could occur.
Error SQL72014: .Net SqlClient Data Provider: Msg 50000, Level 16, State 127, Line 6 Rows were detected. The schema update is terminating because data loss might occur.
Error SQL72045: Script execution error. The executed script:
IF EXISTS (SELECT TOP 1 1
FROM [dbo].[Table1])
RAISERROR (N'Rows were detected. The schema update is terminating because data loss might occur.', 16, 127)
WITH NOWAIT;

最佳答案

我知道这是一个旧线程,但是当我面临同样的问题时我遇到了这个线程..有人可能仍然受益..

这是对我有用的:

当您右键单击 VS 中的数据库项目时,您将看到“发布数据库”对话框。您设置目​​标服务器连接并选择正确的数据库。

然后单击“高级...”按钮打开“高级发布设置”。

1) Uncheck - 'Block incremental deployment if data loss might occur' checkbox.
2) Check - 'DROP objects in target but not in project'

单击确定按钮。然后单击生成脚本按钮以生成发布脚本。

如果您想频繁生成脚本,可以将这些设置保存到配置文件中。

关于visual-studio-2013 - Visual Studio 2013 数据库项目放置列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25653142/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com