mysql insert syntax code example

Example 1: mysql insert on dupèlicate

INSERT INTO table_name(c1)
VALUES(c1)
ON DUPLICATE KEY UPDATE c1 = VALUES(c1) + 1;

Example 2: mySql insert row

INSERT INTO `table_name`(column_1,column_2,...) VALUES (value_1,value_2,...);

Example 3: Insert mysql

#Some columns or all 
INSERT INTO table_name (column1, column2, column3, ...)
VALUES (value1, value2, value3, ...);
#All columns
INSERT INTO table_name
VALUES (value1, value2, value3, ...);

Example 4: mysql insert

INSERT INTO table1 (col1, col2) VALUES (3, 'A string');
INSERT INTO table1 (col1) VALUES (3);			-- col2 will be NULL if allowed
INSERT INTO table1 VALUES (3, 'A string');     	-- all table1 columns
INSERT INTO table1 (col1, col2) SELECT value3, value1 FROM table2;

Example 5: insert mysql

INSERT INTO tbl_name (a,b,c) 
    VALUES(1,2,3), (4,5,6), (7,8,9);

Tags:

Sql Example