--Add columns
IF not EXISTS (SELECT * from syscolumns WHERE id=object_id (' tbl_tranwoandcochistorybyrailassure ') and name= ' CreatedDate ' )
BEGIN
ALTER TABLE Tbl_tranwoandcochistorybyrailassure
ADD createddate DATETIME not NULL DEFAULT GETDATE ()
END
--Modify Columns
IF EXISTS (SELECT * from syscolumns WHERE id=object_id (' tbl_tranwoandcochistorybyrailassure ') and Name= ' CreatedDate ')
BEGIN
ALTER TABLE Tbl_tranwoandcochistorybyrailassure
ALTER COLUMN createddate NVARCHAR (10)
END
--1. Deleting a column, deleting the default value constraint name first
IF EXISTS (SELECT * from syscolumns WHERE id=object_id (' tbl_tranwoandcochistorybyrailassure ') and Name= ' CreatedDate ')
BEGIN
ALTER TABLE Tbl_tranwoandcochistorybyrailassure
DROP constraint df__tbl_tranw__createddate__359dcdd0
END
--2. Deleting columns
IF EXISTS (SELECT * from syscolumns WHERE id=object_id (' tbl_tranwoandcochistorybyrailassure ') and Name= ' CreatedDate ')
BEGIN
ALTER TABLE Tbl_tranwoandcochistorybyrailassure
DROP COLUMN CreatedDate
END
SQL Server Add or modify columns