mysql - Inserting into table with skipping the auto incremented column without the need to write the columns' names -


Then I have this large table with more than 30 columns, and what I wanted to do would include its values But the first skipping column on the OCC is 'ID' which automatically increments, so I have two options which I can think of, one is:

  'table name' col2 , Col3, col4 ... INESERT INSERT Val2, val3, val4   

But it takes a long time to copy the names of columns, Having Uti is likely to be missing a letter. Then another option will bring the last ID in the table and edit the next ID itself:

  $ last_row_query = mysql_query ("Select ID from order order by ID DESC limit 1"); If (! $ Last_row_query) {dead ('invalid query:' .mysql_error ()); } $ Last_row = mysql_fetch_assoc ($ last_row_query); $ Last_id = $ last_row ['id']; $ Current_id = $ last_id + 1;   

and then the query will be

  INSERT 'table name' VALUES $ current_id, val2, val3, val4   

Is there any difference in the efficiency of those two methods? And is there any way more recommended than the other?

If you get the current value and try to enter the next higher value, you create the position of the race Are there. Two concurrent app requests will attempt to include the same value.

Using either the NULL or DEFAULT in place of a value is a better solution, even zeros can work on the basis of SQL mode.

  embed in `table name` values ​​(default,?,?,?);   

Remember to put the table name in the back-tick, not the single-quotation. Single-quotes are for string literals or date litterres.

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -