VB.Net & Access - Set two foreign keys, that refer to the same table/field

旧时模样 提交于 2020-01-06 04:56:05

问题


I have an Access database where I want to store the contacts in a company: In this database I have a table named "users" where I keep the users which will have access to the database. In the main table, named "contacts", two of my fields "insert_user" and "contact_user" refer to the user who entered the contact information and the user who actually made the contact. The way I am thinking it, I will have to set both of the fields as foreign keys to the same table/field, namely "users"/"username".

So: I set two foreign key constrains in two different fields ("insert_user", "contact_user"), which refer to the same table/field ("users"/"username") in an Access database, using VB.Net OleDB (See the SQL Statement below)

ALTER TABLE contacts ADD CONSTRAINT insert_user_foreignkey FOREIGN KEY (insert_user) REFERENCES users (username)
ALTER TABLE contacts ADD CONSTRAINT contact_user_foreignkey FOREIGN KEY (contact_user) REFERENCES users (username)

I open the database with MS-Access. I see that all the tables are fine (as they should be).

However when I click on relationships at Access I get all my tables plus a table named users_1 connected to "contacts"/"contact_user" (the table users is only connected to "contacts"/"insert_user")

It is very strange that in the Table View of Access I don't see this table, but only in the Relationships View.

Questions

  • Is my thinking right (to set 2 foreign keys, that refer to the same table/field)?
  • What is this table "users_1"?
  • Will my database work or am I doing something wrong?

回答1:


This is the way that Access sets up relationships when a table is used more than once. If you added another relationship, it would be for users_2 and so on. This is only an alias, not a new table.



来源:https://stackoverflow.com/questions/5081055/vb-net-access-set-two-foreign-keys-that-refer-to-the-same-table-field

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!