clear markdown compare help donate or buy diddy dollings comments/suggestions/bugs a leap of faith? bible365
clear markdown donate comments/suggestions/bugs a leap of faith? bible365 diddy dollings
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0. 648489 fiddles created (15213 in the last week).

CREATE TABLE Species ( SpeciesCode CHAR(1) NOT NULL, Name CHAR(30) NOT NULL, -- CONSTRAINT Species_PK PRIMARY KEY (SpeciesCode), CONSTRAINT Species_AK UNIQUE (Name) ); CREATE TABLE Animal ( AnimalId INT NOT NULL IDENTITY (1,1), SpeciesCode CHAR(1) NOT NULL, CreatedDateTime DATETIME NOT NULL, -- CONSTRAINT Animal_PK PRIMARY KEY (AnimalId), CONSTRAINT Animal_to_Species_FK FOREIGN KEY (SpeciesCode) REFERENCES Species (SpeciesCode) ); CREATE TABLE Fox ( FoxId INT NOT NULL, BusinessId VARCHAR(50) NOT NULL, BodyLength INT NOT NULL, FurColour VARCHAR NOT NULL, -- CONSTRAINT Fox_PK PRIMARY KEY (FoxId), CONSTRAINT Fox_AK UNIQUE (BusinessId), CONSTRAINT Fox_to_Animal_FK FOREIGN KEY (FoxId) REFERENCES Animal (AnimalId) ); CREATE TABLE Elephant ( ElephantId INT NOT NULL, BusinessId VARCHAR(50) NOT NULL, Weight INT NOT NULL, TuskLength INT NOT NULL, -- CONSTRAINT Elephant_PK PRIMARY KEY (ElephantId), CONSTRAINT Elephant_AK UNIQUE (BusinessId), CONSTRAINT Elephant_to_Animal_FK FOREIGN KEY (ElephantId) REFERENCES Animal (AnimalId) ); CREATE TABLE Item ( ItemSeq INT NOT NULL IDENTITY (1,1), AnimalId INT NOT NULL, Description VARCHAR(500) NOT NULL, CreatedDateTime DATETIME NOT NULL, -- CONSTRAINT Item_PK PRIMARY KEY (ItemSeq), CONSTRAINT Item_to_Animal_FK FOREIGN KEY (AnimalId) REFERENCES Animal (AnimalId) );
 hidden batch(es)


INSERT INTO Species (SpeciesCode, Name) VALUES ('F', 'Fox'), ('E', 'Elephant');
2 rows affected
 hidden batch(es)


SELECT SpeciesCode, Name FROM Species;
SpeciesCode Name
E Elephant
F Fox
 hidden batch(es)


CREATE VIEW FullFox AS SELECT A.AnimalId, F.BusinessId, F.BodyLength, F.FurColour, A.CreatedDateTime FROM Fox F JOIN Animal A ON F.FoxId = A.AnimalId;
 hidden batch(es)


CREATE VIEW FullElephant AS SELECT A.AnimalId, E.BusinessId, E.Weight, E.TuskLength, A.CreatedDateTime FROM Elephant E JOIN Animal A ON E.ElephantId = A.AnimalId;
 hidden batch(es)


CREATE VIEW ItemWithAnimal AS SELECT I.ItemSeq, A.AnimalId, A.SpeciesCode, I.Description, I.CreatedDateTime AS ItemCreatedDateTime, A.CreatedDateTime AS AnimalCreatedDateTime FROM Item I JOIN Animal A ON I.AnimalId = A.AnimalId;
 hidden batch(es)