CREATE TABLE [dbo].[XmlItemCode]
(
[XmlItemCodeID] [int] NOT NULL IDENTITY(1, 1),
[XmlInterfaceFID] [int] NOT NULL,
[XmlItemCode] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[TransportationFlag] [bit] NOT NULL CONSTRAINT [DF_XmlItemCode_TransportationFlag] DEFAULT ((0)),
[ItemCodeFID] [int] NULL,
[MaterialTypeFID] [int] NULL
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[XmlItemCode] ADD CONSTRAINT [CK_XmlItemCode_ItemCode_MaterialType] CHECK (([ItemCodeFID] IS NOT NULL AND [MaterialTypeFID] IS NULL OR [ItemCodeFID] IS NULL AND [MaterialTypeFID] IS NOT NULL))
GO
ALTER TABLE [dbo].[XmlItemCode] ADD CONSTRAINT [PK_XmlItemCode] PRIMARY KEY CLUSTERED ([XmlItemCodeID]) WITH (FILLFACTOR=80) ON [PRIMARY]
GO
ALTER TABLE [dbo].[XmlItemCode] ADD CONSTRAINT [IX_Unique_XmlItemCode_XmlInterface] UNIQUE NONCLUSTERED ([XmlItemCode], [XmlInterfaceFID]) WITH (FILLFACTOR=80) ON [PRIMARY]
GO
ALTER TABLE [dbo].[XmlItemCode] ADD CONSTRAINT [FK_XmlItemCode_ItemCode] FOREIGN KEY ([ItemCodeFID]) REFERENCES [dbo].[ItemCode] ([ICPriKey])
GO
ALTER TABLE [dbo].[XmlItemCode] ADD CONSTRAINT [FK_XmlItemCode_MaterialType] FOREIGN KEY ([MaterialTypeFID]) REFERENCES [dbo].[MaterialType] ([MaterialTypeID])
GO
ALTER TABLE [dbo].[XmlItemCode] ADD CONSTRAINT [FK_XmlItemCode_XmlInterface] FOREIGN KEY ([XmlInterfaceFID]) REFERENCES [dbo].[XmlInterface] ([XmlInterfaceID])
GO
GRANT SELECT ON [dbo].[XmlItemCode] TO [MssExec]
GRANT INSERT ON [dbo].[XmlItemCode] TO [MssExec]
GRANT DELETE ON [dbo].[XmlItemCode] TO [MssExec]
GRANT UPDATE ON [dbo].[XmlItemCode] TO [MssExec]
GO
EXEC sp_addextendedproperty N'MS_Description', N'Indicates if the item is transportation. 0 for no, 1 for yes.', 'SCHEMA', N'dbo', 'TABLE', N'XmlItemCode', 'COLUMN', N'TransportationFlag'
GO
EXEC sp_addextendedproperty N'MS_Description', N'Foreign key to an xml interface.', 'SCHEMA', N'dbo', 'TABLE', N'XmlItemCode', 'COLUMN', N'XmlInterfaceFID'
GO
EXEC sp_addextendedproperty N'MS_Description', N'Item code for the xml interface.', 'SCHEMA', N'dbo', 'TABLE', N'XmlItemCode', 'COLUMN', N'XmlItemCode'
GO
EXEC sp_addextendedproperty N'MS_Description', N'The primary key.', 'SCHEMA', N'dbo', 'TABLE', N'XmlItemCode', 'COLUMN', N'XmlItemCodeID'
GO