SitePoint Sponsor |
|
User Tag List
Results 1 to 5 of 5
-
Oct 12, 2003, 01:05 #1
Do you need an auto-increment id field?
I am quite good with php, and have made some cool apps, however, I have always made an id/auto-increment/unsigned/notnull/primary key field to start with all my tables just as a habit, and ive used that field before, but is it necessary? And, do I need a primary key? what does defining a field as primary actually do? Also, I know what happens when you make a field unique, but what is index?
AbcArcade.com - free internet games!
-
Oct 12, 2003, 01:29 #2
- Join Date
- May 2003
- Location
- Berlin, Germany
- Posts
- 1,829
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
You set up primary keys and indexes to allow faster sql querying. Auto-Increment is almost always needed, to make each data row unique. You could also use a TIME STAMP for that however.
-
Oct 12, 2003, 02:03 #3
well wouldnt each data row always be unique, unless you added all the same info as one?
AbcArcade.com - free internet games!
-
Oct 12, 2003, 03:15 #4
- Join Date
- May 2003
- Location
- Berlin, Germany
- Posts
- 1,829
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
How would you access a row then ? Data rows have to differ on at least one field, which would be the auto-incremented primary key.
-
Oct 12, 2003, 04:09 #5
- Join Date
- Mar 2002
- Location
- Svíþjóð
- Posts
- 4,080
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by DarkAngelBGE
Not always needed, but it's a very convenient way of getting unique values.
If you have a table containing names, for example, people can have same name, same address etc, i.e. could be really difficult to find the property that is different (OK, date of birth can be used...).
SQL by Design: How to Choose a Primary Key
Bookmarks