westnyorai Posted April 8, 2006 Share Posted April 8, 2006 I'm wondering what exactly key assignments do. Can't you just create the ER diagram without using Primary and Foreign keys?I can easily make a PHP statement that will link two databases together with just ID numbers.Like...Table: tableAid: INTname: VARCHARtableBLink: INTtableABtableAid: INTtableBid: INTtableB:id: INTname: VARCHARdesc: VARCHARif you simply need a database to connect them, I don't see what primary and foreign keys really do. I understand Unique keys though, but I don't get what UC_Fieldname(fieldname) is for.Any insights? Quote Link to comment https://forums.phpfreaks.com/topic/6915-primary-and-foreign-keys-and-unique/ Share on other sites More sharing options...
fenway Posted April 9, 2006 Share Posted April 9, 2006 That's a two part question. First, PRIMARY keys are used by the DB to uniquely identify each record in a table -- in your example, the ID column would be an excellent choice. This is almost always necessary, especially for any lookups to find said ID. Without an index, the DB would have to scan each and every row of the table to find the id in question. Obviously, PRIMARY keys must be unique; however, you can make a similar index on any other column, unique or not.As for foriegn keys, you're somewhat correct -- you need not establish this link explicity in the DB (e.g. via InnoDB tables) just to query to two tables. However, you'd be hard pressed to enforce referential integrity without them, or ensure ACID-compliant transactions. Quote Link to comment https://forums.phpfreaks.com/topic/6915-primary-and-foreign-keys-and-unique/#findComment-25289 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.