IF EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'SERVISENTEGRASYON' AND TABLE_SCHEMA = 'DBO')
BEGIN
    IF EXISTS (SELECT *  FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS WHERE CONSTRAINT_NAME = 'FK_SERVISENTEGRASYON_SERVISENTEGRASYONTANIM' AND CONSTRAINT_SCHEMA = 'DBO')
	   ALTER TABLE [dbo].[SERVISENTEGRASYON] DROP CONSTRAINT [FK_SERVISENTEGRASYON_SERVISENTEGRASYONTANIM] 
    DROP TABLE DBO.SERVISENTEGRASYON
END
GO
CREATE TABLE [dbo].[SERVISENTEGRASYON](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[SERVISGONDERIMFONKSIYONADI] [nvarchar](50) NOT NULL,
	[ISTEKZAMANI] [datetime] NOT NULL,
	[CEVAPZAMANI] [datetime] NULL,
	[SUBEID] [int] NULL,
	[KAYITID] [nvarchar](50) NOT NULL,
	[ISTEKXML] [nvarchar](max) NULL,
	[CEVAPXML] [nvarchar](max) NULL,
	[DENEMESAYISI] [tinyint] NULL,
	[DURUM] [tinyint] NOT NULL,
PRIMARY KEY CLUSTERED 
(
	[ISTEKZAMANI] ASC,
	[SERVISGONDERIMFONKSIYONADI] ASC,
	[KAYITID] ASC,
	[DURUM] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
UNIQUE NONCLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
SET ANSI_PADDING ON
GO
/****** Object:  Index [IX_SERVISENTEGRASYON_DURUM_DENEMESAYISI]    Script Date: 27.03.2018 19:48:10 ******/
CREATE NONCLUSTERED INDEX [IX_SERVISENTEGRASYON_DURUM_DENEMESAYISI] ON [dbo].[SERVISENTEGRASYON]
(
	[DURUM] ASC,
	[DENEMESAYISI] ASC
)
INCLUDE ( 	[ID],
	[SERVISGONDERIMFONKSIYONADI],
	[KAYITID],
	[ISTEKXML],[SUBEID]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
ALTER TABLE [dbo].[SERVISENTEGRASYON]  WITH CHECK ADD  CONSTRAINT [FK_SERVISENTEGRASYON_SERVISENTEGRASYONTANIM] FOREIGN KEY([SERVISGONDERIMFONKSIYONADI])
REFERENCES [dbo].[SERVISENTEGRASYONTANIM] ([GONDERIMFONKSIYONADI])
GO
ALTER TABLE [dbo].[SERVISENTEGRASYON] CHECK CONSTRAINT [FK_SERVISENTEGRASYON_SERVISENTEGRASYONTANIM]
GO
