VB.Net & Access - Set two foreign keys, that refer

2019-08-26 06:02发布

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条回答
smile是对你的礼貌
2楼-- · 2019-08-26 06:37

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.

查看更多
登录 后发表回答