[dbo].[MaterialItemCodeMap]
CREATE TABLE [dbo].[MaterialItemCodeMap]
(
[MaterialItemCodeMapID] [int] NOT NULL IDENTITY(1, 1),
[MaterialTypeFID] [int] NOT NULL,
[MaterialCPUTypeFID] [int] NOT NULL,
[ItemCodeFID] [int] NOT NULL
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[MaterialItemCodeMap] ADD CONSTRAINT [PK_MaterialItemCodeMap] PRIMARY KEY CLUSTERED ([MaterialItemCodeMapID]) WITH (FILLFACTOR=80) ON [PRIMARY]
GO
ALTER TABLE [dbo].[MaterialItemCodeMap] ADD CONSTRAINT [IX_MaterialItemCodeMap_Type_CPUType] UNIQUE NONCLUSTERED ([MaterialTypeFID], [MaterialCPUTypeFID]) WITH (FILLFACTOR=80) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_MaterialItemCodeMap_ItemCode] ON [dbo].[MaterialItemCodeMap] ([ItemCodeFID]) WITH (FILLFACTOR=80) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_MaterialItemCodeMap_MaterialCPUType] ON [dbo].[MaterialItemCodeMap] ([MaterialCPUTypeFID], [MaterialTypeFID]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_MaterialItemCodeMap_MaterialType] ON [dbo].[MaterialItemCodeMap] ([MaterialTypeFID], [MaterialCPUTypeFID]) ON [PRIMARY]
GO
ALTER TABLE [dbo].[MaterialItemCodeMap] ADD CONSTRAINT [FK_MaterialItemCodeMap_ItemCode] FOREIGN KEY ([ItemCodeFID]) REFERENCES [dbo].[ItemCode] ([ICPriKey])
GO
ALTER TABLE [dbo].[MaterialItemCodeMap] ADD CONSTRAINT [FK_MaterialItemCodeMap_MaterialCPUType] FOREIGN KEY ([MaterialCPUTypeFID]) REFERENCES [dbo].[MaterialCPUType] ([MaterialCPUTypeID])
GO
ALTER TABLE [dbo].[MaterialItemCodeMap] ADD CONSTRAINT [FK_MaterialItemCodeMap_MaterialType] FOREIGN KEY ([MaterialTypeFID]) REFERENCES [dbo].[MaterialType] ([MaterialTypeID]) ON DELETE CASCADE
GO
GRANT SELECT ON [dbo].[MaterialItemCodeMap] TO [MssExec]
GRANT INSERT ON [dbo].[MaterialItemCodeMap] TO [MssExec]
GRANT DELETE ON [dbo].[MaterialItemCodeMap] TO [MssExec]
GRANT UPDATE ON [dbo].[MaterialItemCodeMap] TO [MssExec]
GO