Created
September 22, 2013 21:40
-
-
Save Cyberloki/6664126 to your computer and use it in GitHub Desktop.
Alter Table Add Field with Constraint
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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