Question: The given SQL creates an Album and Song tables. The SHOW COLUMNS queries show information about the Album and Song table columns. Modify the two
The given SQL creates an Album and Song tables. The SHOW COLUMNS queries show information about the Album and Song table columns.
Modify the two CREATE TABLE statements. Add a primary key constraint to the Album table's ID column. Add a primary key constraint to the Song table's ID column, and add a foreign key constraint so the AlbumID column refers to the Album table's ID column.
-- Add a primary key
CREATE TABLE Album (
ID INT,
Title VARCHAR(60),
ReleaseYear INT
PRIMARY KEY (ID)
);
-- Add primary and foriegn keys
CREATE TABLE Song (
ID INT,
Title VARCHAR(60),
Artist VARCHAR(60),
AlbumID INT
PRIMARY KEY (ID),
FOREIGN KEY (AlbumID)
);
SHOW COLUMNS
FROM Album;
SHOW COLUMNS
FROM Song;
ERROR 1064 (42000) at line 2: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(ID) )' at line 5
What is going wrong please?
Step by Step Solution
There are 3 Steps involved in it
The syntax error in your SQL statements is due to the incorrect placement of the PRIMARY KEY and FOR... View full answer
Get step-by-step solutions from verified subject matter experts
