Declare @TableName Varchar(60)
Declare @FieldName Varchar(50)
Declare @DefaultName Varchar(100)
Declare @StrCommand varchar(1000)

Declare ChangeDefaultField cursor For
Select 'HeadH' TableName, 'Store_code' FieldName
Union 
Select 'HeadC' TableName, 'Store_code' FieldName
Union 
Select 'HeadS' TableName, 'Store_code' FieldName
Union 
Select 'TmpHeadH' TableName, 'Store_code' FieldName
Union 
Select 'TmpHeadC' TableName, 'Store_code' FieldName
Union 
Select 'TmpHeadS' TableName, 'Store_code' FieldName
Union 
Select 'Over_Under' TableName, 'Storecode' FieldName
Union 
Select 'Guy' TableName, 'Store_code' FieldName
Union 
Select 'Bank' TableName, 'Store_code' FieldName
Union 
Select 'Account' TableName, 'Store_code' FieldName
Union 
Select 'AnbarId' TableName, 'Store_code' FieldName

Open ChangeDefaultField
Fetch Next From ChangeDefaultField Into @TableName, @FieldName
While @@Fetch_Status = 0 
Begin
  Set @StrCommand = ' ALTER TABLE dbo.' + @TableName + ' ADD CONSTRAINT' +
                    ' DF_' + @TableName + '_' + @FieldName + ' DEFAULT Dbo.GetShopCode() FOR ' + @FieldName
  Execute(@StrCommand)
  Fetch Next From ChangeDefaultField Into @TableName, @FieldName
End
Close ChangeDefaultField
Deallocate ChangeDefaultField

