03-05 Increment Primary Key

AUTO_INCREMENT

1

Increment the PRIMARY KEY without an argument in INSERT

DROP TABLE student;
CREATE TABLE student(
    student_id INT AUTO_INCREMENT,
    name VARCHAR(20),
    major VARCHAR(20) DEFAULT 'undecided',
    PRIMARY KEY(student_id)
);
INSERT INTO student(name,major) VALUES('John','Biology');

02

These lines will increment themselves in the PRIMARY KEY when formatted like this.

INSERT INTO student(name,major) VALUES('John','Biology');
INSERT INTO student(name,major) VALUES('Claire','Sociology');
INSERT INTO student(name) VALUES('George');
INSERT INTO student(name,major) VALUES('John','Computer Science');
SELECT * FROM student