IF NOT EXISTS (SELECT * FROM sysobjects WHERE name = 'PISGetActivePrescriptionIdDetail')
BEGIN
CREATE TABLE [dbo].[PISGetActivePrescriptionIdDetail](
	[Id] [UNIQUEIDENTIFIER] NOT NULL,
	[ActivePrescriptionId] [UNIQUEIDENTIFIER] NULL,
	[HID] [VARCHAR](50) NULL,
	[InsuranceCode] [NVARCHAR](MAX) NULL,
	[CreatedOn] [DATETIME] NULL,
 CONSTRAINT [PK_PISGetActivePrescriptionIdDetail] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)
) ON [PRIMARY] 

ALTER TABLE [dbo].[PISGetActivePrescriptionIdDetail] ADD  CONSTRAINT [DF_PISGetActivePrescriptionIdDetail_Id]  DEFAULT (NEWID()) FOR [Id]
ALTER TABLE [dbo].[PISGetActivePrescriptionIdDetail] ADD  CONSTRAINT [DF_PISGetActivePrescriptionIdDetail_CreatedOn]  DEFAULT (GETDATE()) FOR [CreatedOn]
ALTER TABLE [dbo].[PISGetActivePrescriptionIdDetail]  WITH CHECK ADD  CONSTRAINT [FK_PISGetActivePrescriptionIdDetail_PISGetActivePrescriptionId] FOREIGN KEY([ActivePrescriptionId])
REFERENCES [dbo].[PISGetActivePrescriptionId] ([Id])
ON DELETE CASCADE
ALTER TABLE [dbo].[PISGetActivePrescriptionIdDetail] CHECK CONSTRAINT [FK_PISGetActivePrescriptionIdDetail_PISGetActivePrescriptionId]

End