IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Tmp_Over_Under_Row_Drug]') AND type IN (N'U'))
BEGIN
CREATE TABLE [dbo].[Tmp_Over_Under_Row_Drug](
	[AutoId] [NUMERIC](18, 0) IDENTITY(1,1) NOT NULL,
	[PrescriptionId] [NUMERIC](19, 0) NOT NULL,
	[Code_Over_Under] [SMALLINT] NULL,
	[Code_Act] [SMALLINT] NULL,
	[Kind_Act] [SMALLINT] NULL,
	[Price] [MONEY] NULL,
	[Percent] [REAL] NULL,
	[Name] [NVARCHAR](30) NULL,
	[Type] [CHAR](1) NOT NULL,
	[Max_Price] [MONEY] NULL,
	[Max_Percent] [REAL] NULL,
	[ShowPrice] [CHAR](1) NULL,
	[Price_Row] [CHAR](1) NULL,
 CONSTRAINT [PK_Tmp_Over_Under_Row_Drug] PRIMARY KEY CLUSTERED 
(
	[AutoId] ASC
)
) ON [PRIMARY]
END

IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Tmp_Over_Under_Row_Drug_TmpDrugHavaleh]') AND parent_object_id = OBJECT_ID(N'[dbo].[Tmp_Over_Under_Row_Drug]'))
ALTER TABLE [dbo].[Tmp_Over_Under_Row_Drug]  WITH CHECK ADD  CONSTRAINT [FK_Tmp_Over_Under_Row_Drug_TmpDrugHavaleh] FOREIGN KEY([PrescriptionId])
REFERENCES [dbo].[TmpDrugHavaleh] ([AutoId])
ON DELETE CASCADE

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