Unique constraint on multiple fields in Access 2003

浪尽此生 提交于 2019-12-01 03:51:30

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:

In ANSI-92 Query Mode, execute this SQL DDL:

ALTER TABLE MyTable ADD 
   CONSTRAINT MyTable__key
      UNIQUE (A, B);

Using VBA in Access:

CurrentProject.Connection.Execute _
    "ALTER TABLE MyTable ADD CONSTRAINT MyTable__key UNIQUE (A, B);"
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!