DECLARE @Id Int                               

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

SELECT @Id = Id From sysobjects Where Name = 'Headh'
IF not Exists(SELECT * FROM syscolumns WHERE id = @Id and Name = 'Sended')
  Alter Table dbo.Headh Add Sended Bit Default(0)

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 = 'TmpHeadh'
IF not Exists(SELECT * FROM syscolumns WHERE id = @Id and Name = 'Id')
  Alter Table dbo.TmpHeadh 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 = 'TmpHavaleh'
if not Exists(SELECT * FROM syscolumns WHERE id = @Id and Name = 'Id')
  Alter Table dbo.TmpHavaleh Add Id UNIQUEIDENTIFIER Default(NEWID()) NOT NULL

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

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

SELECT @Id = Id From sysobjects Where Name = 'Over_Under_Factor'
if not Exists(SELECT * FROM syscolumns WHERE id = @Id and Name = 'FactorId')
  Alter Table dbo.Over_Under_Factor Add FactorId UNIQUEIDENTIFIER Null
  
SELECT @Id = Id From sysobjects Where Name = 'Tmp_Over_Under_Factor'
if not Exists(SELECT * FROM syscolumns WHERE id = @Id and Name = 'Id')
  Alter Table dbo.Tmp_Over_Under_Factor Add Id UNIQUEIDENTIFIER Default(NEWID()) NOT NULL

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

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

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

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

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

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

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

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

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


SELECT @Id = Id From sysobjects Where Name = 'SummaryFactors'
IF not Exists(SELECT * FROM syscolumns WHERE id = @Id and Name = 'Sended')
  Alter Table SummaryFactors Add Sended bit DEFAULT(0)

SELECT @Id = Id From sysobjects Where Name = 'SummaryFactorDetails'
IF not Exists(SELECT * FROM syscolumns WHERE id = @Id and Name = 'Sended')
  Alter Table dbo.SummaryFactorDetails Add Sended bit DEFAULT(0)
