卡住MS Access的表关系 [英] Got stuck with table relations for MS Access
问题描述
首先,我要感谢所有花时间查看此主题并尝试提供帮助的人。
我在MS Access中有3个表,它应该变为T,A1和A2。
应用程序,使用WIN32 API以C ++编写,有一个包含两个项目的菜单,标记为上面提到的表格(A1和A2)。
编辑#1:
************ ************************
当用户从菜单中选择2项中的一项时,表T中的特定列应该参考相应表的数据。
问题是数据不是简单的属性插入列,而是表A1或表A2,取决于用户的选择,这对我来说是一个问题。
我应该设计表之间的关系,但我不知道如何。
* ********************************
我应该提供主要和外国的钥匙来提及TA bles,但我不知道怎么做。
表A1和A2的值可以多次出现在表T中,但表T的值可以出现在表A1和表A1中A2只有一次,所以我猜两种情况都是1:N关系。
此外,我想我应该让T'的主键成为外键两个表(A1和A2)。
另外,在我看来,表A1和A2是弱实体,并且依赖于表T.
一个小的,即兴的图形帮助:
T< ------ A1(如果用户选择了选项) A1菜单)
^
|
|
A2(如果用户从菜单中选择选项A1)
所以我的问题是:
这3个表的正确关系是什么(外键,主键...)?
我应该介绍第四张表,如果是的话,应该是什么主键,外键......?
谢谢你,亲切。
< blockquote>我认为A1和T之间的关系是1:N(A1是1,T是N)以及A2和T之间的关系。
当用户选择A1时,用户可以从中选择数据T如下:
从T中选择* T.column1 in(从A1中选择A1.column1)
和类似于A2。
我将使用ADO查询MS Access数据库,但我只是不知道如何创建上述关系和表格。
如果您可以查询MS Access数据库,则可以使用sql语句创建表:创建表(MS Access) [ ^ ]。以同样的方式,您可以在表之间创建关系:如何:使用Access SQL定义表之间的关系 [ ^ ]
I would like to start by saying thanks to everyone who takes some time to view this thread and try to help.
I have 3 tables in MS Access, which shall be dimmed as T, A1, and A2.
Application, which was written in C++ using WIN32 API, has a menu with two items, labeled as same as the above mentioned tables ( A1 and A2 ).
EDIT #1:
************************************
When user selects one of 2 items from the menu ,specific column in table T should reference the corresponding table''s data.
The problem is that the data isn''t simple attribute to be inserted into column, but a table A1 or table A2, depending on the user''s choice, and that represents an issue for me.
I should design relations between tables, but I don''t know how.
*********************************
I should make primary and foreign keys to reference mentioned tables, but I do not know how.
Value from tables A1 and A2 can appear in table T many times, but value for table T can appear in tables A1 and A2 only once, so I guess it is 1:N relationship for both cases.
Furthermore, I guess I should make T''s primary key a foreign key for both tables ( A1 and A2 ).
Also, tables A1 and A2 are, in my opinion, weak entities, and depend on table T.
A small, improvised, graphical help:
T <------ A1 ( if user selected option A1 from menu )
^
|
|
A2 ( if user selected option A1 from menu )
So my question is:
What are proper relations for these 3 tables ( foreign key, primary key ... )?
Should I introduce 4th table, and if so, what should be primary key, foreign key... ?
Thank you,kindly.
I think the relationship between A1 and T is 1:N (A1 is 1, T is N) and also the relationship between A2 and T.
When user selects A1, user can select data from T as below:
select * from T where T.column1 in (select A1.column1 from A1)
and the similar to A2.
I will use ADO to query MS Access database, but I just don''t know how to create above mentioned relations and tables.
If you can query MS Access database, you can create tables using sql statement: CREATE TABLE (MS Access)[^]. In the same way you can create relationships between tables: How to: Define Relationships Between Tables Using Access SQL[^]
这篇关于卡住MS Access的表关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!