auto increment single field
Posted March 17th, 2009 by WilliamCarrier
Log from IRC server Freenode (IPv6) channel #SQL.
| <me> | I have a table which only has an auto incremented ID, usually I'd have a second field in which I'd insert some content then fetch the new ID with PHP mysql_insert_id() and use that but in this case I really don't need to have that second field to get the new ID ; is there a way to do the same without another field or without fetching the max ID ? |
| <||cw> | me: try INSERT xx VALUES ( NULL ) |
| <me> | ||cw: xx is a made up field right ? |
| <||cw> | me: table name |
| <||cw> | field list is optional |
| <||cw> | though might have to give it in this case |
| <||cw> | also, MSSQL has a DEFAULT keyword, maybe mysql has same or similar |
| <me> | ||cw: so I might have to create a bogus field ? |
| <||cw> | no |
| <||cw> | INSERT mytable ( counrerfield ) VALUES ( NULL ) |
| <||cw> | or INSERT mytable ( counrerfield ) VALUES ( DEFAULT ) |
| <me> | ||cw: counrerfield is the auto incremented right ? |
| <||cw> | yeah |
| <me> | ||cw: thank :) |
| <||cw> | not sure I see the point though |
| <me> | ||cw: it's referenced by another table |
| <||cw> | do you need some form of globaly unique ID? |
| <||cw> | well, put the autonumber in that table and be done with it |
| <me> | ||cw: it have different languages |
| <||cw> | still don't get it, seems over-normalized |
| <me> | ||cw: I've retaken a system which normally has informations attached to the table with now only has the ID |
| <me> | sorry for the delay I wasn't notified without my nick |
| <||cw> | so obsolete the table |
| <me> | ||cw: it's quicker for cleanup |
| <me> | it deletes the referenced tables |
