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 8493281
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T22:57:40+00:00 2026-06-10T22:57:40+00:00

I have created a tickets table that holds ID’s for everything so they can

  • 0

I have created a tickets table that holds ID’s for everything so they can all be unique. The tickets table is inserted with new data BEFORE insert on other tables. I need to put the ID that was generated in the tickets table into other tables in one fell swoop.

Here’s how it will run;

  1. Query to insert data into table1
  2. Trigger insert of the ref and an auto incremented ID in tickets
  3. ID from tickets inserted back into table1 as well as the data from the first query.
  4. More goes on after this but that’s sorted.

Here’s what I have so far.

delimiter |

CREATE TRIGGER status_ref BEFORE INSERT ON status
FOR EACH ROW BEGIN
 INSERT INTO tickets SET ref = S;

 END;
|

delimiter ;
  • 1 1 Answer
  • 0 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-10T22:57:41+00:00Added an answer on June 10, 2026 at 10:57 pm

    I recommend you rethink your numbering scheme: Right now, you are double-linking: The tickets table refers to the details via ref, and the details table refers to the tickets table via its ID.

    This is not a good idea: Think of a later update to one of the tables, that desynchronizes this double link: Either you disallow that, which renders the second number absolutely meaningless, or you allow it, in which case you end up with different results depending on which field you use for a JOIN.

    You should chose a numbering scheme with one leading table – I personally would simply drop the requirement to link tickets.ID back into the details table.

    Edit

    Seems this was a misunderstanding of my part as for the meaning of the ref field – judging by the other comment, I was not alone with this.

    If the ref field carries information about the type of reference only, you have an easy option: create an additional field refID on the tickets table, that stores the (auto incrementing) ID field of the details table. You would need something like

    ALTER TABLE tickets ADD COLUMN refID INT NOT NULL;
    
    -- the following only if you not already have it
    ALTER TABLE status ADD COLUMN ID INT AUTO_INCREMENT PRIMARY KEY;
    
    CREATE TRIGGER status_ref BEFORE INSERT ON status
    FOR EACH ROW BEGIN
     INSERT INTO tickets SET ref = S, refID=NEW.ID;
    END;
    

    This stores the detail-table ID in the tickets table.

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

Sidebar

Related Questions

I have a table of tickets, common_ticket, with a column called creation_date, which holds
Okay, so i have created a new support ticket system, but in my ticket
I have some items called tickers which can be created and subscribed to. When
I have created some JQuery that will expand a div 'popup' on hover and
I have created an android application that calls (using kSOAP library) a SOAP based
I have created a function that shows/hides different messages according to a combination of
I have started this support ticket project where users can create tickets and the
I have two models that can have tags added to them. Player Ticket and
I have a table of People, and a table of Service Tickets. Service Tickets
I have a form that I created with rows of input fields that are

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.