Visual Studio 2012中的数据库项目脚本生成 [英] Script generation in Visual Studio 2012 for a Database Project

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

问题描述



我在VS2012中为数据库项目工作,我正在为此生成部署脚本。

在SQL中执行脚本时生成脚本后服务器然后显示以下错误:



ALTER TABLE [dbo]。[ARC] DROP CONSTRAINT [DF__ARC__created_dt__2BC97F7C];

Msg 4902,等级16,状态1,行1

找不到对象dbo.ARC,因为它不存在或者您没有权限。



当我使用下面的代码它工作正常:

如果EXISTS(SELECT * FROM sysobjects WHERE name = [DF__ARC__created_dt__2BC97F7C];)

BEGIN

ALTER TABLE [dbo]。[ARC] DROP CONSTRAINT [DF__ARC__created_dt__2BC97F7C];

END;



我想生成脚本自动使用IF EXISTS选项。

是否可以选择自动生成带有上述选项的这些脚本。

请同时建议。

解决方案

检查这个



IF NOT EXISTS(SELECT'hisPost')CREATE POST thisPost AS [ ^

Hi,
I m working in VS2012 for a Database project and i am generating deployment scripts for the same.
After generating scripts when i m executing those scripts in SQL Server then it is showing Below error :

ALTER TABLE [dbo].[ARC] DROP CONSTRAINT [DF__ARC__created_dt__2BC97F7C];
Msg 4902, Level 16, State 1, Line 1
Cannot find the object "dbo.ARC" because it does not exist or you do not have permissions.

And when i m using below code it is working fine:
IF EXISTS (SELECT * FROM sysobjects WHERE name =[DF__ARC__created_dt__2BC97F7C];)
BEGIN
ALTER TABLE [dbo].[ARC] DROP CONSTRAINT [DF__ARC__created_dt__2BC97F7C];
END;

I want to generate scripts with "IF EXISTS" option automatically.
Is there any option to generate these scripts with above option automatically.
Please Suggest on the same.

解决方案

Check this

IF NOT EXISTS ( SELECT ‘thisPost’ ) CREATE POST thisPost AS[^]


这篇关于Visual Studio 2012中的数据库项目脚本生成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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