IF NOT EXISTS (SELECT * FROM SYSCOLUMNS INNER JOIN SYSOBJECTS ON SYSOBJECTS.id = SYSCOLUMNS.id 
               WHERE SYSCOLUMNS.NAME = 'HAPANELACIKLAMAID' AND SYSOBJECTS.name = 'HAMELIYAT')
ALTER TABLE dbo.HAMELIYAT 
	ADD HAPANELACIKLAMAID INT NULL
GO

IF NOT EXISTS (SELECT * FROM SYSCOLUMNS INNER JOIN SYSOBJECTS ON SYSOBJECTS.id = SYSCOLUMNS.id 
               WHERE SYSCOLUMNS.NAME = 'HAPANELACIKLAMAAKTIF' AND SYSOBJECTS.name = 'HAMELIYAT')
ALTER TABLE dbo.HAMELIYAT ADD
	HAPANELACIKLAMAAKTIF bit NULL DEFAULT(1)
GO

IF NOT EXISTS (SELECT * FROM SYSCOLUMNS INNER JOIN SYSOBJECTS ON SYSOBJECTS.id = SYSCOLUMNS.id 
               WHERE SYSCOLUMNS.NAME = 'HAPANELACIKLAMABASTARIH' AND SYSOBJECTS.name = 'HAMELIYAT')
ALTER TABLE dbo.HAMELIYAT 
	ADD HAPANELACIKLAMABASTARIH datetime NULL
GO

IF NOT EXISTS (SELECT * FROM SYSCOLUMNS INNER JOIN SYSOBJECTS ON SYSOBJECTS.id = SYSCOLUMNS.id 
               WHERE SYSCOLUMNS.NAME = 'HAPANELACIKLAMABITISTARIH' AND SYSOBJECTS.name = 'HAMELIYAT')
ALTER TABLE dbo.HAMELIYAT 
	ADD HAPANELACIKLAMABITISTARIH datetime NULL
GO

IF NOT EXISTS (SELECT * FROM SYSCOLUMNS INNER JOIN SYSOBJECTS ON SYSOBJECTS.id = SYSCOLUMNS.id 
               WHERE SYSCOLUMNS.NAME = 'HASINIFLAMAID' AND SYSOBJECTS.name = 'HAMELIYAT')
ALTER TABLE dbo.HAMELIYAT ADD
	HASINIFLAMAID int NULL
GO

IF NOT EXISTS(select sysobjects.id from sysconstraints inner join sysobjects on sysobjects.id = constid where sysobjects.name = 'FK_HAMELIYAT_TAMELIYATPANELACIKLAMA' and xtype='F')
ALTER TABLE dbo.HAMELIYAT ADD CONSTRAINT
	FK_HAMELIYAT_TAMELIYATPANELACIKLAMA FOREIGN KEY
	(
	HAPANELACIKLAMAID
	) REFERENCES dbo.TAMELIYATPANELACIKLAMA
	(
	AMELIYATPANELACIKLAMAID
	) ON UPDATE  NO ACTION 
	 ON DELETE  NO ACTION 
	
GO