IF NOT EXISTS (SELECT * FROM SYSCOLUMNS INNER JOIN SYSOBJECTS ON SYSOBJECTS.id = SYSCOLUMNS.id 
              WHERE SYSCOLUMNS.NAME = 'SUBEID' AND SYSOBJECTS.name = 'PEGITIM')
ALTER TABLE PEGITIM ADD SUBEID integer
GO

IF NOT EXISTS (SELECT * FROM SYSCOLUMNS INNER JOIN SYSOBJECTS ON SYSOBJECTS.id = SYSCOLUMNS.id 
              WHERE SYSCOLUMNS.NAME = 'SUBEID' AND SYSOBJECTS.name = 'PEGITIMD')
ALTER TABLE PEGITIMD ADD SUBEID integer
GO

UPDATE PEGITIM SET SUBEID=(SELECT TOP 1 SUBEID FROM SUBELER)
GO
UPDATE PEGITIMD SET SUBEID=(SELECT TOP 1 SUBEID FROM SUBELER)
GO
