Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7732855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T06:50:10+00:00 2026-06-01T06:50:10+00:00

I currently have a table with an id column that is being autoincremented and

  • 0

I currently have a table with an id column that is being autoincremented and then there’s a tracking_code column that has a unique constraint on it.

Currently the tracking_code is being supplied by the person signing up, but now the client wants that tracking_code to be auto-generated yet be changeable as well.
In other words, where a user signs up, auto-generate the tracking_code, but allow the user to update that code to anything else as long as it stays unique.

Is it possible to do something like this in MySQL (append a string to an autoincremented id which only exists after the record is inserted) or is there another way of doing it in mysql:

INSERT INTO mytable (…, tracking_code, …) VALUES (…, ‘foo-‘ + id + ‘-bar’, …)

  • 1 1 Answer
  • 2 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T06:50:11+00:00Added an answer on June 1, 2026 at 6:50 am

    You can do this:

    INSERT INTO mytable
      (..., tracking_code, ...)
    VALUES (
      ...,
      CONCAT(
        'foo-',
        (
            SELECT
                AUTO_INCREMENT
            FROM
                information_schema.TABLES
            WHERE
                TABLE_SCHEMA = 'database'
            AND TABLE_NAME = 'mytable'
        ),
        '-bar'
      ),
      ...
    )
    

    Or

    INSERT INTO mytable
    SET tracking_code = CONCAT(
        'foo-',
        (
            SELECT
                AUTO_INCREMENT
            FROM
                information_schema.TABLES
            WHERE
                TABLE_SCHEMA = 'database'
            AND TABLE_NAME = 'mytable'
        ),
        '-bar'
    ),
    ...
    

    Obviously only works if you have an AUTO_INCREMENT column.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently I have a User table that has a toys_owned column that is an
I currently have a table which only has a single editable column. I have
I have a 2 column table with 2 IDs, each pair being unique. I
I currently have a table with a repeater that is being filled with data
I have an application in which I'm currently using a two column table in
I currently have a table structure that looks something like this(some details omitted): ColumnName
Say I have a table with a unique positive integer field. I currently have
I'm trying to normalize a mysql database.... I currently have a table that contains
I currently have a table with a column as varchar . This column can
I have a SQlite3 table that has typeless columns like in this example: CREATE

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.