简体   繁体   中英

How to make auto-increment INSERT INTO statements?

I really don't know how to explain this very well. This is the piece of code I'll be using as an example to help show what I need help with:

INSERT INTO _increment

(`user_id`, `group_id`, `alias`, `hash`, `function_id`, `value`, `notes`)

VALUES 

('262', NULL, NULL, 'john1', 'wewbsite.ca/', NULL, '0');

So this will make a new entry with the hash "john1". What I need, though, is for "john1" to become "john2" on the next entry, automatically. Like, the first time it runs, it's "john1", the second time, it's "john2", then "john3", and so on. How do I do this?

Thank you.

I see two ways :

First : If you don't really need this column format, you should probably consider the fact to autoincrement a numeric column and concatenate the name (John) and this column to get this result (JohnX).

Second : But if you really need to get the exact name in this column because your boss want it like this, you should deal with SELECT LAST(column_name) FROM table_name; then parse it in your code to get the id and insert the result. But it's really not recommended.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM