David Johnston <[EMAIL PROTECTED]> wrote:
> I am starting to design a database in sql, to replace a flat file db.
>
> The database holds records, currenlty there is a new database for each
> record, so each record for each project starts with a id and increments.
>
> I want to create a sql database that will hold all records for all
> projects, so I'd like to have a primary key -
>
> xxx/xxxxx
>
> The first three digits would be the project ID, the following 5 digits
> would be the records unique number.
>
> Is it possilbe to create a field, that I can enter the first three
> digits, while the following 5 auto increment?
>
> The result would be that all projects would still have records starting
> from 1, and auto incrementing.
If I've got you right you should specify auto_increment on the secondary column of
multiple-column index:
http://www.mysql.com/doc/en/example-AUTO_INCREMENT.html
For example:
mysql> create table t1(
-> p_id int not null,
-> id int not null auto_increment,
-> primary key (p_id, id));
Query OK, 0 rows affected (0.07 sec)
mysql> insert into t1 values
-> (111,NULL),
-> (222,NULL),
-> (111,NULL);
Query OK, 3 rows affected (0.01 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql> select * from t1;
+------+----+
| p_id | id |
+------+----+
| 111 | 1 |
| 111 | 2 |
| 222 | 1 |
+------+----+
3 rows in set (0.01 sec)
--
For technical support contracts, goto https://order.mysql.com/?ref=ensita
This email is sponsored by Ensita.net http://www.ensita.net/
__ ___ ___ ____ __
/ |/ /_ __/ __/ __ \/ / Victoria Reznichenko
/ /|_/ / // /\ \/ /_/ / /__ [EMAIL PROTECTED]
/_/ /_/\_, /___/\___\_\___/ MySQL AB / Ensita.net
<___/ www.mysql.com
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]