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

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

问题描述

我们希望使用多列唯一索引来防止MS访问数据库中的记录重复。由于数据如何通过网络发送,有时会收到重复的数据。数据源不发送唯一的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.

根据唯一索引设计指南


使用多列唯一索引,
索引保证索引键中每个
的值都是唯一的。
例如,如果一个唯一索引是$ last $,
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访问数据库上创建多列唯一索引吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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