IF NOT EXISTS (SELECT * FROM SYSCOLUMNS INNER JOIN SYSOBJECTS ON SYSOBJECTS.id = SYSCOLUMNS.id 
              WHERE SYSCOLUMNS.NAME = 'FR3_AYAKTAN' AND SYSOBJECTS.name = 'TSENCARDDOSYATUR')
ALTER TABLE TSENCARDDOSYATUR ADD FR3_AYAKTAN nvarchar(250)  NULL 
go

IF NOT EXISTS (SELECT * FROM SYSCOLUMNS INNER JOIN SYSOBJECTS ON SYSOBJECTS.id = SYSCOLUMNS.id 
              WHERE SYSCOLUMNS.NAME = 'FR3_YATARAK' AND SYSOBJECTS.name = 'TSENCARDDOSYATUR')
ALTER TABLE TSENCARDDOSYATUR ADD FR3_YATARAK nvarchar(250)  NULL 
go

IF NOT EXISTS (SELECT * FROM SYSCOLUMNS INNER JOIN SYSOBJECTS ON SYSOBJECTS.id = SYSCOLUMNS.id 
              WHERE SYSCOLUMNS.NAME = 'FR3_GUNUBIRLIK' AND SYSOBJECTS.name = 'TSENCARDDOSYATUR')
ALTER TABLE TSENCARDDOSYATUR ADD FR3_GUNUBIRLIK nvarchar(250)  NULL 
go

IF NOT EXISTS (SELECT * FROM SYSCOLUMNS INNER JOIN SYSOBJECTS ON SYSOBJECTS.id = SYSCOLUMNS.id 
              WHERE SYSCOLUMNS.NAME = 'AKTIF' AND SYSOBJECTS.name = 'TSENCARDDOSYATUR')
ALTER TABLE TSENCARDDOSYATUR ADD AKTIF bit NOT NULL CONSTRAINT DF_TSENCARDDOSYATUR_AKTIF DEFAULT 1
go

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

UPDATE TSENCARDDOSYATUR SET SUBEID=(SELECT MIN(SUBEID) FROM SUBELER )  WHERE SUBEID IS NULL
GO