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
> -----Original Message-----
> From: Dušan Pavlica [mailto:pavlica@stripped]
> Sent: June 29, 2010 11:26 AM
> To: Victor Subervi
> Cc: mysql@stripped
> Subject: Re: Two Primary Keys
> 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)
> 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.
> Victor Subervi napsal(a):
> > 2010/6/29 João Cândido de Souza Neto
> >> As far as I know, if you have an auto_increment primary key, you cant
> >> 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
> > 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=1
> 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