如何制作复合唯一索引? [英] How to make composite unique index?

查看:128
本文介绍了如何制作复合唯一索引?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道可以通过按住

控制键并选择多个字段来制作复合主键,然后右键单击并选择
键。但我听说这不是一个好主意。我想要什么

要做的是使用表约束来确保只有唯一的交易 - 由金额,日期,账户和客户的组合定义

- 输入到

表,同时将AutoNumber Transaction_ID保留为PK

索引中的唯一字段。但是如何定义复合唯一索引?


提前致谢。

I understand it''s possible to make a composite Primary Key by holding down
the control key and selecting multiple fields, then right-clicking and
selecting Primary Key. But I''ve heard that''s not a good idea. What I want
to do is use table constraints to ensure only unique transactions - defined
by a combination of amount, date, account and customer - are entered in the
table while leaving the AutoNumber Transaction_ID the sole field in the PK
index. But how do I define a composite unique index?

Thanks in advance.

推荐答案


" deko" < www.clearpointsystems.com@use_contact_form.com>写在

消息新闻:BL ****************** @ newssvr21.news.prodigy.c om ...

"deko" <www.clearpointsystems.com@use_contact_form.com> wrote in
message news:BL******************@newssvr21.news.prodigy.c om...
我理解,可以按
制作复合主键,按住控制键并选择多个字段,然后右键单击
并选择主键。但我听说这不是一个好主意。我想要做的
是使用表约束来确保只保留唯一的交易 -
由金额,日期,账户和客户的组合定义 - 在表中输入
,同时保留AutoNumber Transaction_ID PK索引
中的唯一字段。但是如何定义复合唯一索引呢?

提前致谢。
I understand it''s possible to make a composite Primary Key by holding down the control key and selecting multiple fields, then right-clicking and selecting Primary Key. But I''ve heard that''s not a good idea. What I want to do is use table constraints to ensure only unique transactions - defined by a combination of amount, date, account and customer - are entered in the table while leaving the AutoNumber Transaction_ID the sole field in the PK index. But how do I define a composite unique index?

Thanks in advance.




您可以使用GUI或SQL。


GUI:


- 在设计视图中打开表格。

- 点击密钥QUOT;工具栏上的符号。

- 在出现的对话框中,为索引命名,然后选择

哪些列将成为其中的一部分。

- 关闭对话框。

- 添加到索引中的每个列现在将在最左边的位置显示key

符号它的行。

SQL


CREATE TABLE YourTable

(金额LONG

,YourDate DATETIME

,账户LONG

,客户LONG

,CONSTRAINT pk_YourTable PRIMARY KEY

(金额

,YourDate

,账号

,客户)



此致,


Chris O.



You can use the GUI or SQL.

GUI:

--Open the Table in Design View.
--Click on the "key" symbol on the toolbar.
--In the dialog box that appears, name the index, and then select
which columns will be a part of it.
--Close the dialog box.
--Each column that was added into the index will now display a "key"
symbol at the leftmost of its row.
SQL

CREATE TABLE YourTable
(Amount LONG
,YourDate DATETIME
,Account LONG
,Customer LONG
,CONSTRAINT pk_YourTable PRIMARY KEY
(Amount
,YourDate
,Account
,Customer)
)
Sincerely,

Chris O.


> - 在设计视图中打开表。
> --Open the Table in Design View.
- 单击键键。工具栏上的符号。
- 在出现的对话框中,为索引命名,然后选择
哪些列将成为其中的一部分。
- 关闭对话框。
- 添加到索引中的每个列现在将在其最左侧显示一个键
符号。
--Click on the "key" symbol on the toolbar.
--In the dialog box that appears, name the index, and then select
which columns will be a part of it.
--Close the dialog box.
--Each column that was added into the index will now display a "key"
symbol at the leftmost of its row.




hmmm ......我想我明白你的意思。我正在使用Access 2003,所以

或许可以解释差异(?)


- 在设计视图中打开表格

- 点击工具栏中的闪电图标

- 在索引中对话框输入索引名称

- 选择将成为索引一部分的字段


索引对话框如下所示:


索引名称。 。 。字段名称。 。 。排序订单

MyIndex金额升序

TxDate升序

账户升序



>
- 在

对话框的索引属性部分(底部)中,选择是和是。对于Unique

- 关闭对话框并关闭表格,保存关闭

- 表格字段左侧将显示没有关键图标


这是正确的吗?



hmmm... I think I understand what you meant. I''m using Access 2003, so
perhaps that accounts for the differences (?)

--Open the table in design view
--Click on the lightning bolt icon in the toolbar
--In the "Indexes" dialog enter an Index Name
--Select the fields that will be part of the index

The Indexes dialog will look like this:

Index Name . . . Field Name . . . Sort Order
MyIndex Amount Ascending
TxDate Ascending
Account Ascending
etc.

--In the Index Properties section (bottom) of the
dialog, Select "Yes" for Unique
--Close the dialog and close the table, saving on close
--No key icon will appear to the left of the table field

Is this correct?


" deko" < www.clearpointsystems.com@use_contact_form.com>写在

新闻:ui ***************** @newssvr21.news.prodigy.co m:
"deko" <www.clearpointsystems.com@use_contact_form.com> wrote in
news:ui*****************@newssvr21.news.prodigy.co m:
- 在设计视图中打开表格。
- 点击键键。工具栏上的符号。
- 在出现的对话框中,为索引命名,然后选择哪些列将成为其中的一部分。
- 关闭对话框。
- 添加到索引中的每个列现在将显示
一个键。在它的最左边的符号。
--Open the Table in Design View.
--Click on the "key" symbol on the toolbar.
--In the dialog box that appears, name the index, and then
select which columns will be a part of it.
--Close the dialog box.
--Each column that was added into the index will now display
a "key" symbol at the leftmost of its row.



嗯...我想我明白你的意思。我正在使用Access
2003,所以也许可以解释差异(?)

- 在设计视图中打开表格
- 点击闪电图标在工具栏中
- 在索引中对话框输入索引名称
- 选择将成为索引一部分的字段

索引对话框将如下所示:

索引名称。 。 。字段名称。 。 。排序顺序
MyIndex数量升序
TxDate升序
账户升序

- 在
对话框,选择是对于Unique
- 关闭对话框并关闭表格,保存关闭
- 表格字段左侧将显示无键图标

这是正确的吗?



hmmm... I think I understand what you meant. I''m using Access
2003, so perhaps that accounts for the differences (?)

--Open the table in design view
--Click on the lightning bolt icon in the toolbar
--In the "Indexes" dialog enter an Index Name
--Select the fields that will be part of the index

The Indexes dialog will look like this:

Index Name . . . Field Name . . . Sort Order
MyIndex Amount Ascending
TxDate Ascending
Account Ascending
etc.

--In the Index Properties section (bottom) of the
dialog, Select "Yes" for Unique
--Close the dialog and close the table, saving on close
--No key icon will appear to the left of the table field

Is this correct?




差不多。


- 在

对话框的索引属性部分(底部) ,选择是小学


-

Bob Quintal


PA是你我改变了我的电子邮件地址。



Almost.

--In the Index Properties section (bottom) of the
dialog, Select "Yes" for Primary

--
Bob Quintal

PA is y I''ve altered my email address.


这篇关于如何制作复合唯一索引?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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