Deploy not working Correctly1. Hello, I used the Import Database and Objects, I imported the SOURCE database, I meant the newest one with new tables, fields, etc.<br/> <br/> 2. I created a database comparisson on the schema comparisson folder.<br/> <br/> On the source I choosed Database project and on the target the old database that needs to be updated with new fields, etc.<br/> <br/> Then I clicked Deploy and take a look at the result.<br/> <br/> Questions:<br/> <br/> 1. Why it generated a CREATE TABLE, if that table already exists, I need that it Generates an Alter table with an ADD COLUMN as the schema comparisson did<br/> <br/> <br/> <br/> <pre lang=x-sql>/* Deployment script for EPM.Aguas.ROP.DBComparisson */ GO SET ANSI_NULLS, ANSI_PADDING, ANSI_WARNINGS, ARITHABORT, CONCAT_NULL_YIELDS_NULL, QUOTED_IDENTIFIER ON; SET NUMERIC_ROUNDABORT OFF; GO :setvar DatabaseName &quot;EPM.Aguas.ROP.DBComparisson&quot; :setvar DefaultDataPath &quot;&quot; GO USE [master] GO :on error exit GO IF (DB_ID(N'$(DatabaseName)') IS NOT NULL AND DATABASEPROPERTYEX(N'$(DatabaseName)','Status') &lt;&gt; N'ONLINE') BEGIN RAISERROR(N'The state of the target database, %s, is not set to ONLINE. To deploy to this database, its state must be set to ONLINE.', 16, 127,N'$(DatabaseName)') WITH NOWAIT RETURN END GO IF (DB_ID(N'$(DatabaseName)') IS NOT NULL) BEGIN ALTER DATABASE [$(DatabaseName)] SET SINGLE_USER WITH ROLLBACK IMMEDIATE; DROP DATABASE [$(DatabaseName)]; END GO PRINT N'Creating $(DatabaseName)...' GO CREATE DATABASE [$(DatabaseName)] ON PRIMARY(NAME = [DB_COMPARENUEVA], FILENAME = '$(DefaultDataPath)$(DatabaseName).mdf', MAXSIZE = UNLIMITED, FILEGROWTH = 1024 KB) LOG ON (NAME = [DB_COMPARENUEVA_log], FILENAME = '$(DefaultDataPath)$(DatabaseName)_log.ldf', MAXSIZE = 2097152 MB, FILEGROWTH = 10 %) COLLATE SQL_Latin1_General_CP1_CI_AS GO EXECUTE sp_dbcmptlevel [$(DatabaseName)], 90; GO IF EXISTS (SELECT 1 FROM [master].[dbo].[sysdatabases] WHERE [name] = N'$(DatabaseName)') BEGIN ALTER DATABASE [$(DatabaseName)] SET ANSI_NULLS ON, ANSI_PADDING ON, ANSI_WARNINGS ON, ARITHABORT ON, CONCAT_NULL_YIELDS_NULL ON, NUMERIC_ROUNDABORT OFF, QUOTED_IDENTIFIER ON, ANSI_NULL_DEFAULT ON, CURSOR_DEFAULT LOCAL, RECOVERY FULL, CURSOR_CLOSE_ON_COMMIT OFF, AUTO_CREATE_STATISTICS ON, AUTO_SHRINK OFF, AUTO_UPDATE_STATISTICS ON, RECURSIVE_TRIGGERS OFF WITH ROLLBACK IMMEDIATE; ALTER DATABASE [$(DatabaseName)] SET AUTO_CLOSE OFF WITH ROLLBACK IMMEDIATE; END GO IF EXISTS (SELECT 1 FROM [master].[dbo].[sysdatabases] WHERE [name] = N'$(DatabaseName)') BEGIN ALTER DATABASE [$(DatabaseName)] SET ALLOW_SNAPSHOT_ISOLATION OFF; END GO IF EXISTS (SELECT 1 FROM [master].[dbo].[sysdatabases] WHERE [name] = N'$(DatabaseName)') BEGIN ALTER DATABASE [$(DatabaseName)] SET READ_COMMITTED_SNAPSHOT OFF; END GO IF EXISTS (SELECT 1 FROM [master].[dbo].[sysdatabases] WHERE [name] = N'$(DatabaseName)') BEGIN ALTER DATABASE [$(DatabaseName)] SET AUTO_UPDATE_STATISTICS_ASYNC OFF, PAGE_VERIFY NONE, DATE_CORRELATION_OPTIMIZATION OFF, DISABLE_BROKER, PARAMETERIZATION SIMPLE WITH ROLLBACK IMMEDIATE; END GO IF IS_SRVROLEMEMBER(N'sysadmin') = 1 BEGIN IF EXISTS (SELECT 1 FROM [master].[dbo].[sysdatabases] WHERE [name] = N'$(DatabaseName)') BEGIN EXECUTE sp_executesql N'ALTER DATABASE [$(DatabaseName)] SET TRUSTWORTHY OFF, DB_CHAINING OFF WITH ROLLBACK IMMEDIATE'; END END ELSE BEGIN PRINT N'The database settings for DB_CHAINING or TRUSTWORTHY cannot be modified. You must be a SysAdmin to apply these settings.'; END GO USE [$(DatabaseName)] GO IF fulltextserviceproperty(N'IsFulltextInstalled') = 1 EXECUTE sp_fulltext_database 'enable'; GO GO /* Pre-Deployment Script Template -------------------------------------------------------------------------------------- This file contains SQL statements that will be executed before the build script. Use SQLCMD syntax to include a file in the pre-deployment script. Example: :r .\myfile.sql Use SQLCMD syntax to reference a variable in the pre-deployment script. Example: :setvar TableName MyTable SELECT * FROM [$(TableName)] -------------------------------------------------------------------------------------- */ GO GO PRINT N'Creating dbo.Tabla1...'; GO CREATE TABLE [dbo].[Tabla1] ( [idCampo1] INT NOT NULL, [Campo1] NCHAR (10) NOT NULL, [Campo3] NCHAR (10) NULL ); GO PRINT N'Creating dbo.PK_Tabla1...'; GO ALTER TABLE [dbo].[Tabla1] ADD CONSTRAINT [PK_Tabla1] PRIMARY KEY CLUSTERED ([idCampo1] ASC) WITH (ALLOW_PAGE_LOCKS = ON, ALLOW_ROW_LOCKS = ON, PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF, STATISTICS_NORECOMPUTE = OFF); GO PRINT N'Creating AutoCreatedLocal...'; GO CREATE ROUTE [AutoCreatedLocal] AUTHORIZATION [dbo] WITH ADDRESS = N'LOCAL'; GO GO /* Post-Deployment Script Template -------------------------------------------------------------------------------------- This file contains SQL statements that will be appended to the build script. Use SQLCMD syntax to include a file in the post-deployment script. Example: :r .\myfile.sql Use SQLCMD syntax to reference a variable in the post-deployment script. Example: :setvar TableName MyTable SELECT * FROM [$(TableName)] -------------------------------------------------------------------------------------- */ GO GO GO ALTER DATABASE [$(DatabaseName)] SET MULTI_USER WITH ROLLBACK IMMEDIATE; GO </pre> <br/><hr class="sig">MCPD ENTERPRISE APPLICATIONS DEVELOPER http://wantmvp.blogspot.com/© 2009 Microsoft Corporation. All rights reserved.Tue, 30 Jun 2009 13:42:12 Z2de6ae35-7aaa-4e40-b2da-0b73f6b3dd28http://social.msdn.microsoft.com/Forums/en-US/vstsdb/thread/2de6ae35-7aaa-4e40-b2da-0b73f6b3dd28#2de6ae35-7aaa-4e40-b2da-0b73f6b3dd28http://social.msdn.microsoft.com/Forums/en-US/vstsdb/thread/2de6ae35-7aaa-4e40-b2da-0b73f6b3dd28#2de6ae35-7aaa-4e40-b2da-0b73f6b3dd28Luis Esteban Valencia Muñozhttp://social.msdn.microsoft.com/Profile/en-US/?user=Luis%20Esteban%20Valencia%20Mu%u00f1ozDeploy not working Correctly1. Hello, I used the Import Database and Objects, I imported the SOURCE database, I meant the newest one with new tables, fields, etc.<br/> <br/> 2. I created a database comparisson on the schema comparisson folder.<br/> <br/> On the source I choosed Database project and on the target the old database that needs to be updated with new fields, etc.<br/> <br/> Then I clicked Deploy and take a look at the result.<br/> <br/> Questions:<br/> <br/> 1. Why it generated a CREATE TABLE, if that table already exists, I need that it Generates an Alter table with an ADD COLUMN as the schema comparisson did<br/> <br/> <br/> <br/> <pre lang=x-sql>/* Deployment script for EPM.Aguas.ROP.DBComparisson */ GO SET ANSI_NULLS, ANSI_PADDING, ANSI_WARNINGS, ARITHABORT, CONCAT_NULL_YIELDS_NULL, QUOTED_IDENTIFIER ON; SET NUMERIC_ROUNDABORT OFF; GO :setvar DatabaseName &quot;EPM.Aguas.ROP.DBComparisson&quot; :setvar DefaultDataPath &quot;&quot; GO USE [master] GO :on error exit GO IF (DB_ID(N'$(DatabaseName)') IS NOT NULL AND DATABASEPROPERTYEX(N'$(DatabaseName)','Status') &lt;&gt; N'ONLINE') BEGIN RAISERROR(N'The state of the target database, %s, is not set to ONLINE. To deploy to this database, its state must be set to ONLINE.', 16, 127,N'$(DatabaseName)') WITH NOWAIT RETURN END GO IF (DB_ID(N'$(DatabaseName)') IS NOT NULL) BEGIN ALTER DATABASE [$(DatabaseName)] SET SINGLE_USER WITH ROLLBACK IMMEDIATE; DROP DATABASE [$(DatabaseName)]; END GO PRINT N'Creating $(DatabaseName)...' GO CREATE DATABASE [$(DatabaseName)] ON PRIMARY(NAME = [DB_COMPARENUEVA], FILENAME = '$(DefaultDataPath)$(DatabaseName).mdf', MAXSIZE = UNLIMITED, FILEGROWTH = 1024 KB) LOG ON (NAME = [DB_COMPARENUEVA_log], FILENAME = '$(DefaultDataPath)$(DatabaseName)_log.ldf', MAXSIZE = 2097152 MB, FILEGROWTH = 10 %) COLLATE SQL_Latin1_General_CP1_CI_AS GO EXECUTE sp_dbcmptlevel [$(DatabaseName)], 90; GO IF EXISTS (SELECT 1 FROM [master].[dbo].[sysdatabases] WHERE [name] = N'$(DatabaseName)') BEGIN ALTER DATABASE [$(DatabaseName)] SET ANSI_NULLS ON, ANSI_PADDING ON, ANSI_WARNINGS ON, ARITHABORT ON, CONCAT_NULL_YIELDS_NULL ON, NUMERIC_ROUNDABORT OFF, QUOTED_IDENTIFIER ON, ANSI_NULL_DEFAULT ON, CURSOR_DEFAULT LOCAL, RECOVERY FULL, CURSOR_CLOSE_ON_COMMIT OFF, AUTO_CREATE_STATISTICS ON, AUTO_SHRINK OFF, AUTO_UPDATE_STATISTICS ON, RECURSIVE_TRIGGERS OFF WITH ROLLBACK IMMEDIATE; ALTER DATABASE [$(DatabaseName)] SET AUTO_CLOSE OFF WITH ROLLBACK IMMEDIATE; END GO IF EXISTS (SELECT 1 FROM [master].[dbo].[sysdatabases] WHERE [name] = N'$(DatabaseName)') BEGIN ALTER DATABASE [$(DatabaseName)] SET ALLOW_SNAPSHOT_ISOLATION OFF; END GO IF EXISTS (SELECT 1 FROM [master].[dbo].[sysdatabases] WHERE [name] = N'$(DatabaseName)') BEGIN ALTER DATABASE [$(DatabaseName)] SET READ_COMMITTED_SNAPSHOT OFF; END GO IF EXISTS (SELECT 1 FROM [master].[dbo].[sysdatabases] WHERE [name] = N'$(DatabaseName)') BEGIN ALTER DATABASE [$(DatabaseName)] SET AUTO_UPDATE_STATISTICS_ASYNC OFF, PAGE_VERIFY NONE, DATE_CORRELATION_OPTIMIZATION OFF, DISABLE_BROKER, PARAMETERIZATION SIMPLE WITH ROLLBACK IMMEDIATE; END GO IF IS_SRVROLEMEMBER(N'sysadmin') = 1 BEGIN IF EXISTS (SELECT 1 FROM [master].[dbo].[sysdatabases] WHERE [name] = N'$(DatabaseName)') BEGIN EXECUTE sp_executesql N'ALTER DATABASE [$(DatabaseName)] SET TRUSTWORTHY OFF, DB_CHAINING OFF WITH ROLLBACK IMMEDIATE'; END END ELSE BEGIN PRINT N'The database settings for DB_CHAINING or TRUSTWORTHY cannot be modified. You must be a SysAdmin to apply these settings.'; END GO USE [$(DatabaseName)] GO IF fulltextserviceproperty(N'IsFulltextInstalled') = 1 EXECUTE sp_fulltext_database 'enable'; GO GO /* Pre-Deployment Script Template -------------------------------------------------------------------------------------- This file contains SQL statements that will be executed before the build script. Use SQLCMD syntax to include a file in the pre-deployment script. Example: :r .\myfile.sql Use SQLCMD syntax to reference a variable in the pre-deployment script. Example: :setvar TableName MyTable SELECT * FROM [$(TableName)] -------------------------------------------------------------------------------------- */ GO GO PRINT N'Creating dbo.Tabla1...'; GO CREATE TABLE [dbo].[Tabla1] ( [idCampo1] INT NOT NULL, [Campo1] NCHAR (10) NOT NULL, [Campo3] NCHAR (10) NULL ); GO PRINT N'Creating dbo.PK_Tabla1...'; GO ALTER TABLE [dbo].[Tabla1] ADD CONSTRAINT [PK_Tabla1] PRIMARY KEY CLUSTERED ([idCampo1] ASC) WITH (ALLOW_PAGE_LOCKS = ON, ALLOW_ROW_LOCKS = ON, PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF, STATISTICS_NORECOMPUTE = OFF); GO PRINT N'Creating AutoCreatedLocal...'; GO CREATE ROUTE [AutoCreatedLocal] AUTHORIZATION [dbo] WITH ADDRESS = N'LOCAL'; GO GO /* Post-Deployment Script Template -------------------------------------------------------------------------------------- This file contains SQL statements that will be appended to the build script. Use SQLCMD syntax to include a file in the post-deployment script. Example: :r .\myfile.sql Use SQLCMD syntax to reference a variable in the post-deployment script. Example: :setvar TableName MyTable SELECT * FROM [$(TableName)] -------------------------------------------------------------------------------------- */ GO GO GO ALTER DATABASE [$(DatabaseName)] SET MULTI_USER WITH ROLLBACK IMMEDIATE; GO </pre> <br/><hr class="sig">MCPD ENTERPRISE APPLICATIONS DEVELOPER http://wantmvp.blogspot.com/Fri, 26 Jun 2009 14:19:40 Z2009-06-26T14:19:40Zhttp://social.msdn.microsoft.com/Forums/en-US/vstsdb/thread/2de6ae35-7aaa-4e40-b2da-0b73f6b3dd28#39c2d0e4-ab8d-4795-b472-82c022397554http://social.msdn.microsoft.com/Forums/en-US/vstsdb/thread/2de6ae35-7aaa-4e40-b2da-0b73f6b3dd28#39c2d0e4-ab8d-4795-b472-82c022397554Jill McClenahanhttp://social.msdn.microsoft.com/Profile/en-US/?user=Jill%20McClenahanDeploy not working CorrectlyHi Luis,<br/><br/>It seems that you are getting the schema comparison tool and our deployment a bit mixed together.  When you do a schema compare and choose a source and target, it will generate results for you in the preview pane and you click the &quot;Write Updates&quot; in the schema comparison window to apply the changes.  <br/><br/>When trying to do the deploy, you probably do not have a database connection specified in your project properties and you are deploying to a SQL script, thus it treats it as a new database.  Try setting your database connection and deploying to database in your deploy options.  <br/><br/>I think this is the same answer to one of your other posts, so please let us know it both questions are answered.<br/><br/>Thanks,<br/>JillFri, 26 Jun 2009 19:30:42 Z2009-06-26T19:30:42Zhttp://social.msdn.microsoft.com/Forums/en-US/vstsdb/thread/2de6ae35-7aaa-4e40-b2da-0b73f6b3dd28#ed93a474-476f-49ef-acd5-79f84111ee95http://social.msdn.microsoft.com/Forums/en-US/vstsdb/thread/2de6ae35-7aaa-4e40-b2da-0b73f6b3dd28#ed93a474-476f-49ef-acd5-79f84111ee95Brian Buninhttp://social.msdn.microsoft.com/Profile/en-US/?user=Brian%20BuninDeploy not working CorrectlyDo you have the project set to &quot;Always recreate Database&quot;?Fri, 26 Jun 2009 20:10:23 Z2009-06-26T20:10:23Zhttp://social.msdn.microsoft.com/Forums/en-US/vstsdb/thread/2de6ae35-7aaa-4e40-b2da-0b73f6b3dd28#2aa3128f-f065-4761-9d6e-959b8fdef32ehttp://social.msdn.microsoft.com/Forums/en-US/vstsdb/thread/2de6ae35-7aaa-4e40-b2da-0b73f6b3dd28#2aa3128f-f065-4761-9d6e-959b8fdef32eGert Drapershttp://social.msdn.microsoft.com/Profile/en-US/?user=Gert%20DrapersDeploy not working CorrectlyAnd do you have a target connection specified in the Deploy properties, otherwise you always and only get a new deployment script from Deploy.<br/><br/>But the fact that this fragment is in your script<br/><br/> <pre lang=x-sql>IF (DB_ID(N'$(DatabaseName)') IS NOT NULL) BEGIN ALTER DATABASE [$(DatabaseName)] SET SINGLE_USER WITH ROLLBACK IMMEDIATE; DROP DATABASE [$(DatabaseName)]; END </pre> <br/>Implies that Brian is correct that it seems that Always Recreate is turned on.<hr class="sig">GertD @ www.DBProj.com Fri, 26 Jun 2009 22:17:16 Z2009-06-26T22:17:16Zhttp://social.msdn.microsoft.com/Forums/en-US/vstsdb/thread/2de6ae35-7aaa-4e40-b2da-0b73f6b3dd28#0f6c23be-c7e2-4fef-9217-29d26988c242http://social.msdn.microsoft.com/Forums/en-US/vstsdb/thread/2de6ae35-7aaa-4e40-b2da-0b73f6b3dd28#0f6c23be-c7e2-4fef-9217-29d26988c242Luis Esteban Valencia Muñozhttp://social.msdn.microsoft.com/Profile/en-US/?user=Luis%20Esteban%20Valencia%20Mu%u00f1ozDeploy not working Correctly<p>Hi. Alwas recreate was set to False, it wasnt turned on.<br/><br/>But. As you said in the project options there was no target database selected, after I configured this and click on Deploy, the generated script looks fine  because it generated an ALTER TABLE with and ADD COLUMN <br/><br/><br/>ALTER TABLE [dbo].[Tabla1]<br/>    ADD [Campo3] NCHAR (10) NULL;</p> <p><br/>GO</p><hr class="sig">MCPD ENTERPRISE APPLICATIONS DEVELOPER http://wantmvp.blogspot.com/Tue, 30 Jun 2009 13:41:57 Z2009-06-30T13:41:57Z