-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cars.sql
60 lines (51 loc) · 1.67 KB
/
Cars.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
/*
CREATE TABLE dbo.Cars(
Id INT NOT NULL PRIMARY KEY identity,
LicencePlate varchar(10) NOT NULL unique,
Year INT NOT NULL,
DateFabrication DATETIME NOT NULL,
New BIT NOT NULL,
Transmissions BIT NOT NULL,
ModelId INT NOT NULL
)
GO
CREATE TABLE dbo.Brands(
Id INT NOT NULL PRIMARY KEY identity,
Name varchar(50) NOT NULL
)
GO
CREATE TABLE dbo.Models(
Id INT NOT NULL PRIMARY KEY identity,
Name varchar(50) NOT NULL,
BrandId INT NOT NULL
)
GO
*/
ALTER TABLE Models add foreign key(BrandId) references Brands(Id);
ALTER TABLE Cars add foreign key(ModelId) references Models(Id);
SET IDENTITY_INSERT dbo.Brands ON
INSERT dbo.Brands (Id, Name) VALUES (1, 'Toyota')
INSERT dbo.Brands (Id, Name) VALUES (2, 'Chevrolet')
INSERT dbo.Brands (Id, Name) VALUES (3, 'Suzuki')
INSERT dbo.Brands (Id, Name) VALUES (4, 'Ford')
SET IDENTITY_INSERT dbo.Brands OFF
GO
SET IDENTITY_INSERT dbo.Models ON
INSERT dbo.Models (Id, Name, BrandId) VALUES (1, 'Yaris Sedan XLI C MT', 1)
INSERT dbo.Models (Id, Name, BrandId) VALUES (2, 'Yaris Sedan LEY MD', 1)
INSERT dbo.Models (Id, Name, BrandId) VALUES (3, 'New Silverado', 2)
INSERT dbo.Models (Id, Name, BrandId) VALUES (4, 'Onix Sedan', 2)
INSERT dbo.Models (Id, Name, BrandId) VALUES (5, 'Ñuniki', 3)
INSERT dbo.Models (Id, Name, BrandId) VALUES (6, 'Edge', 3)
INSERT dbo.Models (Id, Name, BrandId) VALUES (7, 'Explored', 3)
SET IDENTITY_INSERT dbo.Models OFF
GO
SET IDENTITY_INSERT dbo.Cars ON
INSERT dbo.Cars (Id, LicencePlate, Year, DateFabrication, New, Transmissions, ModelId)
VALUES
(1, '11111', 2011, '01/03/2021', 'FALSE', 'FALSE', 1)
SET IDENTITY_INSERT dbo.Cars OFF
GO
SELECT * FROM dbo.Cars;
SELECT * FROM dbo.Brands;
SELECT * FROM dbo.Models;