[9602] | 1 | create table [dbo].[ContactInformations] (
|
---|
| 2 | [ContactInformationId] [bigint] not null identity,
|
---|
| 3 | [OrganizationName] [nvarchar](max) null,
|
---|
| 4 | [Street] [nvarchar](max) null,
|
---|
| 5 | [City] [nvarchar](max) null,
|
---|
| 6 | [State] [nvarchar](max) null,
|
---|
| 7 | [PostalCode] [nvarchar](max) null,
|
---|
| 8 | [LastName] [nvarchar](max) null,
|
---|
| 9 | [FirstName] [nvarchar](max) null,
|
---|
| 10 | [Email] [nvarchar](max) null,
|
---|
| 11 | primary key ([ContactInformationId])
|
---|
| 12 | );
|
---|
| 13 | create table [dbo].[Invoices] (
|
---|
| 14 | [InvoiceId] [bigint] not null identity,
|
---|
| 15 | [UserId] [bigint] not null,
|
---|
| 16 | [OrderId] [bigint] not null,
|
---|
[9619] | 17 | [InvoiceDate] [datetime] not null,
|
---|
[9602] | 18 | [Due] [datetime] not null,
|
---|
| 19 | [StatusValue] [int] not null,
|
---|
[9619] | 20 | [Total] [float] not null,
|
---|
| 21 | [Tax] [float] not null,
|
---|
[9602] | 22 | [InvoiceDocument] [nvarchar](max) null,
|
---|
| 23 | primary key ([InvoiceId])
|
---|
| 24 | );
|
---|
| 25 | create table [dbo].[InvoiceLines] (
|
---|
| 26 | [InvoiceLineId] [bigint] not null identity,
|
---|
| 27 | [InvoiceId] [bigint] not null,
|
---|
| 28 | [ProductId] [bigint] not null,
|
---|
| 29 | [Quantity] [int] not null,
|
---|
| 30 | [ProductPrice] [float] not null,
|
---|
| 31 | primary key ([InvoiceLineId])
|
---|
| 32 | );
|
---|
| 33 | create table [dbo].[Orders] (
|
---|
| 34 | [OrderId] [bigint] not null identity,
|
---|
| 35 | [UserId] [bigint] not null,
|
---|
| 36 | [StateValue] [int] not null,
|
---|
| 37 | [BillingTypeValue] [int] not null,
|
---|
| 38 | [BillingPeriodValue] [int] not null,
|
---|
| 39 | [ActiveSince] [datetime] null,
|
---|
| 40 | [ActiveUntil] [datetime] null,
|
---|
[9619] | 41 | [LastBillableDay] [datetime] null,
|
---|
| 42 | [NextBillableDay] [datetime] null,
|
---|
[9602] | 43 | primary key ([OrderId])
|
---|
| 44 | );
|
---|
| 45 | create table [dbo].[OrderLines] (
|
---|
| 46 | [OrderLineId] [bigint] not null identity,
|
---|
| 47 | [OrderId] [bigint] not null,
|
---|
| 48 | [ProductId] [bigint] not null,
|
---|
| 49 | [Quantity] [int] not null,
|
---|
| 50 | [ProductPrice] [float] not null,
|
---|
| 51 | primary key ([OrderLineId])
|
---|
| 52 | );
|
---|
| 53 | create table [dbo].[PaymentInformations] (
|
---|
| 54 | [PaymentInformationId] [bigint] not null identity,
|
---|
| 55 | [UserId] [bigint] not null,
|
---|
| 56 | [CardNumber] [nvarchar](max) null,
|
---|
| 57 | [PaymentMethodValue] [int] not null,
|
---|
| 58 | [AdditionalInformation] [nvarchar](max) null,
|
---|
| 59 | primary key ([PaymentInformationId])
|
---|
| 60 | );
|
---|
| 61 | create table [dbo].[Products] (
|
---|
| 62 | [ProductId] [bigint] not null identity,
|
---|
| 63 | [Name] [nvarchar](max) null,
|
---|
| 64 | [Description] [nvarchar](max) null,
|
---|
| 65 | [ProductType] [nvarchar](max) null,
|
---|
| 66 | [Price] [float] not null,
|
---|
| 67 | primary key ([ProductId])
|
---|
| 68 | );
|
---|
| 69 | create table [dbo].[UsageRecords] (
|
---|
| 70 | [UsageRecordId] [bigint] not null identity,
|
---|
| 71 | [UserId] [bigint] not null,
|
---|
| 72 | [ProductId] [bigint] not null,
|
---|
| 73 | [Begin] [datetime] not null,
|
---|
| 74 | [End] [datetime] not null,
|
---|
| 75 | [ServiceIdentifier] [int] not null,
|
---|
| 76 | [ResourceIdentifier] [int] not null,
|
---|
| 77 | primary key ([UsageRecordId])
|
---|
| 78 | );
|
---|
| 79 | create table [dbo].[Users] (
|
---|
| 80 | [UserId] [bigint] not null identity,
|
---|
[9641] | 81 | [ContactInformationId] [bigint] not null,
|
---|
[9602] | 82 | [Name] [nvarchar](max) null,
|
---|
| 83 | primary key ([UserId])
|
---|
| 84 | );
|
---|
| 85 | alter table [dbo].[Invoices] add constraint [Invoice_Order] foreign key ([OrderId]) references [dbo].[Orders]([OrderId]);
|
---|
| 86 | alter table [dbo].[Invoices] add constraint [Invoice_User] foreign key ([UserId]) references [dbo].[Users]([UserId]);
|
---|
| 87 | alter table [dbo].[InvoiceLines] add constraint [InvoiceLine_Invoice] foreign key ([InvoiceId]) references [dbo].[Invoices]([InvoiceId]) on delete cascade;
|
---|
| 88 | alter table [dbo].[InvoiceLines] add constraint [InvoiceLine_Product] foreign key ([ProductId]) references [dbo].[Products]([ProductId]);
|
---|
| 89 | alter table [dbo].[Orders] add constraint [Order_User] foreign key ([UserId]) references [dbo].[Users]([UserId]);
|
---|
| 90 | alter table [dbo].[OrderLines] add constraint [OrderLine_Order] foreign key ([OrderId]) references [dbo].[Orders]([OrderId]) on delete cascade;
|
---|
| 91 | alter table [dbo].[OrderLines] add constraint [OrderLine_Product] foreign key ([ProductId]) references [dbo].[Products]([ProductId]);
|
---|
| 92 | alter table [dbo].[UsageRecords] add constraint [UsageRecord_Product] foreign key ([ProductId]) references [dbo].[Products]([ProductId]);
|
---|
| 93 | alter table [dbo].[UsageRecords] add constraint [UsageRecord_User] foreign key ([UserId]) references [dbo].[Users]([UserId]);
|
---|
[9641] | 94 | alter table [dbo].[Users] add constraint [User_ContactInformation] foreign key ([ContactInformationId]) references [dbo].[ContactInformations]([ContactInformationId]);
|
---|
[9602] | 95 | alter table [dbo].[PaymentInformations] add constraint [User_PaymentInformation] foreign key ([UserId]) references [dbo].[Users]([UserId]);
|
---|