Quantcast

[14:05:08] Error while executing SQL query on database 'onlinemusicstore': FOREIGN KEY constraint failed

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[14:05:08] Error while executing SQL query on database 'onlinemusicstore': FOREIGN KEY constraint failed

tinaoguntimehin
This post has NOT been accepted by the mailing list yet.
i have been banging my head for days on how to fix this error.

code below
create table artist (
artistid integer,
name varchar(120),
primary key (artistid)
);
create table album (
albumid integer,
title varchar(160),
artistid integer,
primary key (albumid),
foreign key (artistid) references artist(artistid)
)
;
create table mediatype (
mediatypeid integer primary key,
name varchar(120)
);
create table genre (
genreid integer primary key,
name varchar(120)
);
create table track (
trackid integer,
name varchar(120),
albumid integer,
mediatypeid integer not null,
genreid integer,
composer varchar (120),
milliseconds integer not null,
bytes integer,
unitprice float not null,
primary key (trackid),
foreign key (albumid) references album (albumid),
foreign key  (mediatypeid) references mediatype (mediatypeid),
foreign key (genreid) references genre (genreid)
)
;
INSERT INTO Genre (GenreId, Name) VALUES (1, 'Rock');
INSERT INTO Genre (GenreId, Name) VALUES (2, 'Jazz');
INSERT INTO Genre (GenreId, Name) VALUES (3, 'Metal');
INSERT INTO Genre (GenreId, Name) VALUES (4, 'Alternative & Punk');
INSERT INTO Genre (GenreId, Name) VALUES (5, 'Rock And Roll');

INSERT INTO MediaType (MediaTypeId, Name) VALUES (1, 'MPEG audio file');
INSERT INTO MediaType (MediaTypeId, Name) VALUES (2, 'Protected AAC audio file');
INSERT INTO MediaType (MediaTypeId, Name) VALUES (3, 'Protected MPEG-4 video file');
INSERT INTO MediaType (MediaTypeId, Name) VALUES (4, 'Purchased AAC audio file');
INSERT INTO MediaType (MediaTypeId, Name) VALUES (5, 'AAC audio file');

INSERT INTO Artist (ArtistId, Name) VALUES (1, 'AC/DC');
INSERT INTO Artist (ArtistId, Name) VALUES (2, 'Accept');
INSERT INTO Artist (ArtistId, Name) VALUES (3, 'Aerosmith');
INSERT INTO Artist (ArtistId, Name) VALUES (4, 'Alanis Morissette');
INSERT INTO Artist (ArtistId, Name) VALUES (5, 'Alice In Chains');
INSERT INTO Artist (ArtistId, Name) VALUES (6, 'Antônio Carlos Jobim');
INSERT INTO Artist (ArtistId, Name) VALUES (7, 'Apocalyptica');
INSERT INTO Artist (ArtistId, Name) VALUES (8, 'Audioslave');
INSERT INTO Artist (ArtistId, Name) VALUES (9, 'BackBeat');
INSERT INTO Artist (ArtistId, Name) VALUES (10, 'Billy Cobham');
INSERT INTO Artist (ArtistId, Name) VALUES (11, 'Black Label Society');
INSERT INTO Artist (ArtistId, Name) VALUES (12, 'Black Sabbath');

INSERT INTO Album (AlbumId, Title, ArtistId) VALUES (1, 'For Those About To Rock We Salute You', 1);

INSERT INTO Album (AlbumId, Title, ArtistId) VALUES (2, 'Balls to the Wall', 2);

INSERT INTO Album (AlbumId, Title, ArtistId) VALUES (3, 'Restless and Wild', 2);

INSERT INTO Album (AlbumId, Title, ArtistId) VALUES (4, 'Let There Be Rock', 1);

INSERT INTO Album (AlbumId, Title, ArtistId) VALUES (5, 'Big Ones', 3);

INSERT INTO Album (AlbumId, Title, ArtistId) VALUES (6, 'Jagged Little Pill', 4);

INSERT INTO Album (AlbumId, Title, ArtistId) VALUES (7, 'Facelift', 5);

INSERT INTO Album (AlbumId, Title, ArtistId) VALUES (8, 'Warner 25 Anos', 6);

INSERT INTO Album (AlbumId, Title, ArtistId) VALUES (9, 'Plays Metallica By Four Cellos', 7);

INSERT INTO Album (AlbumId, Title, ArtistId) VALUES (10, 'Audioslave', 8);

INSERT INTO Album (AlbumId, Title, ArtistId) VALUES (11, 'Out Of Exile', 8);

INSERT INTO Album (AlbumId, Title, ArtistId) VALUES (12, 'BackBeat Soundtrack', 9);

INSERT INTO Album (AlbumId, Title, ArtistId) VALUES (13, 'The Best Of Billy Cobham', 10);

INSERT INTO Album (AlbumId, Title, ArtistId) VALUES (14, 'Alcohol Fueled Brewtality Live! Disc 1', 11);
Loading...