List:General Discussion« Previous MessageNext Message »
From:Bruce Feist Date:April 4 2003 4:39pm
Subject:Re: Primary key
View as plain text  
Grégoire Dubois wrote:

> Victoria Reznichenko wrote:
>
>> On Friday 04 April 2003 15:37, Grégoire Dubois wrote:
>>
>>> In the following table, I declare ID as a PRIMARY KEY.  Is it then
>>> necessary to add the parameters NOT NULL AUTO_INCREMENT?
>>>
>>> CREATE TABLE company (
>>>    ID INT NOT NULL AUTO_INCREMENT,
>>>
>>>    name VARCHAR(30),
>>>
>>>    admin_ID INT,
>>>
>>>    PRIMARY KEY ID,
>>>    INDEX admin_ID,
>>> );
>>>
>>> Or can I just declare the table like that? Does creating a primary key
>>> on an int immediatly involve this one to be not null, and to
>>> auto-incrИment?   
>>
>>
>> NOT NULL - yes, but if you want to have AUTO_INCREMENT column you 
>> should declare it as AUTO_INCREMENT.
>
> Thank you very much for your reply.
> But I read that a PRIMARY KEY is a "globally unique identifier" for a 
> table. As it is an identifier, it should never be null (ok, that's 
> what you said), and it should be unique... Then, if I don't set 
> AUTO_INCREMENT to my column ID, it still should be unique, and then 
> increment itself... No? 

Not all unique identifiers are computer-generated.  If you leave off 
AUTO_INCREMENT but still make it a primary key, uniqueness will be 
enforced on whatever the application(s) enter(s) as the value, but 
nothing will be plugged in.

Bruce Feist


Thread
Conception - Tree - Recursivity -Address book - Query speedGrégoire Dubois2 Apr
  • RE: Conception - Tree - Recursivity -Address book - Query speedKevin Fries2 Apr
    • Re: Conception - Tree - Recursivity -Address book - Query speedGrégoire Dubois3 Apr
      • RE: Conception - Tree - Recursivity -Address book - Query speedKevin Fries3 Apr
  • Re: Conception - Tree - Recursivity -Address book - Query speedLeif B. Kristensen3 Apr
    • Primary keyGrégoire Dubois4 Apr
      • re: Primary keyVictoria Reznichenko4 Apr
        • Re: Primary keyGrégoire Dubois4 Apr
          • Re: Primary keyBruce Feist4 Apr
            • Re: Primary keyGrégoire Dubois5 Apr
Re: Primary keydpgirago5 Apr