-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReCapProjectDB.sql
96 lines (83 loc) · 3.37 KB
/
ReCapProjectDB.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
CREATE DATABASE reCapDatabase;
USE reCapDatabase
CREATE TABLE [dbo].[Brands] (
[Id] INT IDENTITY (1, 1) NOT NULL,
[Name] NVARCHAR (25) NOT NULL,
PRIMARY KEY CLUSTERED ([Id] ASC)
);
CREATE TABLE [dbo].[Colors] (
[Id] INT IDENTITY (1, 1) NOT NULL,
[Name] NVARCHAR (25) NOT NULL,
PRIMARY KEY CLUSTERED ([Id] ASC)
);
CREATE TABLE [dbo].[Models] (
[Id] INT IDENTITY (1, 1) NOT NULL,
[BrandId] INT NOT NULL,
[Name] NVARCHAR (30) NOT NULL,
PRIMARY KEY CLUSTERED ([Id] ASC),
CONSTRAINT [FK_Colors_Brands] FOREIGN KEY ([BrandId]) REFERENCES [dbo].[Brands] ([Id])
);
CREATE TABLE [dbo].[Cars] (
[Id] INT IDENTITY (1, 1) NOT NULL,
[ModelId] INT NOT NULL,
[BrandId] INT NOT NULL,
[ColorId] INT NOT NULL,
[DailyPrice] DECIMAL (18) NOT NULL,
[ModelYear] SMALLINT NOT NULL,
[Description] NVARCHAR (50) NULL,
[FindeksScore] INT NULL,
PRIMARY KEY CLUSTERED ([Id] ASC),
CONSTRAINT [FK_Cars_Brands] FOREIGN KEY ([BrandId]) REFERENCES [dbo].[Brands] ([Id]),
CONSTRAINT [FK_Cars_Colors] FOREIGN KEY ([ColorId]) REFERENCES [dbo].[Colors] ([Id]),
CONSTRAINT [FK_Cars_Models] FOREIGN KEY ([ModelId]) REFERENCES [dbo].[Models] ([Id])
);
CREATE TABLE [dbo].[Users] (
[Id] INT IDENTITY (1, 1) NOT NULL,
[FirstName] NVARCHAR (50) NOT NULL,
[LastName] NVARCHAR (50) NOT NULL,
[Email] NVARCHAR (50) NOT NULL,
[PasswordHash] VARBINARY(500) NOT NULL,
[PasswordSalt] VARBINARY(500) NOT NULL,
[Status] BIT NOT NULL,
[Age] DATETIME NULL,
PRIMARY KEY CLUSTERED ([Id] ASC)
);
CREATE TABLE [dbo].[Customers] (
[Id] INT IDENTITY (1, 1) NOT NULL,
[UserId] INT NOT NULL,
[CompanyName] NVARCHAR (50) NULL,
[FindeksScore] INT NULL,
PRIMARY KEY CLUSTERED ([Id] ASC),
CONSTRAINT [FK_Customers_Users] FOREIGN KEY ([UserId]) REFERENCES [dbo].[Users] ([Id])
);
CREATE TABLE [dbo].[Rentals] (
[Id] INT IDENTITY (1, 1) NOT NULL,
[CarId] INT NOT NULL,
[CustomerId] INT NOT NULL,
[RentDate] DATETIME NULL,
[ReturnDate] DATETIME NULL,
PRIMARY KEY CLUSTERED ([Id] ASC),
CONSTRAINT [FK_Rentals_Cars] FOREIGN KEY ([CarId]) REFERENCES [dbo].[Cars] ([Id]),
CONSTRAINT [FK_Rentals_Customers] FOREIGN KEY ([CustomerId]) REFERENCES [dbo].[Customers] ([Id])
);
CREATE TABLE [dbo].[CarImages] (
[Id] INT NOT NULL IDENTITY,
[CarId] INT NOT NULL,
[ImagePath] NVARCHAR (MAX) NOT NULL,
[Date] DATETIME NOT NULL,
PRIMARY KEY CLUSTERED ([Id] ASC),
CONSTRAINT [FK_CarImages_Cars] FOREIGN KEY ([CarId]) REFERENCES [dbo].[Cars] ([Id])
);
CREATE TABLE [dbo].[OperationClaims] (
[Id] INT IDENTITY (1, 1) NOT NULL,
[Name] VARCHAR (250) NOT NULL,
PRIMARY KEY CLUSTERED ([Id] ASC)
);
CREATE TABLE [dbo].[UserOperationClaims] (
[Id] INT IDENTITY (1, 1) NOT NULL,
[UserId] INT NOT NULL,
[OperationClaimId] INT NOT NULL,
PRIMARY KEY CLUSTERED ([Id] ASC),
CONSTRAINT [FK_UserOperationClaims_Users] FOREIGN KEY ([UserId]) REFERENCES [dbo].[Users] ([Id]),
CONSTRAINT [FK_UserOperationClaims_OperationClaims] FOREIGN KEY ([OperationClaimId]) REFERENCES [dbo].[OperationClaims] ([Id])
);