Skip to content

Instantly share code, notes, and snippets.

@Cyberloki
Created September 22, 2013 21:40
Show Gist options
  • Save Cyberloki/6664126 to your computer and use it in GitHub Desktop.
Save Cyberloki/6664126 to your computer and use it in GitHub Desktop.
Alter Table Add Field with Constraint
if not exists (select 1 from syscolumns where name = 'Integrated_Mapping' and ID in (select so.ID from sysobjects so where so.name = 'PRODUCTS' and so.type = 'U') )
alter table PRODUCTS ADD Integrated_Mapping bit NULL
GO
UPDATE PRODUCTS SET Integrated_Mapping = 0 where (Integrated_Mapping IS NULL)
GO
if not exists ( select 1 from sysconstraints where constid in
(select so.ID from sysobjects so
where so.name = 'df_Product_IntgMapping' and so.type = 'D')
)
ALTER TABLE [dbo].[PRODUCTS] ADD CONSTRAINT [df_Product_IntgMapping] DEFAULT ((0)) FOR [Integrated_Mapping]
GO
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment