Use @DBNAME

SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
SET ANSI_PADDING ON
Begin Transaction updateSystem

If(Not Exists(SELECT     id
                FROM         syscolumns
                WHERE     (name = 'AddressURL') AND (id IN
                                          (SELECT     id
                                             FROM         sysobjects
                                             WHERE     (name = 'SYSTEM')))))
Alter Table SYSTEM Add
        AddressURL char(100)  NULL

If(Not Exists(SELECT     id
                FROM         syscolumns
                WHERE     (name = 'TextURL') AND (id IN
                                          (SELECT     id
                                             FROM         sysobjects
                                             WHERE     (name = 'SYSTEM')))))
Alter Table SYSTEM Add TextURL char(100)  NULL

If(Not Exists(SELECT     id
                FROM         syscolumns
                WHERE     (name = 'MorTransfer') AND (id IN
                                          (SELECT     id
                                             FROM         sysobjects
                                             WHERE     (name = 'SYSTEM')))))
Alter Table [SYSTEM] Add MorTransfer char(1) DEFAULT '0' NULL

If(Not Exists(SELECT     id
                FROM         syscolumns
                WHERE     (name = 'MisTransfer') AND (id IN
                                          (SELECT     id
                                             FROM         sysobjects
                                             WHERE     (name = 'SYSTEM')))))
Alter Table [SYSTEM] Add MisTransfer char(1) DEFAULT '0' NULL


If(Not Exists(SELECT     id
                FROM         syscolumns
                WHERE     (name = 'SystemPasswordPolicy') AND (id IN
                                          (SELECT     id
                                             FROM         sysobjects
                                             WHERE     (name = 'SYSTEM')))))
Alter Table [SYSTEM] Add SystemPasswordPolicy numeric(6, 0) NULL DEFAULT(0) WITH VALUES


If(Not Exists(SELECT     id
                FROM         syscolumns
                WHERE     (name = 'UserPassMinLength') AND (id IN
                                          (SELECT     id
                                             FROM         sysobjects
                                             WHERE     (name = 'SYSTEM')))))
Alter Table [SYSTEM] Add UserPassMinLength numeric(6, 0) NULL DEFAULT(10) WITH VALUES


If(Not Exists(SELECT     id
                FROM         syscolumns
                WHERE     (name = 'UserPassCharTypeCount') AND (id IN
                                          (SELECT     id
                                             FROM         sysobjects
                                             WHERE     (name = 'SYSTEM')))))
Alter Table [SYSTEM] Add UserPassCharTypeCount numeric(6, 0) NULL DEFAULT(4) WITH VALUES


If(Not Exists(SELECT     id
                FROM         syscolumns
                WHERE     (name = 'MinDayCredit') AND (id IN
                                          (SELECT     id
                                             FROM         sysobjects
                                             WHERE     (name = 'SYSTEM')))))
Alter Table [SYSTEM] Add MinDayCredit numeric(6, 0) NULL DEFAULT(1) WITH VALUES


If(Not Exists(SELECT     id
                FROM         syscolumns
                WHERE     (name = 'ManagerPassMinLength') AND (id IN
                                          (SELECT     id
                                             FROM         sysobjects
                                             WHERE     (name = 'SYSTEM')))))
Alter Table [SYSTEM] Add ManagerPassMinLength numeric(6, 0) NULL DEFAULT(10) WITH VALUES 

If(Not Exists(SELECT     id
                FROM         syscolumns
                WHERE     (name = 'ManagerPassCharTypeCount') AND (id IN
                                          (SELECT     id
                                             FROM         sysobjects
                                             WHERE     (name = 'SYSTEM')))))
Alter Table [SYSTEM] Add ManagerPassCharTypeCount numeric(6, 0) NULL DEFAULT(4) WITH VALUES


If(Not Exists(SELECT     id
                FROM         syscolumns
                WHERE     (name = 'HasRepeatChar') AND (id IN
                                          (SELECT     id
                                             FROM         sysobjects
                                             WHERE     (name = 'SYSTEM')))))
Alter Table [SYSTEM] Add HasRepeatChar numeric(6, 0) NULL DEFAULT(0) WITH VALUES


If(Not Exists(SELECT     id
                FROM         syscolumns
                WHERE     (name = 'MaxDayCredit') AND (id IN
                                          (SELECT     id
                                             FROM         sysobjects
                                             WHERE     (name = 'SYSTEM')))))
Alter Table [SYSTEM] Add MaxDayCredit numeric(6, 0) NULL DEFAULT(90) WITH VALUES

If(Not Exists(SELECT     id
                FROM         syscolumns
                WHERE     (name = 'MaxDayExist') AND (id IN
                                          (SELECT     id
                                             FROM         sysobjects
                                             WHERE     (name = 'SYSTEM')))))
Alter Table [SYSTEM] Add MaxDayExist numeric(6, 0) NULL DEFAULT(0) WITH VALUES


If(Not Exists(SELECT     id
                FROM         syscolumns
                WHERE     (name = 'DayMessageCredit') AND (id IN
                                          (SELECT     id
                                             FROM         sysobjects
                                             WHERE     (name = 'SYSTEM')))))
Alter Table [SYSTEM] Add DayMessageCredit numeric(6, 0) NULL DEFAULT(7) WITH VALUES

If(Not Exists(SELECT     id
                FROM         syscolumns
                WHERE     (name = 'ManagerMaxDayCredit') AND (id IN
                                          (SELECT     id
                                             FROM         sysobjects
                                             WHERE     (name = 'SYSTEM')))))
Alter Table [SYSTEM] Add ManagerMaxDayCredit numeric(6, 0) NULL DEFAULT(90) WITH VALUES

If(Not Exists(SELECT     id
                FROM         syscolumns
                WHERE     (name = 'ManagerMaxDayExist') AND (id IN
                                          (SELECT     id
                                             FROM         sysobjects
                                             WHERE     (name = 'SYSTEM')))))
Alter Table [SYSTEM] Add ManagerMaxDayExist numeric(6, 0) NULL DEFAULT(0) WITH VALUES


If(Not Exists(SELECT     id
                FROM         syscolumns
                WHERE     (name = 'ManagerDayMessageCredit') AND (id IN
                                          (SELECT     id
                                             FROM         sysobjects
                                             WHERE     (name = 'SYSTEM')))))
Alter Table [SYSTEM] Add ManagerDayMessageCredit numeric(6, 0) NULL DEFAULT(7) WITH VALUES


If(Not Exists(SELECT     id
                FROM         syscolumns
                WHERE     (name = 'MaxRepeatPassCount') AND (id IN
                                          (SELECT     id
                                             FROM         sysobjects
                                             WHERE     (name = 'SYSTEM')))))
Alter Table [SYSTEM] Add MaxRepeatPassCount numeric(6, 0) NULL DEFAULT(5) WITH VALUES

If(Not Exists(SELECT     id
                FROM         syscolumns
                WHERE     (name = 'MaxTryExist') AND (id IN
                                          (SELECT     id
                                             FROM         sysobjects
                                             WHERE     (name = 'SYSTEM')))))
Alter Table [SYSTEM] Add MaxTryExist numeric(6, 0) NULL DEFAULT(0) WITH VALUES

If(Not Exists(SELECT     id
                FROM         syscolumns
                WHERE     (name = 'MaxTryCountDeactive') AND (id IN
                                          (SELECT     id
                                             FROM         sysobjects
                                             WHERE     (name = 'SYSTEM')))))
Alter Table [SYSTEM] Add MaxTryCountDeactive numeric(6, 0) NULL DEFAULT(3) WITH VALUES

If(Not Exists(SELECT     id
                FROM         syscolumns
                WHERE     (name = 'ChangePassFirstLogin') AND (id IN
                                          (SELECT     id
                                             FROM         sysobjects
                                             WHERE     (name = 'SYSTEM')))))
Alter Table [SYSTEM] Add ChangePassFirstLogin numeric(6, 0) NULL DEFAULT(0) WITH VALUES


If(Not Exists(SELECT     id
                FROM         syscolumns
                WHERE     (name = 'HasPersonalityInformation') AND (id IN
                                          (SELECT     id
                                             FROM         sysobjects
                                             WHERE     (name = 'SYSTEM')))))
Alter Table [SYSTEM] Add HasPersonalityInformation numeric(6, 0) NULL DEFAULT(0) WITH VALUES

If(Not Exists(SELECT     id
                FROM         syscolumns
                WHERE     (name = 'MaxTryMinutes') AND (id IN
                                          (SELECT     id
                                             FROM         sysobjects
                                             WHERE     (name = 'SYSTEM')))))
Alter Table [SYSTEM] Add MaxTryMinutes numeric(6, 0) NULL DEFAULT(0) WITH VALUES

If(Not Exists(SELECT     id
                FROM         syscolumns
                WHERE     (name = 'MaxTryActiveMinutes') AND (id IN
                                          (SELECT     id
                                             FROM         sysobjects
                                             WHERE     (name = 'SYSTEM')))))
Alter Table [SYSTEM] Add MaxTryActiveMinutes numeric(6, 0) NULL DEFAULT(0) WITH VALUES


If (@@ERROR > 0 )
  Rollback Transaction updateSystem
Else
    Commit Transaction updateSystem
