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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T05:31:39+00:00 2026-06-09T05:31:39+00:00

I am inserting into two tables. Into the first table goes a new ‘item’.

  • 0

I am inserting into two tables. Into the first table goes a new ‘item’. There are a lot of fields, but for simplicity I’ll only show you what I need. This is my coldfusion page:

<cfquery>
    INSERT INTO my_item_table (itemid, a bunch of other stuff)
    VALUES (itemid_sequence.nextval, a bunch of other stuff)
</cfquery>

My issue is I want to insert that auto-incremented itemid as a value into another table, a file-attachment table. The same coldfusion page:

<cfquery>
    INSERT INTO my_attachments_table (attachno, itemid, filename)
    VALUES (attachment_sequence.nextval, **AUTO-INCREMENT VALUE HERE**, '#url.fileName#')
</cfquery>

I know I could query the item table for the values that were just entered into the first table, but even though it’s not likely, there is a possibility that the user input isn’t unique, meaning a query of the same fields could return more than one row. In which case, I couldn’t get the itemid. The itemid created in the query is the only unique identifier.

My question is: is there a way to set the auto=increment to a value inside the query so I can use it outside? If not, how would you suggest getting my itemid? Thanks.

  • 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-09T05:31:41+00:00Added an answer on June 9, 2026 at 5:31 am

    You could start by retrieving the next sequence value into a variable with a query like this:

    SELECT itemid_sequence.nextval FROM DUAL
    

    (DUAL is a dummy table in Oracle). You could then proceed to use this variable in both INSERT queries.

    Another option: create a stored procedure in the database that will fire both queries for you.

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

Sidebar

Related Questions

Basically I'm trying to combine two tables together into a new table. The first
I have a table with two decimal(18,0) fields. I am inserting into this table,
I'm working with three tables, but only inserting into two( one called images, and
I have two tables that i am inserting records into. I am using PHP
I am inserting data into two tables, however I can not figure out (after
I have two separate tables already created and filled with info. The first table
I have a question about inserting column stored procedure into table. I have two
I've got a table that people have been inserting into getting the primary key
Before inserting data into table i need to check against duplicate records and report
When inserting values into my table what do I edit here? Do I delete

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.