DECLARE @Id Int                               
SELECT @Id = Id From sysobjects Where Name = 'TmpHeadH'
if not Exists(SELECT * FROM syscolumns WHERE id = @Id and Name = 'Store_Code')
  Alter Table dbo.TmpHeadH Add  Store_Code VARCHAR(3) NULL

SELECT @Id = Id From sysobjects Where Name = 'TmpHeadC'
if not Exists(SELECT * FROM syscolumns WHERE id = @Id and Name = 'Store_Code')
  Alter Table dbo.TmpHeadC Add  Store_Code VARCHAR(3) NULL

SELECT @Id = Id From sysobjects Where Name = 'TmpHeadS'
if not Exists(SELECT * FROM syscolumns WHERE id = @Id and Name = 'Store_Code')
  Alter Table dbo.TmpHeadS Add  Store_Code VARCHAR(3) NULL

SELECT @Id = Id From sysobjects Where Name = 'TmpSanad'
if not Exists(SELECT * FROM syscolumns WHERE id = @Id and Name = 'Store_Code')
  Alter Table dbo.TmpSanad Add  Store_Code VARCHAR(3) NULL

SELECT @Id = Id From sysobjects Where Name = 'HeadH'
if not Exists(SELECT * FROM syscolumns WHERE id = @Id and Name = 'Store_Code')
  Alter Table dbo.HeadH Add  Store_Code VARCHAR(3) NULL

Select @Id = Id From sysobjects Where Name = 'Headh'
if not Exists(SELECT * FROM syscolumns WHERE id = @Id and Name = 'Id')
  Alter Table dbo.Headh Add  Id UNIQUEIDENTIFIER DEFAULT(NEWID()) NOT NULL

Select @Id = Id From sysobjects Where Name = 'Havaleh'
if not Exists(SELECT * FROM syscolumns WHERE id = @Id and Name = 'Id')
  Alter Table dbo.Havaleh Add Id UNIQUEIDENTIFIER DEFAULT(NEWID()) NOT NULL

Select @Id = Id From sysobjects Where Name = 'Havaleh'
IF not Exists(SELECT * FROM syscolumns WHERE id = @Id and Name = 'FactorId')
  Alter Table dbo.Havaleh Add FactorId UNIQUEIDENTIFIER Null

Select @Id = Id From sysobjects Where Name = 'Havaleh'
if not Exists(SELECT * FROM syscolumns WHERE id = @Id and Name = 'ChainFlag')
  Alter Table dbo.Havaleh Add  ChainFlag char(1)  Default(0)

SELECT @Id = Id From sysobjects Where Name = 'HeadC'
if not Exists(SELECT * FROM syscolumns WHERE id = @Id and Name = 'Store_Code')
  Alter Table dbo.HeadC Add  Store_Code VARCHAR(3) NULL

SELECT @Id = Id From sysobjects Where Name = 'HeadS'
if not Exists(SELECT * FROM syscolumns WHERE id = @Id and Name = 'Store_Code')
  Alter Table dbo.HeadS Add  Store_Code VARCHAR(3) NULL

SELECT @Id = Id From sysobjects Where Name = 'Sanad'
if not Exists(SELECT * FROM syscolumns WHERE id = @Id and Name = 'Store_Code')
  Alter Table dbo.Sanad Add  Store_Code VARCHAR(3) NULL

Select @Id = Id From sysobjects Where Name = 'Sanad'
if not Exists(SELECT * FROM syscolumns WHERE id = @Id and Name = 'ChainFlag')
  Alter Table dbo.Sanad Add  ChainFlag char(1)  Default(0)

Select @Id = Id From sysobjects Where Name = 'Heads'
if not Exists(SELECT * FROM syscolumns WHERE id = @Id and Name = 'Id')
  Alter Table dbo.Heads Add  Id UNIQUEIDENTIFIER DEFAULT(NEWID()) NOT NULL

SELECT @Id = Id From sysobjects Where Name = 'Sanad'
IF not Exists(SELECT * FROM syscolumns WHERE id = @Id and Name = 'Id')
  Alter Table dbo.Sanad Add  Id UNIQUEIDENTIFIER DEFAULT(NEWID()) NOT NULL

SELECT @Id = Id From sysobjects Where Name = 'Sanad'
IF not Exists(SELECT * FROM syscolumns WHERE id = @Id and Name = 'AccountingDocumentId')
  Alter Table dbo.Sanad Add AccountingDocumentId UNIQUEIDENTIFIER NULL

Select @Id = Id From sysobjects Where Name = 'AnbarId'
if not Exists(SELECT * FROM syscolumns WHERE id = @Id and Name = 'SyncTime')
  Alter Table dbo.AnbarId Add  SyncTime DATETIME Null

Select @Id = Id From sysobjects Where Name = 'Anbar'
if not Exists(SELECT * FROM syscolumns WHERE id = @Id and Name = 'SyncTime')
  Alter Table dbo.Anbar Add  SyncTime DATETIME Null

Select @Id = Id From sysobjects Where Name = 'Kalaid'
if not Exists(SELECT * FROM syscolumns WHERE id = @Id and Name = 'SyncTime')
  Alter Table dbo.Kalaid Add  SyncTime DATETIME Null

Select @Id = Id From sysobjects Where Name = 'SummaryAccountingDocuments'
if not Exists(SELECT * FROM syscolumns WHERE id = @Id and Name = 'SyncTime')
  Alter Table dbo.SummaryAccountingDocuments Add  SyncTime DATETIME Null

Select @Id = Id From sysobjects Where Name = 'SummaryAccountingDocumentDetails'
if not Exists(SELECT * FROM syscolumns WHERE id = @Id and Name = 'SyncTime')
  Alter Table dbo.SummaryAccountingDocumentDetails Add  SyncTime DATETIME Null

Select @Id = Id From sysobjects Where Name = 'SummaryFactors'
if not Exists(SELECT * FROM syscolumns WHERE id = @Id and Name = 'SyncTime')
  Alter Table dbo.SummaryFactors Add  SyncTime DATETIME Null

Select @Id = Id From sysobjects Where Name = 'SummaryFactorDetails'
if not Exists(SELECT * FROM syscolumns WHERE id = @Id and Name = 'SyncTime')
  Alter Table dbo.SummaryFactorDetails Add  SyncTime DATETIME Null

Select @Id = Id From sysobjects Where Name = 'SummaryFactorDetails'
if not Exists(SELECT * FROM syscolumns WHERE id = @Id and Name = 'Status')
  Alter Table dbo.SummaryFactorDetails Add  Status Char(1) Null