Hi @enchev,
i use visual studio "sql server data tools" projekt (SSDT)
SSDT
I have tested that...
i inserted a column in DispoArtikelPreisbestandteil Table in the ssdt project
,[VKEinheitId] INT NULL
,[GueltigVon] DATE NULL
,[GueltigBis] DATE NULL
,[TestDatum] DATE NULL <-- NEW COLUMN
,[Bemerkung] NVARCHAR(100) NULL
,[TransportMitEigenenFahrzeugen] BIT DEFAULT(0) NOT NULL
The project compares the "project model" with a given database.
the differences are shown and a update database script is generated.
thats all in an SSDT project. very easy to use for database definition and organisation.
this is the generated script when i insert the new column "TestDatum":
/*
Bereitstellungsskript für trentdb_entw
Dieser Code wurde von einem Tool generiert.
Änderungen an dieser Datei führen möglicherweise zu falschem Verhalten und gehen verloren, falls
der Code neu generiert wird.
*/
GO
SET ANSI_NULLS, ANSI_PADDING, ANSI_WARNINGS, ARITHABORT, CONCAT_NULL_YIELDS_NULL, QUOTED_IDENTIFIER ON;
SET NUMERIC_ROUNDABORT OFF;
GO
:setvar DatabaseName "xxx"
:setvar DefaultFilePrefix "xxx"
:setvar DefaultDataPath "xxx"
:setvar DefaultLogPath "xxx"
GO
:on error exit
GO
/*
Überprüfen Sie den SQLCMD-Modus, und deaktivieren Sie die Skriptausführung, wenn der SQLCMD-Modus nicht unterstützt wird.
Um das Skript nach dem Aktivieren des SQLCMD-Modus erneut zu aktivieren, führen Sie folgenden Befehl aus:
SET NOEXEC OFF;
*/
:setvar __IsSqlCmdEnabled "True"
GO
IF N'$(__IsSqlCmdEnabled)' NOT LIKE N'True'
BEGIN
PRINT N'Der SQLCMD-Modus muss aktiviert sein, damit dieses Skript erfolgreich ausgeführt werden kann.';
SET NOEXEC ON;
END
GO
USE [$(DatabaseName)];
GO
PRINT N'DEFAULT-Einschränkung "unbenannte Einschränkungen auf [dbo].[DispoArtikelPreisBestandteil]" wird gelöscht...';
GO
ALTER TABLE [dbo].[DispoArtikelPreisBestandteil] DROP CONSTRAINT [DF__tmp_ms_xx__Trans__5BAE681F];
GO
PRINT N'Fremdschlüssel "[dbo].[FKPreisBestandteilUploadInfoDispoArtikelPreisBestandteil]" wird gelöscht...';
GO
ALTER TABLE [dbo].[DispoArtikelPreisBestandteilUploadInfo] DROP CONSTRAINT [FKPreisBestandteilUploadInfoDispoArtikelPreisBestandteil];
GO
PRINT N'Fremdschlüssel "[dbo].[FKDispoArtikelPreisBestandteil_DispoOutlookArtikel]" wird gelöscht...';
GO
ALTER TABLE [dbo].[DispoArtikelPreisBestandteil] DROP CONSTRAINT [FKDispoArtikelPreisBestandteil_DispoOutlookArtikel];
GO
PRINT N'Fremdschlüssel "[dbo].[FKDispoArtikelPreisBestandteil_PreisBestandteilTyp]" wird gelöscht...';
GO
ALTER TABLE [dbo].[DispoArtikelPreisBestandteil] DROP CONSTRAINT [FKDispoArtikelPreisBestandteil_PreisBestandteilTyp];
GO
PRINT N'Fremdschlüssel "[dbo].[FKPreisBestandteil_EkEinheit]" wird gelöscht...';
GO
ALTER TABLE [dbo].[DispoArtikelPreisBestandteil] DROP CONSTRAINT [FKPreisBestandteil_EkEinheit];
GO
PRINT N'Fremdschlüssel "[dbo].[FKPreisBestandteil_Entsorgungsnachweis]" wird gelöscht...';
GO
ALTER TABLE [dbo].[DispoArtikelPreisBestandteil] DROP CONSTRAINT [FKPreisBestandteil_Entsorgungsnachweis];
GO
PRINT N'Fremdschlüssel "[dbo].[FKPreisBestandteil_VkEinheit]" wird gelöscht...';
GO
ALTER TABLE [dbo].[DispoArtikelPreisBestandteil] DROP CONSTRAINT [FKPreisBestandteil_VkEinheit];
GO
PRINT N'Fremdschlüssel "[dbo].[FKPreisBestandteil_ZuschlagBezeichnung]" wird gelöscht...';
GO
ALTER TABLE [dbo].[DispoArtikelPreisBestandteil] DROP CONSTRAINT [FKPreisBestandteil_ZuschlagBezeichnung];
GO
PRINT N'Fremdschlüssel "[dbo].[FKPreisBestandteil_Artikel]" wird gelöscht...';
GO
ALTER TABLE [dbo].[DispoArtikelPreisBestandteil] DROP CONSTRAINT [FKPreisBestandteil_Artikel];
GO
PRINT N'Fremdschlüssel "[dbo].[FKPreisBestandteil_Befoerdererpartner]" wird gelöscht...';
GO
ALTER TABLE [dbo].[DispoArtikelPreisBestandteil] DROP CONSTRAINT [FKPreisBestandteil_Befoerdererpartner];
GO
PRINT N'Das erneute Erstellen der Tabelle "[dbo].[DispoArtikelPreisBestandteil]" wird gestartet....';
GO
BEGIN TRANSACTION;
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;
SET XACT_ABORT ON;
CREATE TABLE [dbo].[tmp_ms_xx_DispoArtikelPreisBestandteil] (
[DispoArtikelPreisBestandteilId] INT IDENTITY (1, 1) NOT NULL,
[PreisBestandteilTypId] INT NOT NULL,
[DispoOutlookArtikelId] INT NOT NULL,
[EKPreis] DECIMAL (11, 2) NULL,
[EKEinheitId] INT NULL,
[VKPreis] DECIMAL (11, 2) NULL,
[VKEinheitId] INT NULL,
[GueltigVon] DATE NULL,
[GueltigBis] DATE NULL,
[TestDatum] DATE NULL,
[Bemerkung] NVARCHAR (100) NULL,
[TransportMitEigenenFahrzeugen] BIT DEFAULT (0) NOT NULL,
[ArtikelId] INT NULL,
[BefoerdererpartnerId] INT NULL,
[ZuschlagBezeichnungId] INT NULL,
[EntsorgungsnachweisId] INT NULL,
PRIMARY KEY CLUSTERED ([DispoArtikelPreisBestandteilId] ASC)
);
IF EXISTS (SELECT TOP 1 1
FROM [dbo].[DispoArtikelPreisBestandteil])
BEGIN
SET IDENTITY_INSERT [dbo].[tmp_ms_xx_DispoArtikelPreisBestandteil] ON;
INSERT INTO [dbo].[tmp_ms_xx_DispoArtikelPreisBestandteil] ([DispoArtikelPreisBestandteilId], [PreisBestandteilTypId], [DispoOutlookArtikelId], [EKPreis], [EKEinheitId], [VKPreis], [VKEinheitId], [GueltigVon], [GueltigBis], [Bemerkung], [TransportMitEigenenFahrzeugen], [ArtikelId], [BefoerdererpartnerId], [ZuschlagBezeichnungId], [EntsorgungsnachweisId])
SELECT [DispoArtikelPreisBestandteilId],
[PreisBestandteilTypId],
[DispoOutlookArtikelId],
[EKPreis],
[EKEinheitId],
[VKPreis],
[VKEinheitId],
[GueltigVon],
[GueltigBis],
[Bemerkung],
[TransportMitEigenenFahrzeugen],
[ArtikelId],
[BefoerdererpartnerId],
[ZuschlagBezeichnungId],
[EntsorgungsnachweisId]
FROM [dbo].[DispoArtikelPreisBestandteil]
ORDER BY [DispoArtikelPreisBestandteilId] ASC;
SET IDENTITY_INSERT [dbo].[tmp_ms_xx_DispoArtikelPreisBestandteil] OFF;
END
DROP TABLE [dbo].[DispoArtikelPreisBestandteil];
EXECUTE sp_rename N'[dbo].[tmp_ms_xx_DispoArtikelPreisBestandteil]', N'DispoArtikelPreisBestandteil';
COMMIT TRANSACTION;
SET TRANSACTION ISOLATION LEVEL READ COMMITTED;
GO
PRINT N'Fremdschlüssel "[dbo].[FKPreisBestandteilUploadInfoDispoArtikelPreisBestandteil]" wird erstellt...';
GO
ALTER TABLE [dbo].[DispoArtikelPreisBestandteilUploadInfo] WITH NOCHECK
ADD CONSTRAINT [FKPreisBestandteilUploadInfoDispoArtikelPreisBestandteil] FOREIGN KEY ([DispoArtikelPreisBestandteilId]) REFERENCES [dbo].[DispoArtikelPreisBestandteil] ([DispoArtikelPreisBestandteilId]) ON DELETE CASCADE;
GO
PRINT N'Fremdschlüssel "[dbo].[FKDispoArtikelPreisBestandteil_DispoOutlookArtikel]" wird erstellt...';
GO
ALTER TABLE [dbo].[DispoArtikelPreisBestandteil] WITH NOCHECK
ADD CONSTRAINT [FKDispoArtikelPreisBestandteil_DispoOutlookArtikel] FOREIGN KEY ([DispoOutlookArtikelId]) REFERENCES [dbo].[DispoOutlookArtikel] ([DispoOutlookArtikelId]) ON DELETE CASCADE;
GO
PRINT N'Fremdschlüssel "[dbo].[FKDispoArtikelPreisBestandteil_PreisBestandteilTyp]" wird erstellt...';
GO
ALTER TABLE [dbo].[DispoArtikelPreisBestandteil] WITH NOCHECK
ADD CONSTRAINT [FKDispoArtikelPreisBestandteil_PreisBestandteilTyp] FOREIGN KEY ([PreisBestandteilTypId]) REFERENCES [dbo].[PreisBestandteilTyp] ([PreisBestandteilTypId]);
GO
PRINT N'Fremdschlüssel "[dbo].[FKPreisBestandteil_EkEinheit]" wird erstellt...';
GO
ALTER TABLE [dbo].[DispoArtikelPreisBestandteil] WITH NOCHECK
ADD CONSTRAINT [FKPreisBestandteil_EkEinheit] FOREIGN KEY ([EKEinheitId]) REFERENCES [dbo].[Einheit] ([EinheitId]);
GO
PRINT N'Fremdschlüssel "[dbo].[FKPreisBestandteil_Entsorgungsnachweis]" wird erstellt...';
GO
ALTER TABLE [dbo].[DispoArtikelPreisBestandteil] WITH NOCHECK
ADD CONSTRAINT [FKPreisBestandteil_Entsorgungsnachweis] FOREIGN KEY ([EntsorgungsnachweisId]) REFERENCES [dbo].[Entsorgungsnachweis] ([EntsorgungsnachweisId]);
GO
PRINT N'Fremdschlüssel "[dbo].[FKPreisBestandteil_VkEinheit]" wird erstellt...';
GO
ALTER TABLE [dbo].[DispoArtikelPreisBestandteil] WITH NOCHECK
ADD CONSTRAINT [FKPreisBestandteil_VkEinheit] FOREIGN KEY ([VKEinheitId]) REFERENCES [dbo].[Einheit] ([EinheitId]);
GO
PRINT N'Fremdschlüssel "[dbo].[FKPreisBestandteil_ZuschlagBezeichnung]" wird erstellt...';
GO
ALTER TABLE [dbo].[DispoArtikelPreisBestandteil] WITH NOCHECK
ADD CONSTRAINT [FKPreisBestandteil_ZuschlagBezeichnung] FOREIGN KEY ([ZuschlagBezeichnungId]) REFERENCES [dbo].[ZuschlagBezeichnung] ([ZuschlagBezeichnungId]);
GO
PRINT N'Fremdschlüssel "[dbo].[FKPreisBestandteil_Artikel]" wird erstellt...';
GO
ALTER TABLE [dbo].[DispoArtikelPreisBestandteil] WITH NOCHECK
ADD CONSTRAINT [FKPreisBestandteil_Artikel] FOREIGN KEY ([ArtikelId]) REFERENCES [dbo].[Artikel] ([ArtikelId]);
GO
PRINT N'Fremdschlüssel "[dbo].[FKPreisBestandteil_Befoerdererpartner]" wird erstellt...';
GO
ALTER TABLE [dbo].[DispoArtikelPreisBestandteil] WITH NOCHECK
ADD CONSTRAINT [FKPreisBestandteil_Befoerdererpartner] FOREIGN KEY ([BefoerdererpartnerId]) REFERENCES [dbo].[Partner] ([PartnerId]);
GO
PRINT N'Vorhandene Daten werden auf neu erstellte Einschränkungen hin überprüft.';
GO
USE [$(DatabaseName)];
GO
ALTER TABLE [dbo].[DispoArtikelPreisBestandteilUploadInfo] WITH CHECK CHECK CONSTRAINT [FKPreisBestandteilUploadInfoDispoArtikelPreisBestandteil];
ALTER TABLE [dbo].[DispoArtikelPreisBestandteil] WITH CHECK CHECK CONSTRAINT [FKDispoArtikelPreisBestandteil_DispoOutlookArtikel];
ALTER TABLE [dbo].[DispoArtikelPreisBestandteil] WITH CHECK CHECK CONSTRAINT [FKDispoArtikelPreisBestandteil_PreisBestandteilTyp];
ALTER TABLE [dbo].[DispoArtikelPreisBestandteil] WITH CHECK CHECK CONSTRAINT [FKPreisBestandteil_EkEinheit];
ALTER TABLE [dbo].[DispoArtikelPreisBestandteil] WITH CHECK CHECK CONSTRAINT [FKPreisBestandteil_Entsorgungsnachweis];
ALTER TABLE [dbo].[DispoArtikelPreisBestandteil] WITH CHECK CHECK CONSTRAINT [FKPreisBestandteil_VkEinheit];
ALTER TABLE [dbo].[DispoArtikelPreisBestandteil] WITH CHECK CHECK CONSTRAINT [FKPreisBestandteil_ZuschlagBezeichnung];
ALTER TABLE [dbo].[DispoArtikelPreisBestandteil] WITH CHECK CHECK CONSTRAINT [FKPreisBestandteil_Artikel];
ALTER TABLE [dbo].[DispoArtikelPreisBestandteil] WITH CHECK CHECK CONSTRAINT [FKPreisBestandteil_Befoerdererpartner];
GO
PRINT N'Update abgeschlossen.';
GO
As you see the update script generates the table new and transfers the data from the "old" table to the "new" table and then deletes the old table.
Thomas