Last active
June 8, 2018 13:25
-
-
Save ssougnez/28f08ba483f91f8034875429e6046450 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE DATABASE [FormulaOne]; | |
CREATE TABLE [Drivers] ( | |
[Id] int IDENTITY(1, 1) NOT NULL, | |
[FirstName] varchar(32) NOT NULL, | |
[LastName] varchar(32) NOT NULL, | |
[ChampionTitleCount] int NOT NULL CONSTRAINT [DF_Drivers_ChampionTitleCount] DEFAULT 0, | |
CONSTRAINT [PK_DriverId] PRIMARY KEY ([Id]) | |
) | |
CREATE TABLE [Tracks] ( | |
[Id] int IDENTITY(1, 1) NOT NULL, | |
[Title] varchar(126) NOT NULL, | |
[BestLapTimeDriverId] int NULL, | |
CONSTRAINT [PK_TrackId] PRIMARY KEY ([Id]), | |
CONSTRAINT [FK_Tracks_BestLapTimeDriverId] FOREIGN KEY ([BestLapTimeDriverId]) REFERENCES [Drivers]([Id]) | |
) | |
CREATE TABLE [TrackWinners] ( | |
[TrackId] int NOT NULL, | |
[DriverId] int NOT NULL, | |
CONSTRAINT [PK_TrackWinnerId] PRIMARY KEY ([TrackId], [DriverId]), | |
CONSTRAINT [FK_TrackWinners_TrackId] FOREIGN KEY ([TrackId]) REFERENCES [Tracks]([Id]), | |
CONSTRAINT [FK_TrackWinners_DriverId] FOREIGN KEY ([DriverId]) REFERENCES [Drivers]([Id]) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment