开发者

mysql insert handle a lot of values

is there a clean way of INSERT a lot of field entry values without them having to be in order? similar to how you can do with the UPDATE like below. can INSERT be done in that format?

$qstring="UPDATE test SET word = 'something' ,";
$qstring .= " word1 = 'something开发者_开发知识库1',";
...
mysql_query($qstring);


Yupp,

insert into
    your_table
set
    field_1='Yay!',
    field_2='Mmmbop!',
...


You can use the SET syntax:

insert into my_table set col1='value', col2='value'

Or, you can specify column names with a VALUES clause:

insert into my_table (col1, col2, col3) VALUES ('value1', 'value2', 'value3')

Using this later form, the values in the VALUES clause must match the order of the values in the column list that precedes the VALUES clause.

If you turn on "extended inserts" (it's usually on by default), you can use the latter form to insert multiple rows with a single statement:

insert into my_table (col1, col2, col3) VALUES 
   ('value1', 'value2', 'value3'), 
   ('row2value1', 'row2value2', 'row2value3'),
   ('row3value1', 'row3value2', 'row3value3')


INSERT INTO test SET word = 'something', word1 = 'something1'


yes we can do this also with INSERT

$qstring="Insert into test SET";
$qstring .= "word = 'something' ,";
$qstring .= " word1 = 'something1',";
...
mysql_query($qstring);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜