USE @DBNAME 

IF NOT EXISTS (SELECT  * FROM syscolumns WHERE  name = 'PwdP' AND id = object_Id(N'Person')) 
ALTER TABLE person ADD PwdP varchar(30) NULL 

IF EXISTS (SELECT  * FROM syscolumns WHERE  name = 'PwdP' AND id = object_Id(N'Person')) 
ALTER TABLE person ALTER Column PwdP varchar(30) NULL 

IF NOT EXISTS (SELECT  * FROM syscolumns WHERE  name = 'UseActiveDirectory' AND id = object_Id(N'Person')) 
ALTER TABLE person ADD UseActiveDirectory bit NULL 

IF NOT EXISTS(SELECT   * FROM syscolumns WHERE     name = 'DomainLoginName' AND id = object_Id(N'Person')) 
ALTER TABLE person ADD [DomainLoginName] char(50) NULL

IF NOT EXISTS(SELECT   * FROM syscolumns WHERE     name = 'DomainLoginName' AND id = object_Id(N'Person')) 
ALTER TABLE person ADD [DomainLoginName] char(50) NULL

IF NOT EXISTS(SELECT   * FROM syscolumns WHERE     name = 'Theme' AND id = object_Id(N'Person')) 
ALTER TABLE person ADD [Theme] char(20) NULL

IF NOT EXISTS(SELECT   * FROM syscolumns WHERE     name = 'LoginFailedCount' AND id = object_Id(N'Person')) 
ALTER TABLE person ADD [LoginFailedCount] numeric(10, 0) NULL DEFAULT(0) WITH VALUES

IF NOT EXISTS(SELECT   * FROM syscolumns WHERE     name = 'PwdLastChangeDate' AND id = object_Id(N'Person')) 
ALTER TABLE person ADD [PwdLastChangeDate] char(10) NULL 

IF NOT EXISTS(SELECT   * FROM syscolumns WHERE     name = 'DefaultPwd' AND id = object_Id(N'Person')) 
ALTER TABLE person ADD [DefaultPwd] numeric(6, 0) NULL DEFAULT(0) WITH VALUES

IF NOT EXISTS(SELECT   * FROM syscolumns WHERE     name = 'IsEncrypted' AND id = object_Id(N'Person')) 
ALTER TABLE person ADD [IsEncrypted] numeric(6, 0) NULL DEFAULT(0) WITH VALUES

IF NOT EXISTS(SELECT   * FROM syscolumns WHERE     name = 'FirstUSDateTime' AND id = object_Id(N'Person')) 
ALTER TABLE person ADD [FirstUSDateTime] char(13) NULL 


else
begin
ALTER TABLE person
ALTER COLUMN Theme char(20) null
end
IF NOT EXISTS(SELECT   * FROM syscolumns WHERE     name = 'userPermission' AND id = object_Id(N'Person')) 
ALTER TABLE person ADD [userPermission] char(100) NULL


