SQL Server数据库项目通过部署后脚本将列添加到表中

时间:2014-07-10 03:58:47

标签: c# sql .net sql-server vb.net

在我们的一个项目中,我们使用SQL Server数据库项目来维护数据库。在这里,我有一个方案是通过脚本将新列添加到数据库表而不是直接添加到项目中的表。所以我创建了一个alter脚本来添加新列并将其包含在post部署脚本中(在添加之前检查列存在)。它适用于首次发布而没有错误。在我发布项目后,它给了我以下错误。我理解这里的问题是因为项目中的表不包含列(因为它是通过alter script添加的)所以当它被发布时,它会发现需要删除列。

所以我们不能通过Sql server数据库项目中的脚本文件直接向表中添加新列吗?

ERROR: *** Could not deploy package.
2014-07-09 11:15:33 INFO   [Deploy Script]   ERROR: Warning SQL72015: The column [dbo].[aps_client_po].[aps_cost_centre] is being dropped, data loss could occur.
2014-07-09 11:15:33 INFO   [Deploy Script]   ERROR: Warning SQL72015: The column [dbo].[RefPOStaging].[cost_centre] is being dropped, data loss could occur.
2014-07-09 11:15:33 INFO   [Deploy Script]   ERROR: 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.
2014-07-09 11:15:33 INFO   [Deploy Script]   ERROR: Error SQL72045: Script execution error.  The executed script:
2014-07-09 11:15:33 INFO   [Deploy Script]   ERROR: IF EXISTS (SELECT TOP 1 1
2014-07-09 11:15:33 INFO   [Deploy Script]   ERROR:            FROM   [dbo].[aps_client_po])
2014-07-09 11:15:33 INFO   [Deploy Script]   ERROR:     RAISERROR (N'Rows were detected. The schema update is terminating because data loss might occur.', 16, 127)
2014-07-09 11:15:33 INFO   [Deploy Script]   ERROR:         WITH NOWAIT;

0 个答案:

没有答案