 if OBJECT_ID('@t6db..[InventoryPicture]','U') is NOT NULL
BEGIN
   --先插入图片表，并临时将cTableName字段插入存货cInvCode值
   if exists (select 1 from @u8db..syscolumns where id =(select ID from @u8db..sysobjects where 
			name ='AA_Picture' and xtype='u')  and name ='SinglePicture')
   exec ('insert INTO @u8db..AA_Picture
   (cGUID,cPicturetype,cTableName,Picture,SinglePicture)
   SELECT NEWID() AS cGUID,[cPicType],cInvCode AS cTableName,[gInvPicture],NULL AS SinglePicture
   FROM @t6db..InventoryPicture')
   else
   exec('
   insert INTO @u8db..AA_Picture
   (cGUID,cPicturetype,cTableName,Picture)
   SELECT NEWID() AS cGUID,[cPicType],cInvCode AS cTableName,[gInvPicture]
   FROM @t6db..InventoryPicture
    
   UPDATE @u8db..inventory SET @u8db..inventory.pictureGUID=b.cGUID
   FROM @u8db..AA_Picture b JOIN @u8db..inventory ON @u8db..inventory.cInvCode=b.ctablename')
   --根据cInvCode更新存货表中的Guid，并将AA_Picture的cTableName字段更新为'Inventory'
    --更新AA_Picture存货表，将cTableName值改为'Inventory'
   UPDATE @u8db..AA_Picture SET cTableName='Inventory'
END
