IF Not (EXISTS(SELECT * FROM sysobjects WHERE name='IHIOPrescriptionDetail'))
Begin
CREATE TABLE [dbo].[IHIOPrescriptionDetail](
	[Id] [uniqueidentifier] PRIMARY KEY  NOT NULL DEFAULT(NEWID()),
	[PrescriptionId] [uniqueidentifier] NULL,
	[GoodsCode] [varchar](15) NULL,
	[IRCCode] [varchar](20) NULL,
	[CoveredCount] [int] NULL,
	[DeliverCount] [int] NULL DEFAULT ((0)),
	[ShapeCode] [smallint] NULL DEFAULT ((0)),
	[ConsumptionCode] [varchar](20) NULL,
	[ConsumptionInstructionCode] [varchar](20) NULL,
	[NumberOfPeriod] [int] NULL DEFAULT ((0)),
	[Description] [nvarchar](max) NULL,
	[IsOutOfPrescription] [bit] NULL,
	[HasContract] [bit] NULL,
	[BasePrice] [money] NULL,
	[InsurerAmount] [money] NULL DEFAULT ((0)),
	[TotalInsuredAmount] [money] NULL DEFAULT ((0)),
	[TotalInsurerAmount] [money] NULL DEFAULT ((0)),
	[InsurerPercent] [int] NULL DEFAULT ((0)),
	[TotalAmount] [money] NULL DEFAULT ((0)),
	[WarehousePrice] [money] NULL
) ON [PRIMARY] 


ALTER TABLE [dbo].[IHIOPrescriptionDetail]  WITH CHECK ADD  CONSTRAINT [FK_IHIOPrescriptionDetail_IHIOPrescription] FOREIGN KEY([PrescriptionId])
REFERENCES [dbo].[IHIOPrescription] ([Id])
ON DELETE CASCADE


ALTER TABLE [dbo].[IHIOPrescriptionDetail] CHECK CONSTRAINT [FK_IHIOPrescriptionDetail_IHIOPrescription]

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'کد شکل دارو' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'IHIOPrescriptionDetail', @level2type=N'COLUMN',@level2name=N'ShapeCode'
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'کد طريقه مصرف' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'IHIOPrescriptionDetail', @level2type=N'COLUMN',@level2name=N'ConsumptionCode'
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'کد طريقه مصرف شربت' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'IHIOPrescriptionDetail', @level2type=N'COLUMN',@level2name=N'ConsumptionInstructionCode'
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'تعداد در هر نوبت' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'IHIOPrescriptionDetail', @level2type=N'COLUMN',@level2name=N'NumberOfPeriod'
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'توضيحات دارو' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'IHIOPrescriptionDetail', @level2type=N'COLUMN',@level2name=N'Description'
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'نجويز نشده' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'IHIOPrescriptionDetail', @level2type=N'COLUMN',@level2name=N'IsOutOfPrescription'
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'قيمت واحد' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'IHIOPrescriptionDetail', @level2type=N'COLUMN',@level2name=N'BasePrice'
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'سهم بيمه شده' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'IHIOPrescriptionDetail', @level2type=N'COLUMN',@level2name=N'TotalInsuredAmount'
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'سهم سازمان' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'IHIOPrescriptionDetail', @level2type=N'COLUMN',@level2name=N'TotalInsurerAmount'
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'درصد سازمان سلامت' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'IHIOPrescriptionDetail', @level2type=N'COLUMN',@level2name=N'InsurerPercent'
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'مبلغ کل' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'IHIOPrescriptionDetail', @level2type=N'COLUMN',@level2name=N'TotalAmount'
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'قيمت انبار' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'IHIOPrescriptionDetail', @level2type=N'COLUMN',@level2name=N'WarehousePrice'

end