mysql adding id
- Started
- Last post
- 10 Responses
- jpea
is there a way to add a row in an existing table and populate each entry with sequential id's?
- maximillion_0
create the column then use a for or foreach loop and insert the values
- Rickbass0
Or just set up the ID column to 'auto_increment' and add your data as normal. Means there's no risk of duplicate IDs.
- akoni0
Or just set up the ID column to 'auto_increment' and add your data as normal. Means there's no risk of duplicate IDs.
Rickbass
(Feb 1 07, 11:24)and set it to int
- ETM0
Or just set up the ID column to 'auto_increment' and add your data as normal. Means there's no risk of duplicate IDs.
Rickbass
(Feb 1 07, 11:24)---
I agree. Every database should be setup with an ID column regardless... just good practice.
- jpea0
hmm, just realized that phpmyadmin did this once you add the id row with auto_increment checked. nice.
this was imported as a csv so it wasn't setup correctly to begin with, but now that'll change :)
thanks folks!
- maximillion_0
an id column is not always necessary and not good practice
- flavorful0
Not on link tables maximillion, you can go overkill on Identity fields, however, more often than not they are needed.
They help with querying as well as they link better together with other tables (link tables) to reduce text searching to a mininum.
t_Thread.cde_Thread (Unqiue ID)
t_Thread.txt_Thread (Title of Thread)t_Post.cde_Post (Unique ID)
t_Post.txt_Post (Content of Post)t_Thread_Post_Link.cde_Thread
t_Thread_Post_Link.cde_PostHow the two are connected, which house each uniquely.
- maximillion_0
I understand the use of linked tables flavorful, but you are better off searching for a unique identifier in the actual data rather than using id as best practice.
- jpea0
the issue with this particular case though is that the user can change any or all of the attributes of the row, but the id stays the same so that it can be updated to that particular row if things change. not sure if that changes things though, as i'm not very schooled with php/mysql
- maximillion_0
jpea sounds good...just dont assume it as best practice...