如何在MS Access中创建唯一密钥 [英] how to create unique key in MS access

查看:166
本文介绍了如何在MS Access中创建唯一密钥的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,


我正在使用MS Access作为后端.我的表格结构是
{SId(数字),
PId(数字),
数量(个)
}
我想将SId + Pid设为唯一,即这两个密钥的组合不应重复.


1,1,5
1,2,5
它应该被接受.
但是
1,1,5
1,1,12
不应该接受

hello,


i am using MS Access as back end. my table structure is
{ SId (number),
PId (number),
Qty (number)
}
i want make SId+ Pid as unique,i.e combination of this both key should not repeat.

i.e
1, 1, 5
1,2, 5
it should be accept.
but
1,1,5
1,1,12
should not accept

how should be this done?

推荐答案

在我看来,您想为多对多关系创建一个相交表.我知道在Access中可以检查每列重复项,但不能检查列组合.

因此,如果要执行此操作,则必须在程序中的代码中执行此操作,或者在Access数据库中创建一个存储过程,以免添加它.
It sounds to me that you want to create an intersect table for a Many-to-Many relationship. I know that in Access there is the possibility of checking for duplicates per column but not a combination of columns.

So if you want to do this you''d have to do it in code within your program or make a stored procedure within the Access database to avoid it from being added.


您需要为此,请定义主键

1.在设计视图中打开表
2.选择列Sid,Pid
3.右键单击它,选择设置主


:)


更新1

您分配主键了吗?
按照上述步骤操作
无需分配唯一键

谢谢
You need to define primary key for that follow this steps

1. Open table in design view
2. Select both column Sid, Pid
3. rigth click on it, selct set primary


:)


Update 1

Have you assign primary key ?
by following above steps
there is no need to assign unique key

Thanks


这篇关于如何在MS Access中创建唯一密钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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