03-01 INSERT INTO

01

We want to make a table with these values from the example

02

The values must correspond to the values types decalred in the table.

CREATE TABLE student(
    student_id INT,
    name VARCHAR(20),
    major VARCHAR(20),
    PRIMARY KEY(student_id)
);
INSERT INTO student VALUES(1,'Jack','Biology');

If inserted, you will see Rows affected: 1

03

To display the table with values use SELECT followed by the * asterisk then FROM <tablename>

SELECT * FROM student;

The SELECT * FROM keywords display tables with values, while DESCRIBE show just the table

04

Add more values the same way. Since the student_id column is the PRIMARY KEY it cannot be repeated.

INSERT INTO student VALUES(2,'Kate','Sociology');

05

If you try to run the same line,

INSERT INTO student VALUES(2,'Kate','Sociology');

It will throw an error