开发者

mysql (5.1) insert syntax > col_name=value?

开发者 https://www.devze.com 2023-04-05 16:56 出处:网络
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, list

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=e开发者_如何学Goxpr] ... ]

but that is just for duplicates :/


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

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

精彩评论

暂无评论...
验证码 换一张
取 消