How to set initial value and auto increment in MySQL?
Use this: or if you haven’t already added an id column, also add it
Use this: or if you haven’t already added an id column, also add it
There is no such thing as “auto_increment” or “identity” columns in Oracle as of Oracle 11g. However, you can model it easily with a sequence and a trigger: Table definition: Trigger definition: UPDATE: IDENTITY column is now available on Oracle 12c: or specify starting and increment values, also preventing any insert into the identity column … Read more
You need to use the LAST_INSERT_ID() function: http://dev.mysql.com/doc/refman/5.0/en/information-functions.html#function_last-insert-id Eg: This will get you back the PRIMARY KEY value of the last row that you inserted: The ID that was generated is maintained in the server on a per-connection basis. This means that the value returned by the function to a given client is the first … Read more
You can reset the counter with: For InnoDB you cannot set the auto_increment value lower or equal to the highest current index. (quote from ViralPatel): Note that you cannot reset the counter to a value less than or equal to any that have already been used. For MyISAM, if the value is less than or equal to the maximum value … Read more
If you really need this you can achieve your goal with help of separate table for sequencing (if you don’t mind) and a trigger. Tables Now the trigger Then you just insert rows to table1 And you’ll have | ID | NAME | —————— | LHPL001 | Jhon | | LHPL002 | Mark | Here … Read more