SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TKLINIKKALITEREFERANS]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[TKLINIKKALITEREFERANS](
	[KLINIKKALITEREFERANSKOD] [int] NOT NULL,
	[KLINIKKALITEKOD] [int] NOT NULL,
	[REFERANSKOD] [nvarchar](50) NOT NULL,
	[REFERANSTUR] [nvarchar](50) NULL,
	[AKTIF] [bit] NOT NULL,
	[OLUSTURMATARIHI] [datetime] NULL,
	[GUNCELLEMETARIHI] [datetime] NULL,
 CONSTRAINT [PK_TKLINIKKALITEREFERANS] PRIMARY KEY CLUSTERED 
(
	[KLINIKKALITEREFERANSKOD] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO

IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[DF_TKLINIKKALITEREFERANS_AKTIF]') AND type = 'D')
BEGIN
ALTER TABLE [dbo].[TKLINIKKALITEREFERANS] ADD  CONSTRAINT [DF_TKLINIKKALITEREFERANS_AKTIF]  DEFAULT ((1)) FOR [AKTIF]
END

GO

IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_TKLINIKKALITEREFERANS_TKLINIKKALITE]') AND parent_object_id = OBJECT_ID(N'[dbo].[TKLINIKKALITEREFERANS]'))
ALTER TABLE [dbo].[TKLINIKKALITEREFERANS]  WITH CHECK ADD  CONSTRAINT [FK_TKLINIKKALITEREFERANS_TKLINIKKALITE] FOREIGN KEY([KLINIKKALITEKOD])
REFERENCES [dbo].[TKLINIKKALITE] ([KLINIKKALITEKOD])
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_TKLINIKKALITEREFERANS_TKLINIKKALITE]') AND parent_object_id = OBJECT_ID(N'[dbo].[TKLINIKKALITEREFERANS]'))
ALTER TABLE [dbo].[TKLINIKKALITEREFERANS] CHECK CONSTRAINT [FK_TKLINIKKALITEREFERANS_TKLINIKKALITE]
GO


