> I want to create a table with two Primary Keys. The first key is
> a category
> field, and the second is auto-incremented. Example: Key
> 1=Chapter name, Key
> 2 =section number. For example, (Chapter1, 1) (Chapter1, 2) (Chapter1, 3)
> then with a new Cheaper, I want to restart the auto-incremented field back
> to 1 (Chapter2, 1) (Chapter2, 2). How do I get the auto-incrementer to
> restart with each new chapter?
Try this:
mysql> CREATE TABLE test (chapter INT NOT NULL, section INT NOT NULL
AUTO_INCREMENT, PRIMARY KEY (chapter, section));
Query OK, 0 rows affected (0.00 sec)
mysql> INSERT INTO test (chapter) VALUES (1);
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO test (chapter) VALUES (2);
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO test (chapter) VALUES (2);
Query OK, 1 row affected (0.00 sec)
mysql> SELECT * FROM test;
+---------+---------+
| chapter | section |
+---------+---------+
| 1 | 1 |
| 2 | 1 |
| 2 | 2 |
+---------+---------+
3 rows in set (0.00 sec)
You can't have two primary keys, but you can have a single primary key on
two columns.
---------------------------------------------------------------------
Before posting, please check:
http://www.mysql.com/manual.php (the manual)
http://lists.mysql.com/ (the list archive)
To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php