删除列时Visual Studio数据库项目问题 [英] Visual Studio Database Project problem with deleting a column

查看:115
本文介绍了删除列时Visual Studio数据库项目问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 

 

您好,

我还有其他问题使用数据库项目。

I have another problem with database project.

我从表中删除了一列AreaUsageTypeID,但希望在现有行中保存此列的值以填充其他表。

I remove a column AreaUsageTypeID from a table but want to save the values for this column in the existing rows to fill other tables.

 

所以我尝试创建一个临时表并将整个表数据复制到临时表中。当然我在另一个脚本中创建了临时表。

So I try to create a temporary Table and copy the whole table data into the temporary table. Of course I created the temporary table in another script.

我使用insert语句执行此操作:

I do this with an insert statement:

IF EXISTS (SELECT TOP 1 1
           FROM  [fm].[tAreas])
BEGIN
       INSERT INTO [dbo].[tmp_tAreasForNewTable]
           ([Id]
           ,[RevisionNumber]
           ...
   ,[AreaUsageTypeID])
        SELECT  [Id]
           ,[RevisionNumber]
            ...
   ,[AreaUsageTypeID]
         FROM [fm].[tAreas]

END



项目重建正确但在部署时他告诉我:


The project rebuilds correct but when deploying he tells me:

第44行无效的列名'AreaUsageTypeID'

Line 44 Invalid column name 'AreaUsageTypeID'

 

当然,在更新架构后,此列已不复存在。

Of course after the schema is updated then this column is not there any more.

但我想要在前节中运行此脚本。所以我认为我应该可以使用目标数据库中的所有现有列。

But I want to run this script in the pre section. So I think I should be able to use all existing columns in the target database.

但这是不可能的。

 

该问题的解决方案是什么?

What is the solution for that problem?

 

我使用Visual Studio 2010 ServicePack 1

I use Visual Studio 2010 ServicePack 1

提前致谢。

Jü rgen

Jürgen

推荐答案

嗨Jurgen,

Hi Jurgen,

 

为此,您将使用预部署脚本。 项目有一个前后部署脚本,您可以将自定义T-SQL添加到其他脚本或包含其他脚本。 在您的方案中,我会检查以确定列是否存在,如果存在,请将
数据移至临时表。 然后,您可以使用后部署脚本来处理您认为合适的数据。

For this you would use the pre-deployment script.  Projects have a pre and post deployment script which you can add custom T-SQL to or include other scripts.  In your scenario I would put a check to determine if the column exists and if so, move the data to temp table.  You then can use the post deployment script to process the data as you see fit.

谢谢,


这篇关于删除列时Visual Studio数据库项目问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆