RELATIONNAL DATABASE

admin

Administrator
Staff member
LET'S SUPOSE TABLE WE HAVE AN MP3 DATABASE LIKE THE ONE BELOW:
TABLE : INFO
+---------+---------+-----------+----------+
|SONG NAME|FILE SIZE|ARTIST NAME|ALBUM NAME|
+---------|---------|-----------|----------+
|SONG_1 | 4.2 | ARTIST_A | ALBUM_X |
|SONG_2 | 5.3 | ARTIST_A | ALBUM_Q |
|SONG_3 | 2.1 | ARTIST_Z | ALBUM_W |
| - | - | - | - |

WE WANNA CREATE A RELATIONNAL TABLES FROM TABLE INFO LIKE BELOW :

WHERE ID_SONG (INT NOT NULL AUTO_INCREMENT), PRIMARY KEY OF TABLE SONG
AND ID_ARTIST (INT NOT NULL AUTO_INCREMENT), PRIMARY KEY OF TABLE ARTIST
AND ID_ALBUM (INT NOT NULL AUTO_INCREMENT), PRIMARY KEY OF TABLE ABLUM
AND ID (INT NOT NULL AUTO_INCREMENT), PRIMARY KEY OF TABLE RELATION

THE TABLE RELATION REPRESENT THE RELATION BETWEEN (SONG,ARTIST,ALBUM) EXACTLY LIKE THE TABLE
INFO BUT USING ONLY THE PRIMARY KEY OF TABLES (SONG,ARTIST,ALBUM)

HOW CAN I WRITE AN SQL QUERY TO DO IT (BACTH)

TABLE : SONG
+---------+----------+----------+
| ID_SONG |SONG NAME | FILE SIZE|
+--------------------+----------+
| 1 | SONG_1 | 4.2 |
| 2 | SONG_2 | 5.3 |
| 3 | SONG_3 | 2.1 |
| | | |
+---------+----------+----------+

TABLE : ARTIST
+----------+-----------+
|ID_ARTIST |ARTIST NAME|
+----------------------+
| 1 | ARTIST_A |
| 2 | ARTIST_Z |
| - | - |
| | |
+----------+-----------+

TABLE : ALBUM
+--------+----------+
|ID_ALBUM|ALBUM NAME|
+-------------------+
| 1 | ALBUM_X |
| 2 | ALBUM_Q |
| 3 | ALBUM_W |
| | |
+--------+----------+

TABLE : RELATION
+----+--------+---------+---------+
| ID |ID_SONG |ID_ARTIST|ID_ALBUM |
+----+--------+---------+---------+
| 1 | 1 | 1 | 1 |
| 2 | 2 | 1 | 2 |
| 3 | 3 | 2 | 3 |
+----+--------+---------+---------+
 
Back
Top