设置两个字段的主键 [英] set two field primary key

查看:90
本文介绍了设置两个字段的主键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

table1

id1 ==>数字

id2 ==>数字

id希望id1包含唯一编号,而id2包含唯一编号.

id want id1 contain uniqe number and id2 contain unique number.

如何设置id1和id2 primary key?

how can set id1 and id2 primary key?

推荐答案

在表设计器中,选择两行,然后单击工具栏中的主键"按钮.

In the Table Designer, Select both rows, and then click the Primary Key button in the Toolbar.

或,打开查询设计器,将视图更改为SQL视图,然后键入以下代码:

OR, open the Query Designer, change the view to SQL View, and type the following code:

ALTER TABLE your_table_name ADD CONSTRAINT your_pk_name PRIMARY KEY(id1, id2);

然后,点击运行按钮.这将创建一个包含这两个字段的主键.

Then, hit the run button. This will create a Primary key which includes both of those fields.

如果您要在两列中都包含一个自动递增的整数字段,则不能.您将必须以编程方式执行该操作. Access(和大多数其他数据库)仅允许每个表使用一个自动编号"字段.

If you are asking about having an Auto-incrementing integer field in both columns, you can't. You would have to do that programmatically. Access (and most other db's) only allow one "autonumber" field per table.

这篇关于设置两个字段的主键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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