Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unique constraint on multiple fields in Access 2003

I have not found any answer regarding my question, all unique constraint questions did not involve MS Access.

The question is how to make a unique constraint on multpile fields in MS Access 2003 database?

If my table consists of columns id, A, B, C, D, E, F. I have an index on column id, but I would like to have a unique constraint set on both columns A and B. Hence, I may have a duplicate value in column A, provided the value in column B are different.

I want to stress that I am not interested in a workaround like creating new column with concatenated values from columns A and B, and creating a constraint on this column.

like image 278
MPękalski Avatar asked Apr 12 '11 13:04

MPękalski


People also ask

How do you get unique constraints on multiple columns?

To define a UNIQUE constraint, you use the UNIQUE keyword followed by one or more columns. You can define a UNIQUE constraint at the column or the table level. Only at the table level, you can define a UNIQUE constraint across multiple columns.

Can unique key have multiple columns?

A unique key is a set of one or more than one fields/columns of a table that uniquely identify a record in a database table. You can say that it is little like primary key but it can accept only one null value and it cannot have duplicate values.

Can a unique key be multiple?

A table can have more than one unique key unlike primary key. Unique key constraints can accept only one NULL value for column. Unique constraints are also referenced by the foreign key of another table.

How many columns can hold unique constraints?

You can create a UNIQUE constraint on one or more columns of a table.


1 Answers

If you want to do it through the UI, open the table in design view. Open the indexes window. Enter a new index name, identify column A, mark the index as Unique. Then add a second row below that one, don't specify the index name on that row, and identify column B. Close the indexes window and save the table.

You now have a unique index on columns A and B. E.g. my unique index on A & B is called Boris here:

enter image description here

like image 50
Damien_The_Unbeliever Avatar answered Oct 09 '22 06:10

Damien_The_Unbeliever