×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

incrementing a column without having to query the db first

incrementing a column without having to query the db first

incrementing a column without having to query the db first

(OP)
I'm fairly new to mysql. I have a table with 1 unique/primary column and another called user_id that is unique but doesn't auto increment. When I add someone to the database, I don't know how to increment user_id without querying the db and find the last value first.

RE: incrementing a column without having to query the db first

Set up that field/column as auto increment in the table definition. When you insert a record, just poke a zero in the field/column and the correct auto-incremented value will appear.

RE: incrementing a column without having to query the db first

I agree with spamjim, but also wonder whether your primary key already is an auto_increment column and you try to have two auto_increment columns - MySQL doesn't support that.

Chriss

RE: incrementing a column without having to query the db first

Oops...Chris is correct to notice that. I skimmed the question too quickly and misread. What's the point of having two unique columns? You've already got your unique user_id in the primary column. Get rid of the second user_id column.

RE: incrementing a column without having to query the db first

The primary key might be something else, I just thought I also cover that case. But I also can't imagine a case where you want or need that.

Chriss

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close