IF Not (EXISTS(SELECT * FROM sysobjects WHERE name='TaminPrescriptionDetail'))
Begin
CREATE TABLE [dbo].[TaminPrescriptionDetail](
	[Id] [uniqueidentifier] NOT NULL,
	[PrescriptionId] [uniqueidentifier] NULL,
	[RowIndex] [smallint] NULL,
	[GoodsCode] [varchar](15) NULL,
	[GenericCode] [varchar](5) NULL,
	[Form] [varchar](30) NULL,
	[Instruction] [nvarchar](max) NULL,
	[IsOutOfPrescription] [bit] NULL,
	[DeliverCount] [int] NULL,
	[MaxCoveredCount] [int] NULL,
	[AvailableCount] [int] NULL,
	[MaxDrugPrice] [money] NULL,
	[InsurerCeilingAmount] [money] NULL,
	[RequestedAmount] [money] NULL,
	[InsurerAmount] [money] NULL,
	[InsuredAmount] [money] NULL,
	[DifferenceAmount] [money] NULL,
	[Franshiz] [float] NULL,
	[DrugPrice] [money] NULL,
 CONSTRAINT [PK_TaminPrescriptionDetail_Id] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)
) ON [PRIMARY] 

ALTER TABLE [dbo].[TaminPrescriptionDetail] ADD  CONSTRAINT [DF_TaminPrescriptionDetail_Id]  DEFAULT (newid()) FOR [Id]
  ALTER TABLE dbo.TaminPrescriptionDetail ADD CONSTRAINT FK_TaminPrescriptionDetail_TaminPrescription
    FOREIGN KEY (PrescriptionId) REFERENCES dbo.TaminPrescription (Id) ON DELETE CASCADE;
ALTER TABLE [dbo].[TaminPrescriptionDetail] CHECK CONSTRAINT [FK_TaminPrescriptionDetail_TaminPrescription]
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Id هدر' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'TaminPrescriptionDetail', @level2type=N'COLUMN',@level2name=N'PrescriptionId'
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'رديف' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'TaminPrescriptionDetail', @level2type=N'COLUMN',@level2name=N'RowIndex'
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'کد اصلي' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'TaminPrescriptionDetail', @level2type=N'COLUMN',@level2name=N'GoodsCode'
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'کد ژنريک' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'TaminPrescriptionDetail', @level2type=N'COLUMN',@level2name=N'GenericCode'
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'شکل دارو' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'TaminPrescriptionDetail', @level2type=N'COLUMN',@level2name=N'Form'
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'دستور مصرف' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'TaminPrescriptionDetail', @level2type=N'COLUMN',@level2name=N'Instruction'
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'داروي آزاد' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'TaminPrescriptionDetail', @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'TaminPrescriptionDetail', @level2type=N'COLUMN',@level2name=N'DeliverCount'
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'تعداد تحت پوشش' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'TaminPrescriptionDetail', @level2type=N'COLUMN',@level2name=N'MaxCoveredCount'
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'کل تحت پوشش در دوره' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'TaminPrescriptionDetail', @level2type=N'COLUMN',@level2name=N'AvailableCount'
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'حداکثر قيمت دارو' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'TaminPrescriptionDetail', @level2type=N'COLUMN',@level2name=N'MaxDrugPrice'
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'مبلغ سهم سازمان' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'TaminPrescriptionDetail', @level2type=N'COLUMN',@level2name=N'InsurerCeilingAmount'
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'مبلغ درخواستي داروخانه' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'TaminPrescriptionDetail', @level2type=N'COLUMN',@level2name=N'RequestedAmount'
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'جمع مبلغ سازمان' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'TaminPrescriptionDetail', @level2type=N'COLUMN',@level2name=N'InsurerAmount'
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'جمع مبلغ بيمار' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'TaminPrescriptionDetail', @level2type=N'COLUMN',@level2name=N'InsuredAmount'
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'اختلاف قيمت' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'TaminPrescriptionDetail', @level2type=N'COLUMN',@level2name=N'DifferenceAmount'
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'فرانشيز سازمان' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'TaminPrescriptionDetail', @level2type=N'COLUMN',@level2name=N'Franshiz'
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'قيمت در  داروخانه' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'TaminPrescriptionDetail', @level2type=N'COLUMN',@level2name=N'DrugPrice'
End