A further 7 columns have been added to a table, but you must first check if this column is in the database, otherwise you should not run the column creation script.
Is it possible, in a single condition, to check whether the columns have already been created in the database? Here is the code:
IF NOT EXISTS (SELECT *
FROM SYSCOLUMNS C
INNER JOIN SYSOBJECTS T ON C.id = T.id
WHERE C.name = ('IdUserPreparo')
AND T.name = 'ComandaItem'
AND ('dtSolicitacao')
AND T.name = 'ComandaItem'
AND ('dtPreparo')
AND T.name = 'ComandaItem'
AND ('idUserCancel')
AND T.name = 'ComandaItem'
AND ('dtCancel')
AND T.name = 'ComandaItem'
AND ('IsCancelado')
AND T.name = 'ComandaItem'
AND ('obsCancel')
AND T.name = 'ComandaItem')
BEGIN
This is the script for creating the columns in the database:
ALTER TABLE dbo.ComandaItem ADD
IdUserPreparo int NULL,
dtSolicitacao datetime NULL,
dtPreparo datetime NULL,
idUserCancel int NULL,
dtCancel datetime NULL,
IsCancelado bit NULL,
obsCancel varbinary(5000) NULL
GO
ALTER TABLE dbo.ComandaItem ADD CONSTRAINT
FK_ComandaItem_PessoaPreparo FOREIGN KEY
(
IdUserPreparo
) REFERENCES dbo.Pessoa
(
IDCadastro
) ON UPDATE NO ACTION
ON DELETE NO ACTION
GO
ALTER TABLE dbo.ComandaItem ADD CONSTRAINT
FK_ComandaItem_PessoaCancel FOREIGN KEY
(
idUserCancel
) REFERENCES dbo.Pessoa
(
IDCadastro
) ON UPDATE NO ACTION
ON DELETE NO ACTION
GO
ALTER TABLE dbo.ComandaItem SET (LOCK_ESCALATION = TABLE)
GO
COMMIT