mysql (5.1) insert syntax > col_name=value?

2019-05-01 06:45发布

问题:

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 :/

回答1:

In the MySQL docs, [text] means "text is optional". So this is perfectly valid:

INSERT INTO table
SET col1='value1', col2='value2'...