List:MySQL on Win32« Previous MessageNext Message »
From:Paul DuBois Date:June 30 2000 2:25am
Subject:Re: Question regarding auto-increment integer fields
View as plain text  
At 5:56 PM -0700 2000-06-29, Joel Nelson wrote:
>Just hand it a null.  Assuming test1 has an auto_increment field 
>called Seq and
>a varchar called name, do the following:
>
>insert into test1 values (null,'myName')     or better yet
>insert into test1 (Seq,name) values (null,'myName')
>
>Joel
>
>Ana Farcas wrote:
>
>>  Hi there,
>>
>>  I have a question regarding the autoincrement fields. I am new to mysql. I
>>  used MSSQL though. In MSSQL, when i declare a field as autoincrement, it
>>  gets filled without needing to specify the autoincrement field. In mysql, i
>>  couldn't find any way to get such a field filled automatically. I noticed
>>  though that if i write a query such as "insert into test1 values (0)" -
>>  given that test1 contains only one autoincrement field, the field does get
>>  incremented, but if i insert eg 234, the value that is inserted is 234.
>>  Is there any way to design this field so that i don't need to specifically
>  > fill it further?

Inserting 0 is currently like inserting NULL, so the effect is the
same as in the response at the top of this message.  But you don't need
to specify the field at all in the INSERT statement.  That is, these
two statements are equivalent:

insert into test1 (Seq,name) values (NULL,'myName')
insert into test1 (name) values ('myName')

In the second, the Seq field will get the default value, which is NULL,
and will automatically be assigned the next AUTO_INCREMENT value.

-- 
Paul DuBois, paul@stripped
Thread
Question regarding auto-increment integer fieldsAna Farcas29 Jun
  • Re: Question regarding auto-increment integer fieldsJoel Nelson30 Jun
    • Re: Question regarding auto-increment integer fieldsPaul DuBois30 Jun
  • Re: Question regarding auto-increment integer fieldsSinisa Milivojevic30 Jun