List:General Discussion« Previous MessageNext Message »
From:Michael Dykman Date:June 30 2010 5:42pm
Subject:Re: INSERT with auto increment
View as plain text  
generally, it is:
INSERT INTO TABLE1 (fieldname [ , fieldname]* ) VALUES (value[, value]*)


If you don't list the columns, it assumes you are inserting all of them, so:

INSERT INTO TABLE1 (mycolumn  ) VALUES ('stuff')


This will also work
INSERT INTO TABLE1 VALUES (0, 'stuff')

the auto-increment will engage on an insert of 0

 - michael dykman


On Wed, Jun 30, 2010 at 1:30 PM, David Stoltz <Dstoltz@stripped> wrote:
> Hi All,
>
>
>
> In MS SQL, if the table has an identity field/primary key which is set
> to auto increment, you can leave the value out of an INSERT statement,
> and the next highest value will be automatically inserted...
>
>
>
> For instance, with a two column table I could do "INSERT INTO TABLE1
> VALUES('stuff')"
>
>
>
> I'm having trouble doing the same thing in mySQL...
>
>
>
> In mySQL, if I expressly give it a value, like "INSERT INTO TABLE1
> VALUES(17,'stuff')" - it works fine. But if I remove the 17, it says I
> don't have a matching number of columns.
>
>
>
> The field in question has a foreign key in another table, making this a
> primary key in theory, but there's nothing in myphpadmin that shows this
> as a primary key - perhaps this is the problem?
>
>
>
> Need some guidance....
>
>
>
> Thanks!
>
> Dave
>
>



-- 
 - michael dykman
 - mdykman@stripped

 May the Source be with you.
Thread
INSERT with auto incrementDavid Stoltz30 Jun
  • Re: INSERT with auto incrementMichael Dykman30 Jun
    • RE: INSERT with auto incrementDavid Stoltz1 Jul
  • Re: INSERT with auto incrementjoao30 Jun
Re: INSERT with auto incrementJan Steinman30 Jun