@Dušan Pavlica;

I must say thank you.  
This is really interesting, and in the 7 years I've been using mysql and sql, 
I've never know this (or had, but didn't realize what I had done).
This little bit of information could make for some interesting changes to a 
couple of my projects I am working on, where I've done this, but done it in 
code, rather than in mysql.


Steven Staples


> -----Original Message-----
> From: Dušan Pavlica [mailto:pavl...@unidataz.cz]
> Sent: June 29, 2010 11:26 AM
> To: Victor Subervi
> Cc: mysql@lists.mysql.com
> Subject: Re: Two Primary Keys
> 
> Hi,
> 
> try this and you will see exactly how autoincrement behaves in MyISAM
> tables when it is part of primary key.
> 
> 1) declare table like this:
> CREATE TABLE  `test_tbl` (
>   `field1` int(10) unsigned NOT NULL default '0',
>   `field2` int(10) unsigned NOT NULL auto_increment,
>   `field3` char(10) NOT NULL default '',
>   PRIMARY KEY  (`field1`,`field2`)
> ) ENGINE=MyISAM;
> 
> 2) then insert some values
> INSERT INTO test_tbl (field1, field3)
> VALUES(1,'test1'),(2,'test2'),(1,'test3'),(2,'test4');
> 
> 3) see what's in the table
> SELECT * FROM test_tbl ORDER BY field1;
> 
> result is:
> 1, 1, 'test1'
> 1, 2, 'test3'
> 2, 1, 'test2'
> 2, 2, 'test4'
> 
> field2 is unique only in context of  field1.
> 
> Hth,
> Dusan
> 
> 
> 
> Victor Subervi napsal(a):
> > 2010/6/29 João Cândido de Souza Neto <j...@consultorweb.cnt.br>
> >
> >
> >> As far as I know, if you have an auto_increment primary key, you cant
> have
> >> any other field in its primary key.
> >>
> >>
> >
> > Makes sense. Actually, I was just copying what someone else gave me and
> > adding the auto_increment, then I got to wondering, what is the purpose
> of
> > having two primary keys?
> > TIA,
> > V
> >
> >
> 
> --
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe:    http://lists.mysql.com/mysql?unsub=sstap...@mnsi.net
> 
> No virus found in this incoming message.
> Checked by AVG - www.avg.com
> Version: 9.0.830 / Virus Database: 271.1.1/2917 - Release Date: 06/29/10
> 02:35:00


--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/mysql?unsub=arch...@jab.org

Reply via email to