Skip to content

Instantly share code, notes, and snippets.

@ssougnez ssougnez/wp-dapper-01.sql
Last active Jun 8, 2018

Embed
What would you like to do?
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
You can’t perform that action at this time.