I need help trying set-up Foreign Keys after having difficulty following Music library MySQL database. I have multiple tables: Albums, Songs, Genres, Music Videos, Solo, and Group. There are ids, names and other columns for each specific table. Each id is primary key with int(11). Solo and Group represent solo artists and groups. (soloID and groupID are the primary key for them)
Look again
It could be the way I set up my database.
Solo
• djuIDs – int(11)
• profilepic – varchar(255)
• engname – varchar(255)
• korname – varchar(255)
• engbn – varchar(255)
• occupation – set
• recordlabel – varchar(255)
• debut - date
• dateofbirth – date
• officialsite - varchar(255)
• sitename –varchar(255)
• page – varchar(255)
Group
• djuIDs – int(11)
• profilepic – varchar(255)
• engname – text
• korname – text
• members – text
• recordlabel – varchar(255)
• debut – date
• officialsite - varchar(255)
• sitename –varchar(255)
• page – varchar(255)
Albums
• albumID – int(11)
• albumpic – varchar(255)
• albumthpic – varchar(255)
• albumTitle – varchar(255)
• performer – varchar(255)
• type – set (ex: ep, sp, studio)
• titletrack – varchar(255)
• genre
• releasedate – date
• distributor – varchar(255)
• page – varchar(255)
Songs
• songID – int(11)
• albumpic – varchar(255)
• tracknum – int(11)
• songTitle – varchar(255)
• performer – varchar(255)
• album – varchar(255)
• page – varchar(255)
Music Videos
• mvID – int(11)
• title – varchar(30)
• mvpic – varchar(255)
• performer – varchar(255)
• album – varchar(255)
• releasedate – date
• vURL – varchar(255)
Genres
• genreID – int(11)
• genreName –varchar(30)
• information – varchar(255)
I think that was one of my older answers… If you’ve used
INT(11)as your primary keys, your foreign key definitions should look like something like the following table definitions forArtistsandAlbums:Since you have defined all your PK columns as
INT(11), make sure that in the related tables you use the same data type. For example above,artistid INT NOT NULLassumes that the referenced column inArtistsis defined asid INT NOT NULL.In the definition above, I have made the FK columns as
NOT NULL, but that isn’t strictly necessary. You could, for example, have an album with a NULL artist. If you think that’s a possibility, you should be able to omit theNOT NULLin the column definitions.