-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcarrenting.sql
53 lines (47 loc) · 2.07 KB
/
carrenting.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
CREATE TABLE [dbo].[Brands] (
[BrandId] INT IDENTITY (1, 1) NOT NULL,
[BrandName] VARCHAR (50) NOT NULL,
CONSTRAINT [PK_Brands] PRIMARY KEY CLUSTERED ([BrandId] ASC)
);
CREATE TABLE [dbo].[Colors] (
[ColorId] INT IDENTITY (1, 1) NOT NULL,
[ColorName] VARCHAR (50) NOT NULL,
CONSTRAINT [PK_Colors] PRIMARY KEY CLUSTERED ([ColorId] ASC)
);
CREATE TABLE [dbo].[Cars] (
[CarId] INT IDENTITY (1, 1) NOT NULL,
[BrandId] INT NOT NULL,
[ColorId] INT NOT NULL,
[CarName] VARCHAR (50) NOT NULL,
[DailyPrice] DECIMAL (18) NOT NULL,
[ModelYear] VARCHAR (50) NOT NULL,
[Description] VARCHAR (250) NULL,
CONSTRAINT [PK_Cars] PRIMARY KEY CLUSTERED ([CarId] ASC),
CONSTRAINT [FK_Cars_Colors] FOREIGN KEY ([ColorId]) REFERENCES [dbo].[Colors] ([ColorId]),
CONSTRAINT [FK_Cars_Brands] FOREIGN KEY ([BrandId]) REFERENCES [dbo].[Brands] ([BrandId])
);
CREATE TABLE [dbo].[Customers] (
[CustomerId] INT IDENTITY (1, 1) NOT NULL,
[UserId] INT NOT NULL,
[CompanyName] VARCHAR (255) NOT NULL,
CONSTRAINT [PK_Customers] PRIMARY KEY CLUSTERED ([CustomerId] ASC),
CONSTRAINT [FK_Customers_Users] FOREIGN KEY ([UserId]) REFERENCES [dbo].[Users] ([Id])
);
CREATE TABLE [dbo].[Users] (
[Id] INT IDENTITY (1, 1) NOT NULL,
[FirstName] VARCHAR (50) NOT NULL,
[LastName] VARCHAR (50) NOT NULL,
[Email] VARCHAR (255) NOT NULL,
[Password] VARCHAR (255) NOT NULL,
CONSTRAINT [PK_Users] PRIMARY KEY CLUSTERED ([Id] ASC)
);
CREATE TABLE [dbo].[Rentals] (
[RentalId] INT IDENTITY (1, 1) NOT NULL,
[CarId] INT NOT NULL,
[CustomerId] INT NOT NULL,
[RentDate] DATETIME NULL,
[ReturnDate] DATETIME NULL,
CONSTRAINT [PK_Rentals] PRIMARY KEY CLUSTERED ([RentalId] ASC),
CONSTRAINT [FK_Rentals_Customers] FOREIGN KEY ([CustomerId]) REFERENCES [dbo].[Customers] ([CustomerId]),
CONSTRAINT [FK_Rentals_Cars] FOREIGN KEY ([CarId]) REFERENCES [dbo].[Cars] ([CarId])
);