Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can i use a foreign key where no pr

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Can i use a foreign key where no primary key has been declared?
 
Every table should have a key (which can one, several or all of the fields in the table). That is actually a rule for a relational database. Admittedly Access does not enforce this but you would be silly not to design things this way.

Anyway that is beside the point.A foreign key is just a data item in another table, or a set of data items, that you can use to join.

Put it another way. A foreign key is the list of items you wil put in your INNER JOIN..ON or WHERE T1.x=T2.y SQL statements to create a query. Alternatively, the lines you draw in the QBE Design view.

As long as you can do one of these things, SQL will run and you will get some results.

Remember the primary key is not necessarily the only key. Many times other combinations of data fields uniquely identify a record so you are free to join on those and will get identical results.

Remember you have a primary key (or not) irrespective of whether you tell Access about it. Some table design aspects are for internal reasons eg the table will be 'ordered' on a primary key if you declare one. (Note the relational model says records are always unordered so you shouldn't really rely on this Access feature). Also Access creates an index.

None of this matters as far as whether you have a foreign key. That simply depends on whether you have a set of fields you can use to formulate a join, as I've mentioned. mike.stephens@bnpparibas.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top