Question

SQL Create a database called MyMusician Create three tables, one named “User”, one named “Song”, and...

SQL

Create a database called MyMusician

Create three tables, one named “User”, one named “Song”, and one named “Playlist”.

The “User” table should have a column for userID (integer, autoincrement, not null, primary key), username, and password. It should also have one column for a foreign key we will assign later called “playlistID” (integer).

The “Playlist” table should have a “playlistID” (integer, autoincrement, not null, primary key), and a column for a foreign key we will assign later called “songID” (integer).

The “Song table should have a “songID” (integer, autoincrement, not null, primary key), and a column for name, artist, album, year, duration, and genre.

Add an additional column to Playlist named “name”, which will contain the playlist name. Then add another table called “UserPL” that contains a userID, and a “name”. This is how we connect multip[le users with multiuple playlists.

0 0
Add a comment Improve this question Transcribed image text
Answer #1


Create a database called MyMusician

create database MyMusician;

Create three tables, one named "User", one named "Song", and one named "Playlist" within MyMusician


Create table User:

create table User(usedID INT AUTO_INCREMENT NOT NULL PRIMARY KEY, username varchar(100), password varchar(100), playlistID INT);

Create table Playlist:

create table Playlist( playlistID INT AUTO_INCREMENT NOT NULL PRIMARY KEY, songID INT);

Create table Song:

create table Song(songID INT AUTO_INCREMENT NOT NULL PRIMARY KEY, name varchar(100), artist varchar(100), album varchar(100), year INT, duration DECIMAL(8,2), genre varchar(20));

Add an additional column to Playlist named "name", which will contain the playlist name.

Alter table Playlist add name varchar(100) NOT NULL;

Create table UserPL:

create table UserPL(userID INT NOT NULL , name varchar(100) NOT NULL, constraint fk_user_userPL FOREIGN KEY(userID) references User(userID), PRIMARY KEY(userID, name));

Add foreign key constraint to User table:

Alter table User fk_user_playlist FOREIGN KEY(playlistID) references Playlist(playlistID);

Add foreign key constraint to Playlist:

Alter table Playlist fk_playlist_song FOREIGN KEY(songID) references Song(songID);

Add a comment
Know the answer?
Add Answer to:
SQL Create a database called MyMusician Create three tables, one named “User”, one named “Song”, and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a single SQL statement to create a new playlist called 'Background music'; and write another...

    Write a single SQL statement to create a new playlist called 'Background music'; and write another single SQL statement to associate the new playlist with the 10 longest duration tracks of jazz music from the Track table. CREATE TABLE MediaType ( MediaTypeID INTEGER PRIMARY KEY NOT NULL, Name TEXT ); CREATE TABLE Playlist ( PlaylistID INTEGER PRIMARY KEY NOT NULL, Name TEXT ); CREATE TABLE PlaylistTrack ( PlaylistID INTEGER NOT NULL, TrackID INTEGER NOT NULL, PRIMARY KEY (PlaylistID, TrackID), FOREIGN...

  • a. Write five select statements to select data from each table individually. b. Write one select...

    a. Write five select statements to select data from each table individually. b. Write one select statement with joins to list the playlist name, playlist track number, song name, artist name, album name, sorted by playlist name and playlist track number. DROP TABLE Artists CASCADE CONSTRAINTS; DROP TABLE Albums CASCADE CONSTRAINTS; DROP TABLE Songs CASCADE CONSTRAINTS; DROP TABLE Playlists CASCADE CONSTRAINTS; DROP TABLE PlaylistSongs CASCADE CONSTRAINTS; CREATE TABLE Artists ( ArtistID int NOT NULL, ArtistName varchar(255), PRIMARY KEY (ArtistID) );...

  • Define an SQL view JokesNum that gives the number of jokes each user posts on each...

    Define an SQL view JokesNum that gives the number of jokes each user posts on each day. Database: create table User( userid varchar(30) not null, password varchar(30), firstname varchar(30), lastname varchar(50), email varchar(50), gender char(1), age integer, banned boolean, primary key(userid), unique(email)); create table MyFriends( userid varchar(30), friendid varchar(30), primary key(userid,friendid), foreign key(userid) references User, foreign key(friendid) references User(userid)); Create table Jokes( Jokeid integer, title varchar(100), description varchar(255), authorid varchar(30) not null, primary key(jokeid), posttime Datetime, foreign key(authorid) references User(userid));...

  • 4. Consider the following schema for an online streaming service, where users are allowed to play...

    4. Consider the following schema for an online streaming service, where users are allowed to play (stream) songs performed by different artists. Primary and foreign key constraints are also listed for the schema of each table. User (ID, Password, Name, Location) Primary key = ID Artist (ID, Name, Birthyear) Primary key = ID Song (ID, Title, Album, ArtistID) Primary key = ID Song(ArtistID) references Artist(ID) Play (ID, UserID, SongID, Timestamp) Primary key = ID Play(UserID) references User(ID) Play(SongID) references Song(ID)...

  • Based on the CREATE TABLE statements, make an ER model of the database. Give suitable names...

    Based on the CREATE TABLE statements, make an ER model of the database. Give suitable names to the relationships. (Remember cardinality and participation constraints.) The diagram must use either the notation used in the textbook (and the lectures) or the crow’s foot notation. To save you some time: There are a few tables that include the following address fields: Address, City, State, Country and PostalCode (and the same fields with the prefix Billing-). You are allowed to replace these attributes...

  • Given the mySQL tables created below...    Create a mySQL solution to return the itemIDs of...

    Given the mySQL tables created below...    Create a mySQL solution to return the itemIDs of items posted by user X, such that all the reviews are “Excellent” or “Good” for these items CREATE TABLE Users (    userId varchar (30) NOT NULL,    pass varchar (30),    fname varchar (50),    lname varchar (50),    email varchar (50),    gender char(1),    age integer,    banned boolean,    PRIMARY KEY (userId),    UNIQUE(email)) CREATE TABLE FavSellers (    userId...

  • Write SQL to create a table called City in your account. The schema of the table...

    Write SQL to create a table called City in your account. The schema of the table is listed below. You must define the data types and not null constraint (if needed) of every column and all the primary key and foreign key constraints for the table. No screenshot needed for this question. City (Name, Country, Population, Capital). Name: the name of the city. Text string with maximum 50 characters. Must not be null. Country: the name of the country where...

  • CREATE TABLE Users (               userId varchar (30) NOT NULL,               pass varchar (30),     

    CREATE TABLE Users (               userId varchar (30) NOT NULL,               pass varchar (30),               fname varchar (50),               lname varchar (50),               email varchar (50),               gender char(1),               age integer,               banned boolean,               PRIMARY KEY (userId),               UNIQUE(email)) CREATE TABLE FavSellers (               userId varchar (30),               sellerId varchar (30),               PRIMARY KEY (userId, sellerId),               FOREIGN KEY(userId) references Users,               FOREIGN KEY(sellerId) references Users(userId)) CREATE TABLE Items (               itemId integer,               title varchar (50),              ...

  • Create a new database and execute the code below in SQL Server’s query window to create...

    Create a new database and execute the code below in SQL Server’s query window to create the database tables. CREATE TABLE PhysicianSpecialties (SpecialtyID integer, SpecialtyName varchar(50), CONSTRAINT PK_PhysicianSpecialties PRIMARY KEY (SpecialtyID)) go CREATE TABLE ZipCodes (ZipCode varchar(10), City varchar(50), State varchar(2), CONSTRAINT PK_ZipCodes PRIMARY KEY (ZipCode)) go CREATE TABLE PhysicianPractices (PracticeID integer, PracticeName varchar(50), Address_Line1 varchar(50), Address_Line2 varchar(50), ZipCode varchar(10), Phone varchar(14), Fax varchar(14), WebsiteURL varchar(50), CONSTRAINT PK_PhysicianPractices PRIMARY KEY (PracticeID), CONSTRAINT FK_PhysicianPractices_ZipCodes FOREIGN KEY (ZipCode) REFERENCES Zipcodes) go CREATE...

  • SQL Query Question: I have a database with the tables below, data has also been aded...

    SQL Query Question: I have a database with the tables below, data has also been aded into these tables, I have 2 tasks: 1. Add a column to a relational table POSITIONS to store information about the total number of skills needed by each advertised position. A name of the column is up to you. Assume that no more than 9 skills are needed for each position. Next, use a single UPDATE statement to set the values in the new...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT