Is there a way in mysql to insert a new row in a way that more directly associates a value with its column (rather than table(col_name) values(value)
)? When inserting a lot of values at one time, listing them in-line gets rather confusing and leads to errors/mistakes.
I'm looking for something more like UPDATE
's syntax of SET col_name='value'
.
I see in the mysql doc for INSERT there is the following:
INSERT [LOW_PRIORITY | DELAYED | HIGH_PRIORITY] [IGNORE]
[INTO] tbl_name
SET col_name={expr | DEFAULT}, ...
[ ON DUPLICATE KEY UPDATE
col_name=expr
[, col_name=expr] ... ]
but that is just for duplicates :/
In syntax, First, you must specify the name of the table. After that, in parenthesis, you must specify the column name of the table, and columns must be separated by a comma. The values that you want to insert must be inside the parenthesis, and it must be followed by the VALUES clause.
When inserting a single row into the MySQL table, the syntax is as follows: INSERT INTO table_name(column_1,column_2,column_3) VALUES (value_1,value_2,value_3); In the INSERT INTO query, you should specify the following information: table_name : A MySQL table to which you want to add a new row.
INSERT INTO Syntax 1. Specify both the column names and the values to be inserted: INSERT INTO table_name (column1, column2, column3, ...)
In the MySQL docs, [text]
means "text
is optional". So this is perfectly valid:
INSERT INTO table
SET col1='value1', col2='value2'...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With