IF OBJECT_ID(N'[dbo].[Prc_T_MaterialRequestItem]', 'U') IS NULL BEGIN CREATE TABLE [dbo].[Prc_T_MaterialRequestItem] ( [Id] uniqueidentifier NOT NULL DEFAULT NEWID(), [TenantId] uniqueidentifier NULL, [MaterialRequestId] uniqueidentifier NOT NULL, [ProductId] uniqueidentifier NOT NULL, [Quantity] decimal(18, 4) NOT NULL, [UomId] nvarchar(64) NOT NULL, [FulfillmentMethod] nvarchar(16) NOT NULL DEFAULT 'Purchase', [DueDate] date NOT NULL, [RequestReason] nvarchar(256) NOT NULL, [DeliveredQuantity] decimal(18, 4) NOT NULL DEFAULT 0, [PlannedQuantity] decimal(18, 4) NULL, [PurchaseResponsibleUserId] uniqueidentifier NULL, [LineStatus] nvarchar(16) NOT NULL DEFAULT 'Waiting', [CreationTime] datetime2 NOT NULL DEFAULT GETUTCDATE(), [CreatorId] uniqueidentifier NULL, [LastModificationTime] datetime2 NULL, [LastModifierId] uniqueidentifier NULL, [IsDeleted] bit NOT NULL DEFAULT 0, [DeletionTime] datetime2 NULL, [DeleterId] uniqueidentifier NULL, CONSTRAINT [PK_Prc_T_MaterialRequestItem] PRIMARY KEY NONCLUSTERED ( [Id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY] ) ON [PRIMARY] END GO IF INDEXPROPERTY(OBJECT_ID(N'[dbo].[Prc_T_MaterialRequestItem]'), 'IX_Prc_T_MaterialRequestItem_MaterialRequestId', 'IndexID') IS NULL BEGIN CREATE INDEX [IX_Prc_T_MaterialRequestItem_MaterialRequestId] ON [dbo].[Prc_T_MaterialRequestItem] ([MaterialRequestId] ASC); END GO IF OBJECT_ID(N'[dbo].[FK_Prc_T_MaterialRequestItem_MaterialRequestId]', 'F') IS NULL BEGIN ALTER TABLE [dbo].[Prc_T_MaterialRequestItem] ADD CONSTRAINT [FK_Prc_T_MaterialRequestItem_MaterialRequestId] FOREIGN KEY ([MaterialRequestId]) REFERENCES [dbo].[Prc_T_MaterialRequest] ([Id]) ON DELETE CASCADE ON UPDATE NO ACTION; END GO