In this example we have two tables, album and song and we're using the SQLite dialect.
We will link these together by using a foreign key.
The album table uses a composite primary key (album_artist,album_name), so the foreign key will be a composite foreign key to match.
The song_album column will reference the album_name column,
the song_artist column will reference the album_artist column.
We've already created all of the tables and columns including those used by the foreign key.
We have added a primary key to both tables. The primary key on the album table includes both album_name and album_artist.
You will need to use the inspector to complete this task.
Use the sidebar control in the window toolbar to display the right hand sidebar if it is not visible
If you want to follow along, either download the example starting file or paste the following text into a new empty SQLEditor document (with dialect SQLite).
/* SQLEditor (SQLite)*/
CREATE TABLE album
(
album_artist TEXT,
album_name TEXT,
album_cover BINARY,
PRIMARY KEY (album_artist,album_name)
);
CREATE TABLE song
(
song_id INTEGER PRIMARY KEY,
song_artist TEXT,
song_album TEXT,
song_name TEXT
);
There are 9 steps:
The foreign key is now complete.
The source (left) sidebar should show the SQL:
/* SQLEditor (SQLite)*/
CREATE TABLE album
(
album_artist TEXT,
album_name TEXT,
album_cover BINARY,
PRIMARY KEY (album_artist,album_name)
);
CREATE TABLE song
(
song_id INTEGER PRIMARY KEY,
song_artist TEXT,
song_album TEXT,
song_name TEXT,
FOREIGN KEY (song_artist,song_album) REFERENCES album (album_artist,album_name)
);
Starting File: Starting File
End File: End File
To contact us with a support issue please email: