List:General Discussion« Previous MessageNext Message »
From:Paul DuBois Date:March 10 2003 4:13pm
Subject:RE: automatically incrementing an int value
View as plain text  
At 11:09 -0500 3/10/03, Douglas B. Jones wrote:
>Hi,
>
>
>Great! This works, I did not use the 'null' and that is
>where I had a problem. One other questions: is this atomic?
>If I have several processes trying to do this at one time,
>will each one correctly update the table (assuming they have
>the same 'name' value.

Yes.

>  Also, in the part: unique (name(100)),
>what does the 100 do here? Is that saying the first 100 chars
>are considered unique?

Exactly.

>
>Thanks,
>Cheers,
>Douglas
>
>>  -----Original Message-----
>>  From: Alec.Cawley@stripped [mailto:Alec.Cawley@stripped]
>>  Sent: Monday, March 10, 2003 10:36 AM
>>  To: Douglas B Jones
>>  Cc: mysql@stripped
>>  Subject: Re: automatically incrementing an int value
>>
>>
>>
>>  As I read the manual, the REPLACE command will do what you want.
>>
>>  Make the name field UNIQUE, and the number field AUTO_INCREMENT NOT NULL.
>>  Replace dos a delete-if-present, insert. The insert generates a new ID.
>>
>>  See test below, and note two rows affected by second replace.
>>
>>  mysql> create table test (a int auto_increment not null, name tinytext not
>>  null, primary key (a), unique (name(100))) ;
>>  Query OK, 0 rows affected (0.02 sec)
>>
>>  mysql> replace into test values (null, "hello") ;
>>  Query OK, 1 row affected (0.01 sec)
>>
>>  mysql> select * from test ;
>>  +---+-------+
>>  | a | name  |
>>  +---+-------+
>>  | 1 | hello |
>>  +---+-------+
>>  1 row in set (0.01 sec)
>>
>>  mysql> replace into test values (null, "hello") ;
>>  Query OK, 2 rows affected (0.02 sec)
>>
>>  mysql> select * from test ;
>>  +---+-------+
>>  | a | name  |
>>  +---+-------+
>>  | 2 | hello |
>>  +---+-------+
>  > 1 row in set (0.00 sec)

Thread
automatically incrementing an int valueDouglas B. Jones10 Mar
Re: automatically incrementing an int valueAlec.Cawley10 Mar
  • RE: automatically incrementing an int valueDouglas B. Jones10 Mar
    • RE: automatically incrementing an int valuePaul DuBois10 Mar
      • RE: automatically incrementing an int valueDouglas B. Jones12 Mar
        • RE: automatically incrementing an int valueDouglas B. Jones12 Mar
        • RE: automatically incrementing an int valuePaul DuBois12 Mar
          • RE: automatically incrementing an int valueDouglas B. Jones12 Mar
            • RE: automatically incrementing an int valuePaul DuBois12 Mar
              • Re: automatically incrementing an int valueBenjamin Pflugmann12 Mar
            • Re: automatically incrementing an int valueJoseph Bueno12 Mar
            • RE: automatically incrementing an int valueKeith C. Ivey12 Mar
        • RE: automatically incrementing an int valueKeith C. Ivey12 Mar
          • RE: automatically incrementing an int valueDouglas B. Jones12 Mar
          • RE: automatically incrementing an int valuePaul DuBois12 Mar
RE: automatically incrementing an int valueAlec.Cawley12 Mar
  • RE: automatically incrementing an int valueDouglas B. Jones12 Mar