CREATE TABLE [dbo].[Storage]
(
[StoragePriKey] [int] NOT NULL IDENTITY(1, 1),
[OrdPriKey] [int] NOT NULL,
[DateStorageIn] [datetime] NULL,
[DateStorageOut] [datetime] NULL,
[DateScheduledOut] [datetime] NULL,
[BeginBillingDate] [datetime] NULL,
[AuthorityPriKey] [int] NOT NULL,
[BillingCyclePriKey] [int] NOT NULL,
[StorageTypePriKey] [int] NOT NULL,
[RPPriKey] [int] NULL,
[ABTPriKey] [int] NULL,
[ANPriKey] [int] NULL,
[IsInvoiced] [bit] NOT NULL,
[LastBillDateFrom] [datetime] NULL,
[LastBillDateTo] [datetime] NULL,
[NextBillDate] [datetime] NULL,
[StorageCoordinator] [int] NULL,
[RecordName] [varchar] (64) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[EmailAddresses] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[InstrumentFID] [int] NULL,
[UseOnlinePayment] [bit] NOT NULL CONSTRAINT [DF_Storage_UseOnlinePayment] DEFAULT ((0)),
[EmailInvoice] [bit] NOT NULL CONSTRAINT [DF_Storage_EmailInvoice] DEFAULT ((0)),
[EmailAutoPayReceipt] [bit] NOT NULL CONSTRAINT [DF_Storage_EmailAutoPayReceipt] DEFAULT ((0)),
[FirstRecurringTransInstrumentFID] [int] NULL,
[FirstRecurringTransId] [nvarchar] (64) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[Storage] ADD CONSTRAINT [PK_Storage] PRIMARY KEY NONCLUSTERED ([StoragePriKey]) WITH (FILLFACTOR=80) ON [PRIMARY]
GO
ALTER TABLE [dbo].[Storage] ADD CONSTRAINT [IX_Unique_OrderID_RecordName] UNIQUE NONCLUSTERED ([OrdPriKey], [RecordName]) WITH (FILLFACTOR=80) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_Storage_Order] ON [dbo].[Storage] ([OrdPriKey]) WITH (FILLFACTOR=80) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_Storage_RPPriKey] ON [dbo].[Storage] ([RPPriKey]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_Storage_StorageCoordinator] ON [dbo].[Storage] ([StorageCoordinator]) ON [PRIMARY]
GO
ALTER TABLE [dbo].[Storage] ADD CONSTRAINT [FK_Storage_AlternateBillTo] FOREIGN KEY ([ABTPriKey]) REFERENCES [dbo].[AlternateBillTo] ([ABTPriKey])
GO
ALTER TABLE [dbo].[Storage] ADD CONSTRAINT [FK_Storage_AccountingNote] FOREIGN KEY ([ANPriKey]) REFERENCES [dbo].[AccountingNote] ([ANPriKey])
GO
ALTER TABLE [dbo].[Storage] ADD CONSTRAINT [FK_Storage_AuthorityTypes] FOREIGN KEY ([AuthorityPriKey]) REFERENCES [dbo].[AuthorityTypes] ([AuthPriKey])
GO
ALTER TABLE [dbo].[Storage] ADD CONSTRAINT [FK_Storage_StorageBillingCycleType] FOREIGN KEY ([BillingCyclePriKey]) REFERENCES [dbo].[StorageBillingCycleType] ([BillingCyclePriKey])
GO
ALTER TABLE [dbo].[Storage] ADD CONSTRAINT [FK_Storage_FirstRecurringTransInstrument] FOREIGN KEY ([FirstRecurringTransInstrumentFID]) REFERENCES [dbo].[PlasticInstrument] ([InstrumentID])
GO
ALTER TABLE [dbo].[Storage] ADD CONSTRAINT [FK_Storage_Instrument] FOREIGN KEY ([InstrumentFID]) REFERENCES [dbo].[PlasticInstrument] ([InstrumentID])
GO
ALTER TABLE [dbo].[Storage] ADD CONSTRAINT [FK_Storage_Orders] FOREIGN KEY ([OrdPriKey]) REFERENCES [dbo].[Orders] ([PriKey])
GO
ALTER TABLE [dbo].[Storage] ADD CONSTRAINT [FK_Storage_RatePlans] FOREIGN KEY ([RPPriKey]) REFERENCES [dbo].[RatePlans] ([RPPriKey])
GO
ALTER TABLE [dbo].[Storage] ADD CONSTRAINT [FK_Storage_Sysuser] FOREIGN KEY ([StorageCoordinator]) REFERENCES [dbo].[Sysuser] ([SysUserID])
GO
ALTER TABLE [dbo].[Storage] ADD CONSTRAINT [FK_Storage_StorageType] FOREIGN KEY ([StorageTypePriKey]) REFERENCES [dbo].[StorageType] ([StorageTypePriKey])
GO
GRANT SELECT ON [dbo].[Storage] TO [MssExec]
GRANT INSERT ON [dbo].[Storage] TO [MssExec]
GRANT DELETE ON [dbo].[Storage] TO [MssExec]
GRANT UPDATE ON [dbo].[Storage] TO [MssExec]
GO
EXEC sp_addextendedproperty N'MS_Description', N'Foreign key to an alternate billing customer.', 'SCHEMA', N'dbo', 'TABLE', N'Storage', 'COLUMN', N'ABTPriKey'
GO
EXEC sp_addextendedproperty N'MS_Description', N'Foriegn key to an accounting note.', 'SCHEMA', N'dbo', 'TABLE', N'Storage', 'COLUMN', N'ANPriKey'
GO
EXEC sp_addextendedproperty N'MS_Description', N'Foreign key to an authority.', 'SCHEMA', N'dbo', 'TABLE', N'Storage', 'COLUMN', N'AuthorityPriKey'
GO
EXEC sp_addextendedproperty N'MS_Description', N'Date the order starts billing.', 'SCHEMA', N'dbo', 'TABLE', N'Storage', 'COLUMN', N'BeginBillingDate'
GO
EXEC sp_addextendedproperty N'MS_Description', N'Foreign key to a billing cycle.', 'SCHEMA', N'dbo', 'TABLE', N'Storage', 'COLUMN', N'BillingCyclePriKey'
GO
EXEC sp_addextendedproperty N'MS_Description', N'Date the order is scheduled to move out of storage.', 'SCHEMA', N'dbo', 'TABLE', N'Storage', 'COLUMN', N'DateScheduledOut'
GO
EXEC sp_addextendedproperty N'MS_Description', N'Date the order moved into storage.', 'SCHEMA', N'dbo', 'TABLE', N'Storage', 'COLUMN', N'DateStorageIn'
GO
EXEC sp_addextendedproperty N'MS_Description', N'Date the order moved out of storage.', 'SCHEMA', N'dbo', 'TABLE', N'Storage', 'COLUMN', N'DateStorageOut'
GO
EXEC sp_addextendedproperty N'MS_Description', N'0 if the order does not produce a storage invoice. 1 if it does produce a storage invoice.', 'SCHEMA', N'dbo', 'TABLE', N'Storage', 'COLUMN', N'IsInvoiced'
GO
EXEC sp_addextendedproperty N'MS_Description', N'The last starting date the order was billed.', 'SCHEMA', N'dbo', 'TABLE', N'Storage', 'COLUMN', N'LastBillDateFrom'
GO
EXEC sp_addextendedproperty N'MS_Description', N'The last ending date the order was billed.', 'SCHEMA', N'dbo', 'TABLE', N'Storage', 'COLUMN', N'LastBillDateTo'
GO
EXEC sp_addextendedproperty N'MS_Description', N'The date the order is going to be billed next.', 'SCHEMA', N'dbo', 'TABLE', N'Storage', 'COLUMN', N'NextBillDate'
GO
EXEC sp_addextendedproperty N'MS_Description', N'Foreign key to an order.', 'SCHEMA', N'dbo', 'TABLE', N'Storage', 'COLUMN', N'OrdPriKey'
GO
EXEC sp_addextendedproperty N'MS_Description', N'Foreign key to a rate plan.', 'SCHEMA', N'dbo', 'TABLE', N'Storage', 'COLUMN', N'RPPriKey'
GO
EXEC sp_addextendedproperty N'MS_Description', N'Foreign key to the storage coordinator.', 'SCHEMA', N'dbo', 'TABLE', N'Storage', 'COLUMN', N'StorageCoordinator'
GO
EXEC sp_addextendedproperty N'MS_Description', N'Primary key.', 'SCHEMA', N'dbo', 'TABLE', N'Storage', 'COLUMN', N'StoragePriKey'
GO
EXEC sp_addextendedproperty N'MS_Description', N'Foreign key to a storage type.', 'SCHEMA', N'dbo', 'TABLE', N'Storage', 'COLUMN', N'StorageTypePriKey'
GO