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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:07:29+00:00 2026-05-28T07:07:29+00:00

create table [User] ( UserId int primary key identity(1,1), FirstName nvarchar(256) not null, LastName

  • 0
create table [User]
(
    UserId int primary key identity(1,1),
    FirstName nvarchar(256) not null,
    LastName nvarchar(256) not null,
)

create table Product
(
    ProductId int primary key identity(1,1),
    UnitPrice decimal(18,2) not null, //For catalog purposes.
    Name nvarchar(1000) not null,
    Description nvarchar(max) not null,
    Stock int not null
)

create table [Order]
(
    OrderId int primary key identity(1,1),
    UserId int foreign key references [User](UserId),
    ProductId int foreign key references Product(ProductId),
    UnitCost decimal(18,2) not null, //How much it actually cost when the person bought it.
    ItemCount int not null,
    Subtotal decimal(18,2) not null
)

create table OrderDetail
(
    OrderDetailId int primary key identity(1,1),
    ?

I’m stuck on the database design of the order system.

A user can choose n products to add to a order request. Any suggestions?


Following some advice given here, how would this feel? Any pitfalls?

create table [User]
(
    UserId int primary key identity(1,1),
    FirstName nvarchar(256) not null,
    LastName nvarchar(256) not null,
)

create table Product
(
    ProductId int primary key identity(1,1),
    UnitPrice decimal(18,2) not null,
    Name nvarchar(1000) not null,
    Description nvarchar(max) not null,
    Stock int not null
)

create table [Order]
(
    OrderId int primary key identity(1,1),
    UserId int foreign key references [User](UserId),
    DateOfOrder datetime not null
)

create table OrderDetail
(
    OrderDetailId int primary key identity(1,1),
    OrderId int foreign key references [Order](OrderId),    
    ProductId int foreign key references Product(ProductId),
    UnitCost decimal(18,2) not null,
    ItemCount int not null,
    Subtotal decimal(18,2) not null
)
  • 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-05-28T07:07:30+00:00Added an answer on May 28, 2026 at 7:07 am

    Typically, you’d have the Order table with the top-level order information (who, when etc) and then an OrderItem (or OrderDetail) table which has a row for each product that forms part of the order including columns like:

    OrderId
    ProductId
    Quantity
    etc
    

    Good candidate for a PK on this OrderItem/OrderDetail table would be on OrderId + ProductId.

    So where you have columns like ProductId, UnitCost, ItemCount etc in the Order table, those are in the wrong place and should be in the OrderItem/OrderDetail table.

    Update:
    To set up a compound PK, you can do:

    create table OrderDetail
    (
        OrderId int foreign key references [Order](OrderId),    
        ProductId int foreign key references Product(ProductId),
        ...other columns...,
        CONSTRAINT PK_OrderDetail PRIMARY KEY(OrderId, ProductId)
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this sql statement: CREATE TABLE [dbo].[User]( [UserId] [int] IDENTITY(1,1) NOT NULL, [FirstName]
CREATE TABLE [dbo].[user]( [userID] [int] IDENTITY(1,1) NOT NULL, [fcode] [int] NULL, [scode] [int] NULL,
This is a dummy script : create table #tempLogs ( UserId int identity(1,1) primary
I have the following table: CREATE TABLE FE_USER ( userid int identity (321,4) CONSTRAINT
Consider the following database schema: create table UserGroup ( id int not null auto_increment,
is something like that possible ? CREATE TABLE [dbo].[T_ALERT]( [id] [bigint] NOT NULL IDENTITY(1,1),
Consider the following SQL: CREATE TABLE USER1 ( pkUSER1_ID INT UNSIGNED NOT NULL AUTO_INCREMENT,
Ok, I have two MYSQL tables: CREATE TABLE `sessions` ( `id` int(11) NOT NULL
Here's the scenario: I have 2 tables: CREATE TABLE dbo.API_User ( id int NOT
There is a table: create table table1 ( id integer primary key, user_id varchar(36),

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.