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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:25:03+00:00 2026-06-13T00:25:03+00:00

I have a table of orders with orderID . I want when I create

  • 0

I have a table of orders with orderID. I want when I create a new row in orders, and automatically have it add the same orderID to a new row in orderDetails. I got the auto incrementing to work, however whenever I try to link the two, adding cascade delete, it gives me an error.

‘order’ table saved successfully
‘orderDetail’ table
– Unable to create relationship ‘FK_orderDetail_order’.
Cascading foreign key ‘FK_orderDetail_order’ cannot be created where the referencing column ‘orderDetail.orderID’ is an identity column.
Could not create constraint. See previous errors.

Which seems to be because of the fact there is no orderID at row creation. Without these two linked it’s pretty hard to link an order to its information.

I am using Microsoft SQL server mgt studio. I learned via command-line MySQL, not SQL, so this whole GUI stuff is throwing me off (and I’m a tad rusty).

  • 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-13T00:25:04+00:00Added an answer on June 13, 2026 at 12:25 am

    Your problem is that ‘orderDetail.orderID’ should not be an identity column (auto-incrementing). It should be based on the orderId in the Order table. You can do that in a variety of ways. If you are using stored procedures, and making separate calls to the database for the orderDetail records, have the code save the order row first, and return the newly created OrderId value, then use that value on the calls to save orderdetails. If you are making one call to a stored proc that saves the order header record and all order detail records in one call, then in the stored procd, insert the ordfer record forst, use Scope_identity() to extract the newly created orderId into a T-SQL variable,

      Declare @orderId Integer 
      Insert Orders([Order table columns]) 
      Values([Order table column values])
      Set @orderId = scope_Identity()
    

    and then use the value in @orderId for all inserts into the OrderDetails table…

      Insert OrderDetails(OrderId,  [Other OrderDetail table columns]) 
      Values(@orderId , [Other OrderDetail table column values])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables: orders and orders_items. Both sharing the field orderID. I want
If I have a table Orders with fields CustomerID , OrderID and OrderDate ,
I have an orders table with a schema like this. CREATE TABLE orders (
I got a table that saves executed purchase orders. For a report I want
I have two tables in MySQL sales database: Orders table: CREATE TABLE salestest.`orders` (
Suppose I have an Orders table in my database and a corresponding model class
I have a table of orders. the status is on the soilorders which is
I want to create an invoice of every 2 week. An invoice can have
Say I have a table with 3 cols: ActionId, uid & created. I want
I have created two tables ORDERS and ORDERITEMS with the following constraint: alter table

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.