in reply to (jeffa) 2Re: Inserting values into a MySQL database
in thread Inserting values into a MySQL database

Good point. I make sure I specify the columns all the time because I have been caught out by this before.

I had a quick check through the MySQL docs and I noticed for versions > 3.22.10 you can use SQL like:

INSERT INTO table SET x = 1, y = 2, z = 3;
Which is interesting, but I'm not sure if it is better, and I'm pretty sure it isn't portable. There is a couple of other things that are cool (I never noticed this stuff before!) such as inserting multiple records in 1 statement:
INSERT INTO table (x,y,z) VALUES (1,2,3), (4,5,6), (7,8,9);
Of course this is only really handy if you know in advance how many records you want to insert.

What I forgot to mention is that you should really be using:

INSERT DELAYED INTO table (x,y,z) VALUES (1,2,3);
if you are doing multiple inserts as this can give you quite a bit of a performance boost.

gav^

Replies are listed 'Best First'.
Re: Re: (jeffa) 2Re: Inserting values into a MySQL database
by ralphie (Friar) on Jan 14, 2002 at 17:33 UTC
    just a note that i've found the "insert into table set" syntax more reliable than the standard forms for mysql. not portable, of course, but you can use placeholders in the statement. one of the reasons i started moving away from mysql.