VSTS for DB PRO: Schema Update per aggiunta campo
Dopo il post di ieri sul rename di un campo, ecco come si comporta VSTS for DBPro nel caso di aggiunta di un campo ad una tabella. In questi giorni, sto testando VSTS for DB Pro in vari scenari per capire come si muove dietro le quinte.
Nel caso specifico ho aggiunto il campo DescrizioneAggiuntiva (usando un UDT esistente) alla tabella tabSalami (chi ha partecipato al VSTS Day a settembre si ricorderĂ questa tabella interessantissima :-)).
In questo caso viene generato una ALTER TABLE e quindi non soffriamo il DROP&RECREATE.
Il commento iniziale dice tutto: applica questo script al DB vero per renderlo identico a quanto presente nel progetto disconnesso.
/*
This script was created by Visual Studio on 02/02/2007 at 12.00.
Run this script on peppe.SalamiManagement.dbo to make it the same as IntroVSTSDBPRO02.
Please back up your target database before running this script.
*/
GO
SET
NUMERIC_ROUNDABORT
OFF
GO
SET
ANSI_PADDING
ON
GO
SET
ANSI_WARNINGS
ON
GO
SET
CONCAT_NULL_YIELDS_NULL
ON
GO
SET ARITHABORT ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET
ANSI_NULLS
ON
GO
IF EXISTS
(
SELECT *
FROM tempdb..sysobjects
WHERE id=
OBJECT_ID(
'tempdb..#tmpErrors'))
DROP TABLE #tmpErrors
GO
CREATE TABLE
#tmpErrors (Error
int)
GO
SET
XACT_ABORT
ON
GO
SET TRANSACTION ISOLATION LEVEL READ COMMITTED
GO
BEGIN TRANSACTION
GO
PRINT
N
'Altering [dbo].[tabSalami]'
GO
ALTER TABLE
[dbo].[tabSalami]
ADD
[SalameDescrizioneAggiuntiva] [dbo].[udtDescrizione] NULL
GO
IF
@@ERROR<>0
AND @@TRANCOUNT>0
ROLLBACK TRANSACTION
GO
IF
@@TRANCOUNT=0
BEGIN INSERT INTO #tmpErrors (Error)
SELECT 1
BEGIN TRANSACTION END
GO
IF EXISTS
(
SELECT *
FROM #tmpErrors)
ROLLBACK TRANSACTION
GO
IF
@@TRANCOUNT>0
BEGIN
PRINT
'The database update succeeded'
COMMIT TRANSACTION
END
ELSE PRINT
'The database update failed'
GO
DROP TABLE
#tmpErrors
GO