> umm when i declare a unique constraint on 2 fields in a table like so
>
> unique (col1,col2),
>
> if i insert data into the table will it check them individually or as a
> composite?
>
> for example if i inserted the values
> col1  |   col2
>    1,         A
>    1,         B
>    2,         B
>    2,         A
>
> if the above unique constraint is declared will it give me errors when
> inserting?

No. A good way of finding out is trying :-)

mysql> create table test (col1 int not null, col2 char(1) not null, unique
(col1, col2));
Query OK, 0 rows affected (0.01 sec)

mysql> insert into test values (1, 'A');
Query OK, 1 row affected (0.00 sec)

mysql> insert into test values (1, 'B');
Query OK, 1 row affected (0.00 sec)

mysql> insert into test values (2, 'B');
Query OK, 1 row affected (0.00 sec)

mysql> insert into test values (2, 'A');
Query OK, 1 row affected (0.00 sec)

mysql> insert into test values (2, 'A');
ERROR 1062: Duplicate entry '2-A' for key 1

> neither col1 or col2 are a primary key but together they could be
> considered a composite candidate key pair


---------------------------------------------------------------------
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

Reply via email to