Search the Community
Showing results for tags 'primary key'.
Found 2 results
I am constructing a table where it holds a many to many relationship with other 2 tables. This many-to-many table has 2 columns, both of which are foreign keys to 2 other tables. The many-to-many table is called favorites(it is self-explanatory what it does) and the parent tables are called business users and credentials.Here is an image: https://skydrive.live.com/redir?resid=BE27434B2AAC8130!259&authkey=!ADptTU72dh1KYBc&v=3 As I understand, and tell me if I am wrong, none of these 2 columns must be primary key. The reason being that a primary key must be unique in every row, but in a many -to-many table many times values are repeated throughout rows. For example, many orders placed by the same customer(not related with my app). So, am I right saying that none of the columns must be a primary key? In addition, now that I am reconsidering things, maybe a many to many table is not needed, just one-to-many, from credentials to favorites. Since the credentials table holds all the id's of the users of the site.
I am working on a blog for a friend's website. Upon testing the database which holds her blog posts (for security issues and whatnot), and dropping random rows from it, I have noticed that the id field does not re-organize itself. The way I will be displaying her posts (5 per page, with previous and next buttons) depends on the id being in order and with no gaps. Is there any way I can put in a script using PHP or MySQL to organize these in case of a row being removed once the blog goes live? Also, I have noticed that I can put in one entry, drop it, and then when I test another one the id starts back at 2. The only way to get it to start at 1 again that I have seen is going into PHPmyAdmin and emptying the table. Thanks,Mark