Example questions I am following, created tables this way and was able to insert value for ID as null, since it is auto increment, I thought it would do the math itself? Am I misunderstanding the auto increment feature? How come this doesn't work? Included full code below.
create database music;
use music;
create table Artist(
id INT PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(30)
);
create table Album(
id INT PRIMARY KEY AUTO_INCREMENT,
release_date DATE,
name VARCHAR(30),
genre VARCHAR(30),
artist_id INT,
FOREIGN KEY(artist_id)
REFERENCES Artist(id)
);
create table Song(
id INT PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(3),
length_sec INT,
album_id INT,
FOREIGN KEY(album_id)
REFERENCES Album(id)
);
# NULL NOT WORKING FOR ID????
INSERT INTO Artist VALUES(null, 'Rihanna');
INSERT INTO Album VALUES(null,current_date(),'SUPERBOWL','POP',null);
INSERT INTO Song VALUES(null,'S&M',180,null);
I tried to assign integer values to ID and it worked that way! As below:
INSERT INTO Artist VALUES(1, 'Rihanna');
INSERT INTO Album VALUES(2,current_date(),'SUPERBOWL','POP',1);
INSERT INTO Song VALUES(3,'S&M',180,2);