我们可以在 MS Access 数据库上创建多列唯一索引吗? [英] Can we create multicolumn unique indexes on MS access databases?

查看:26
本文介绍了我们可以在 MS Access 数据库上创建多列唯一索引吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们希望使用多列唯一索引防止 MS Access 数据库中的记录重复.由于数据的发送方式(通过网络),有时会收到重复的数据.数据源不发送唯一ID,因此最简单的选择是防止插入重复记录.

We'd like to prevent record duplication in our MS access database using a multicolumn unique index. Because of how the data is sent (via network), duplicate data is sometimes received. The data source does not send a unique ID, so the simplest option is to prevent duplicate records being inserted.

根据唯一索引设计指南:

使用多列唯一索引,索引保证每个组合索引键中的值是唯一的.例如,如果唯一索引是在姓氏的组合上创建,FirstName 和 MiddleName 列,无表中的两行可能有这些值的相同组合列.

With multicolumn unique indexes, the index guarantees that each combination of values in the index key is unique. For example, if a unique index is created on a combination of LastName, FirstName, and MiddleName columns, no two rows in the table could have the same combination of values for these columns.

不过,这是针对 SQL 2005 的,所以我不确定是否可以使用 MS 访问.

This is for SQL 2005 however, so I'm not sure it's possible using MS access.

我想另一种可能是使用查询(伪代码):

I guess an alternative is to perhaps use the query (pseudo code):

insert into foobar (a, b, c) values ('x', 'y', 'z')
where (a <> 'x') and (b <> 'y') and (c <> 'z')

...但我觉得索引会更好.

... but I feel like an index would be better.

推荐答案

在 MS Access 的设计视图中打开表格,选择要设为唯一索引的三列,然后单击工具栏上的小键.主键(集合)中不能有空值.

Open the table in design view in MS Access, select the three columns that you want to make into the unique index, and then click the little key on the toolbar. You cannot have null values in a primary key (set).

这篇关于我们可以在 MS Access 数据库上创建多列唯一索引吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆