CREATE TABLE [dbo].[OrdMaterial]
(
[OMPriKey] [int] NOT NULL IDENTITY(1, 1),
[ORDPriKey] [int] NULL,
[EstQuantity] [int] NULL,
[MaterialItemCodeMapFID] [int] NULL
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[OrdMaterial] ADD CONSTRAINT [PK_OrdMaterial] PRIMARY KEY CLUSTERED ([OMPriKey]) WITH (FILLFACTOR=80) ON [PRIMARY]
GO
ALTER TABLE [dbo].[OrdMaterial] ADD CONSTRAINT [IX_OrdMaterial_Order_MaterialItemCodeMap] UNIQUE NONCLUSTERED ([ORDPriKey], [MaterialItemCodeMapFID]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_OrdMaterial_MaterialItemCodeMap] ON [dbo].[OrdMaterial] ([MaterialItemCodeMapFID]) WITH (FILLFACTOR=80) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_OrdMaterial_OrdPriKey] ON [dbo].[OrdMaterial] ([ORDPriKey]) WITH (FILLFACTOR=80) ON [PRIMARY]
GO
ALTER TABLE [dbo].[OrdMaterial] ADD CONSTRAINT [FK_OrdMaterial_MaterialItemCodeMap] FOREIGN KEY ([MaterialItemCodeMapFID]) REFERENCES [dbo].[MaterialItemCodeMap] ([MaterialItemCodeMapID])
GO
ALTER TABLE [dbo].[OrdMaterial] ADD CONSTRAINT [FK_OrdMaterial_ORDERS] FOREIGN KEY ([ORDPriKey]) REFERENCES [dbo].[Orders] ([PriKey])
GO
GRANT SELECT ON [dbo].[OrdMaterial] TO [MssExec]
GRANT INSERT ON [dbo].[OrdMaterial] TO [MssExec]
GRANT DELETE ON [dbo].[OrdMaterial] TO [MssExec]
GRANT UPDATE ON [dbo].[OrdMaterial] TO [MssExec]
GO