impactbyte-drogon-scholarship / discussion

General Discussion
https://glints.id
The Unlicense
2 stars 0 forks source link

SQL insert on auto_increment field #18

Open michaeltamsil opened 6 years ago

michaeltamsil commented 6 years ago

preparation

CREATE TABLE employees (
    emp_no INT(11) NOT NULL AUTO_INCREMENT,
    birth_date DATE NOT NULL,
    first_name VARCHAR(14) NOT NULL,
    last_name VARCHAR(16) NOT NULL,
    gender ENUM('M', 'F') NOT NULL,
    hire_date DATE NOT NULL,
    PRIMARY KEY (emp_no)
);

insert record into table where one field is primary key, int and auto_increment

INSERT INTO `employees`(birth_date, first_name, last_name, gender, hire_date) VALUES 
('1991-12-01', 'Surya', 'Raja', 'M', '2004-02-02');

or

INSERT INTO `employees` VALUES 
(``, '1991-12-01', 'Surya', 'Raja', 'M', '2004-02-02');

this will create value for emp_no field automatically increment by database system