CREATE TABLE [dbo].[QuoteDetail]
(
[QuoteDetailID] [int] NOT NULL IDENTITY(1, 1),
[QuoteGroupFID] [int] NOT NULL,
[ItemCodeFID] [int] NULL,
[RateTypeFID] [int] NULL,
[Description] [varchar] (128) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[Rate] [money] NULL,
[Quantity] [decimal] (10, 4) NULL,
[Quantity2] [decimal] (10, 4) NULL,
[Charge] [money] NULL,
[QuoteServiceProviderTypeFID] [int] NULL,
[VendorID] [varchar] (15) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[VendorQuotedCharge] [money] NULL,
[VendorActualCharge] [money] NULL,
[Hidden] [bit] NOT NULL CONSTRAINT [DF_QuoteDetail_Hidden] DEFAULT ((0)),
[SortOrder] [int] NULL,
[PONumber] [varchar] (20) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[InvoiceNumber] [varchar] (20) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[ServiceDate] [datetime] NULL,
[NoteText] [varchar] (1024) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[LaborRatingTypeFID] [int] NULL,
[QuoteServiceProviderBillToFID] [int] NULL,
[RateSource] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[RateSourceRecord] [int] NULL,
[CurrentRowVersion] [timestamp] NOT NULL,
[ExternalVendorID] [varchar] (15) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[ExternalVendorName] [varchar] (40) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[IsLocked] [bit] NOT NULL CONSTRAINT [DF_QuoteDetail_IsLocked] DEFAULT ((0))
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[QuoteDetail] ADD CONSTRAINT [CK_QuoteDetail_ServiceProvider_Agent] CHECK (([QuoteServiceProviderTypeFID] IS NULL AND [VendorID] IS NULL OR [QuoteServiceProviderTypeFID] IS NULL AND [VendorID] IS NOT NULL OR [QuoteServiceProviderTypeFID] IS NOT NULL AND [VendorID] IS NULL))
GO
ALTER TABLE [dbo].[QuoteDetail] ADD CONSTRAINT [PK_QuoteDetail] PRIMARY KEY NONCLUSTERED ([QuoteDetailID]) WITH (FILLFACTOR=80) ON [PRIMARY]
GO
CREATE UNIQUE NONCLUSTERED INDEX [IX_QuoteDetail_QuoteGroup] ON [dbo].[QuoteDetail] ([QuoteGroupFID], [QuoteDetailID]) ON [PRIMARY]
GO
ALTER TABLE [dbo].[QuoteDetail] ADD CONSTRAINT [FK_QuoteDetail_ItemCode] FOREIGN KEY ([ItemCodeFID]) REFERENCES [dbo].[ItemCode] ([ICPriKey])
GO
ALTER TABLE [dbo].[QuoteDetail] ADD CONSTRAINT [FK_QuoteDetail_LaborRatingTypeFID] FOREIGN KEY ([LaborRatingTypeFID]) REFERENCES [dbo].[LaborRatingType] ([LaborRatingTypeID])
GO
ALTER TABLE [dbo].[QuoteDetail] ADD CONSTRAINT [FK_QuoteDetail_QuoteGroup] FOREIGN KEY ([QuoteGroupFID]) REFERENCES [dbo].[QuoteGroup] ([QuoteGroupID]) ON DELETE CASCADE
GO
ALTER TABLE [dbo].[QuoteDetail] ADD CONSTRAINT [FK_QuoteDetail_QuoteServiceProviderBillToFID] FOREIGN KEY ([QuoteServiceProviderBillToFID]) REFERENCES [dbo].[QuoteServiceProviderBillTo] ([QuoteServiceProviderBillToID])
GO
ALTER TABLE [dbo].[QuoteDetail] ADD CONSTRAINT [FK_QuoteDetail_QuoteServiceProviderType] FOREIGN KEY ([QuoteServiceProviderTypeFID]) REFERENCES [dbo].[QuoteServiceProviderType] ([QuoteServiceProviderTypeID])
GO
ALTER TABLE [dbo].[QuoteDetail] ADD CONSTRAINT [FK_QuoteDetail_RateType] FOREIGN KEY ([RateTypeFID]) REFERENCES [dbo].[RateTypes] ([RTypePriKey])
GO
GRANT SELECT ON [dbo].[QuoteDetail] TO [MssExec]
GRANT INSERT ON [dbo].[QuoteDetail] TO [MssExec]
GRANT DELETE ON [dbo].[QuoteDetail] TO [MssExec]
GRANT UPDATE ON [dbo].[QuoteDetail] TO [MssExec]
GO