You would use a concept called auto-increment, and you can create it when
you create your tables:
CREATE TABLE animals (
id MEDIUMINT NOT NULL AUTO_INCREMENT,
name CHAR(30) NOT NULL,
PRIMARY KEY (id)
);
More information here:
http://www.mysql.com/doc/en/example-AUTO_INCREMENT.html
-----Original Message-----
From: news [mailto:[EMAIL PROTECTED] On Behalf Of Linus Nikander
Sent: Tuesday, February 10, 2004 8:31 AM
To: [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Subject: Autocolumn and pk
I'm pretty new to mySQL so there might be an easy way of solving this
(hopefully)
Is there a way to create something akin to an Oracle Sequence in mySQL ?
I know of the autonumber feature. The problem is that the table that will be
using the key won't actually be using it as a unique pk. The pk will instead
consist of the autonumber + the value of another column. Thus, using
autonumber on a column of the target table isn't really an option.
I can think of one way of solving it. I could create a table with a single
autonumber column for the sole purpose of generating the numbers (when i
need them). That is going to clutter up my tables in the long run though,
and isn't really something I want to do. Is that the only viable solution,
or is there some functionality that I don't know of which does it better ?
//Linus Nikander - [EMAIL PROTECTED]
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]