add batch
remove batch
split batch
comment selection
show hidden batches
hide batch
highlight batch
db<>fiddle
Db2
Firebird
MariaDB
MySQL
Node.js
Oracle
Postgres
SQLite
SQL Server
TimescaleDB
YugabyteDB
Developer-C 11.1
3.0
4.0
10.2
10.3
10.4
10.5
10.6
10.7
10.8
10.9
5.5
5.6
5.7
8.0
18
11g Release 2
18c
21c
23c
8.4
9.3
9.4
9.5
9.6
10
11
12
13
14
15
16
3.8
3.16
3.27
3.39
2012
2014
2016
2017
2017 (Linux)
2019
2019 (Linux)
2022
2.11
2.6
2.8
2.18
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
Sakila
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
AdventureWorks
no sample DB
no sample DB
AdventureWorks
no sample DB
no sample DB
no sample DB
no sample DB
run
markdown
donate
feedback
about
By using db<>fiddle, you agree to license everything you submit by
Creative Commons CC0
.
CREATE TABLE Person ( PersonId INT NOT NULL, FirstName CHAR(30) NOT NULL, LastName CHAR(30) NOT NULL, BirthDate DATE NOT NULL, GenderCode CHAR(3) NOT NULL, TwitterProfile CHAR(30) NOT NULL, PhoneNumber CHAR(30) NOT NULL, EmailAddress CHAR(30) NOT NULL, CreatedDateTime DATETIME NOT NULL, -- CONSTRAINT Person_PK PRIMARY KEY (PersonId), CONSTRAINT Person_AK1 UNIQUE ( FirstName, LastName, GenderCode, BirthDate ), CONSTRAINT Person_AK2 UNIQUE (TwitterProfile), CONSTRAINT Person_AK3 UNIQUE (EmailAddress) ); CREATE TABLE Ethnicity ( EthnicityId INT NOT NULL, Name CHAR(30) NOT NULL, Description CHAR(30) NOT NULL, CreatedDateTime DATETIME NOT NULL, -- CONSTRAINT Ethnicity_PK PRIMARY KEY (EthnicityId), CONSTRAINT Ethnicity_AK UNIQUE (Description) ); CREATE TABLE Actor ( ActorId INT NOT NULL, Headshot CHAR(30) NOT NULL, EthnicityId INT NOT NULL, CreatedDateTime DATETIME NOT NULL, -- CONSTRAINT Actor_PK PRIMARY KEY (ActorId), CONSTRAINT ActorToPerson_FK FOREIGN KEY (ActorId) REFERENCES Person (PersonId), CONSTRAINT ActorToEthnicity_FK FOREIGN KEY (EthnicityId) REFERENCES Ethnicity (EthnicityId) ); CREATE TABLE Director ( DirectorId INT NOT NULL, Bio CHAR(120) NOT NULL, Etcetera CHAR(30) NOT NULL, CreatedDateTime DATETIME NOT NULL, -- CONSTRAINT Director_PK PRIMARY KEY (DirectorId), CONSTRAINT DirectorToPerson_FK FOREIGN KEY (DirectorId) REFERENCES Person (PersonId) ); CREATE TABLE Country ( CountryCode CHAR(2) NOT NULL, Name CHAR(30) NOT NULL, CreatedDateTime DATETIME NOT NULL, -- CONSTRAINT Country_PK PRIMARY KEY (CountryCode), CONSTRAINT Country_AK UNIQUE (Name) ); CREATE TABLE Location ( CountryCode CHAR(2) NOT NULL, LocationCode CHAR(3) NOT NULL, Name CHAR(30) NOT NULL, CreatedDateTime DATETIME NOT NULL, -- CONSTRAINT Location_PK PRIMARY KEY (CountryCode, LocationCode), CONSTRAINT Location_AK UNIQUE (CountryCode, Name) ); CREATE TABLE Writer ( WriterId INT NOT NULL, CountryCode CHAR(2) NOT NULL, LocationCode CHAR(3) NOT NULL, CreatedDateTime DATETIME NOT NULL, -- CONSTRAINT Writer_PK PRIMARY KEY (WriterId), CONSTRAINT WriterToPerson_FK FOREIGN KEY (WriterId) REFERENCES Person (PersonId), CONSTRAINT WriterToLocation_FK FOREIGN KEY (CountryCode, LocationCode) REFERENCES Location (CountryCode, LocationCode) ); CREATE TABLE UserProfile ( UserId INT NOT NULL, UserName CHAR(30) NOT NULL, Etcetera CHAR(30) NOT NULL, CreatedDateTime DATETIME NOT NULL, -- CONSTRAINT UserProfile_PK PRIMARY KEY (UserId), CONSTRAINT UserProfile_AK UNIQUE (UserName), CONSTRAINT UserProfileToPerson_FK FOREIGN KEY (UserId) REFERENCES Person (PersonId) ); CREATE TABLE URL ( ActorId INT NOT NULL, Address CHAR(90) NOT NULL, Etcetera CHAR(30) NOT NULL, AddedDateTime DATETIME NOT NULL, -- CONSTRAINT URL_PK PRIMARY KEY (ActorId, Address), CONSTRAINT URLtoActor_FK FOREIGN KEY (ActorId) REFERENCES Actor (ActorId) );
CREATE VIEW FullActor AS SELECT P.FirstName, P.Lastname, P.BirthDate, P.GenderCode, P.TwitterProfile, P.PhoneNumber, P.EmailAddress, A.Headshot, E.Name AS Ethnicity FROM Person P JOIN Actor A ON A.ActorId = P.PersonId JOIN Ethnicity E ON E.EthnicityId = A.EthnicityId;
CREATE VIEW FullDirector AS SELECT P.FirstName, P.Lastname, P.BirthDate, P.GenderCode, P.TwitterProfile, P.PhoneNumber, P.EmailAddress, D.Bio, D.Etcetera FROM Person P JOIN Director D ON D.DirectorId = P.PersonId;
CREATE VIEW FullWriter AS SELECT P.FirstName, P.Lastname, P.BirthDate, P.GenderCode, P.TwitterProfile, P.PhoneNumber, P.EmailAddress, C.Name AS Country, L.Name AS Location FROM Person P JOIN Writer W ON W.WriterId = P.PersonId JOIN Country C ON C.CountryCode = W.CountryCode JOIN Location L ON L.LocationCode = W.LocationCode;