List:General Discussion« Previous MessageNext Message »
From:Alec.Cawley Date:July 1 2005 2:14pm
Subject:Re: Primary Key question
View as plain text  
"Haisam K. Ido" <haisam@stripped> wrote on 01/07/2005 15:04:01:

> 
> I've created the following table (server 4.1 in win2k)
> 
> CREATE TABLE `os` (
>    `id` tinyint(10) NOT NULL auto_increment,
>    `name` varchar(255) NOT NULL default '',
>    `description` varchar(255) default NULL,
>    PRIMARY KEY  (`id`,`name`)
> ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
> 
> and was very surprised that I can do the following twice.  Should'nt 
> this be rejected since name is a primary key ad has already been used?
> 
> INSERT INTO os (name,description) VALUES ( 'winxp','winxp');

No. What you have requested is that the combination of id AND name be 
unique. Since id is auto-increment, every record will be unique unless you 
manually force the id to an old value. I guess you want the values to be 
separately unique, in which case you want
PRIMARY KEY (id), UNIQUE (name) 

        Alec


Thread
Primary Key questionHaisam K. Ido1 Jul
  • Re: Primary Key questionAlec.Cawley1 Jul
Re: Primary Key questionHaisam K. Ido1 Jul
  • error 99(?) : can't connect to MySQL serverFagyal Csongor6 Feb
    • Re: error 99(?) : can't connect to MySQL serverNils Meyer6 Feb
      • Re: error 99(?) : can't connect to MySQL serverFagyal Csongor6 Feb