Bookmarks Window Help --80%) E sat 307 PM Luis Lopez csns.calstatela.edu CS1222
ID: 3603940 • Letter: B
Question
Bookmarks Window Help --80%) E sat 307 PM Luis Lopez csns.calstatela.edu CS1222 EX3 way they want. To do so, we will have to create a new table to track play list to tracks relationship 1. Create PlayLists table with felds of PlaytistID(int) PlayListHame (varchar(255), Descriptiontext) Primary ID should be on PlayListID None of the fields should be allowed to have nul Use DESCRIBE to test result o 2. Create PlayListsongs table with fields of Playt.istID, TitleID, TrackNum, NumberofPlays(int), songorder (int) e None of the fields should be allowed to have null ° Default for Numbe rof Plays and Songorder should be zero Use DESCRIBE to test result 3. Add PlayListID as foreign key from PlayListsongs table to PlayList table Use DESCRIBE to test result 4. Add TitleID and TrackNum as foreign key from PlayListsongs table to Tracks table hint you may need to add primary key to Tracks table e hint: remember foreign key constraints- data type has to be the same Use DESCRIBE to test result 5. Insert sample records to PlayLists table like below o hint: use SELECT FROM PlayLists to test result PlayListID PlayListName Description My Custom Play List Description Very second play list Hello songs 6. Insert sample records to PlayListSongs table like below o hint: use SELECT FROM PlayLists to test result PlayListiD TitlelD TrackNum NumberOfPlays SongOrder 8a8 5 7 8 9 0Explanation / Answer
[1]
CREATE TABLE PlayLists (
PlayListID int NOT NULL,
PlayListName varchar(255) NOT NULL,
Description TEXT NOT NULL,
PRIMARY KEY (PlayListID)
);
DESCRIBE PlayLists;
[2]
CREATE TABLE PlayListSongs (
PlayListID int NOT NULL,
TitleID int NOT NULL,
TrackNum int NOT NULL,
NumbeeOfPlays DEFAULT 0,
SongOrder int DEFAULT 0
);
DESCRIBE PlayListSongs;
[3]
ALTER TABLE PlayListSongs
FOREIGN KEY (PlayListID) REFERENCES PlayLists(PlayListID);
[5]
INSERT INTO PlayLists
VALUES(1,'My Custom Play List','Description');
INSERT INTO PlayLists
VALUES(2,'Very Second Play List','Hello songs');
SELECT * FROM PlayLists;
[6]
INSERT INTO PlayListSongs
VALUES(1,1,1,9,1);
INSERT INTO PlayListSongs
VALUES(1,3,2,2,4);
INSERT INTO PlayListSongs
VALUES(1,3,5,5,3);
INSERT INTO PlayListSongs
VALUES(1,5,3,1,2);
INSERT INTO PlayListSongs
VALUES(1,5,9,99,5);
INSERT INTO PlayListSongs
VALUES(2,6,1,500,4);
INSERT INTO PlayListSongs
VALUES(2,6,2,201,3);
INSERT INTO PlayListSongs
VALUES(2,6,3,999,1);
INSERT INTO PlayListSongs
VALUES(2,1,4,42,2);
SELECT * FROM PlayListSongs;
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.