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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:47:09+00:00 2026-06-12T10:47:09+00:00

I have a table inheritance in my database. I have table Item and Table

  • 0

I have a table inheritance in my database. I have table “Item” and Table “Something“. Item has ItemId which is primary key and auto increment. In table Something I have ItemId which is primary key (not autoincrement). Theese tables are in 1:1 relation.
So I have tried to insert data in those tables but this doesn’t work:

...
DECLARE @itemId int

    INSERT INTO dbo.Items
    (ItemTypeId,UserId,CreatedOnDate,Title,Description)
    VALUES
    (@p_ItemTypeId,@p_UserId,@p_CreatedOnDate,@p_Title,@p_Description)

    SELECT @itemId = SCOPE_IDENTITY()

    INSERT INTO dbo.Something
    (ItemsId)
    VALUES
    (@itemId)
...

This is the error that I get:

The INSERT statement conflicted with the FOREIGN KEY constraint "FK_Items_Somethings".

Tables create script:

CREATE TABLE [dbo].[Items](
    [ItemdId] [int] IDENTITY(1,1) NOT NULL,
    [ItemTypeId] [int] NULL,
    [UserId] [int] NULL,
    [CreatedOnDate] [smalldatetime] NULL,
    [Title] [nvarchar](50) NULL,
    [Description] [nvarchar](max) NULL,

 CONSTRAINT [PK_Items] PRIMARY KEY CLUSTERED 
(
    [ItemId] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

ALTER TABLE [dbo].[Items]  WITH CHECK ADD  CONSTRAINT [FK_Items_Somethings] FOREIGN KEY([ItemId])
REFERENCES [dbo].[Somethings] ([ItemId])
GO

ALTER TABLE [dbo].[Items] CHECK CONSTRAINT [FK_Items_Somethings]
GO


CREATE TABLE [dbo].[Somethings](
    [ItemId] [int] NOT NULL,
 CONSTRAINT [PK_Somethings] PRIMARY KEY CLUSTERED 
(
    [ItemId] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
  • 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-12T10:47:14+00:00Added an answer on June 12, 2026 at 10:47 am
    ALTER TABLE [dbo].[Items]  WITH CHECK ADD  CONSTRAINT [FK_Items_Somethings] FOREIGN KEY([ItemId])
    REFERENCES [dbo].[Somethings] ([ItemId])
    

    Bad Direction of foreign key.

    You should add foreign key to [dbo].[Somethings] and reference [dbo].[Items].ItemId
    Like this:

    ALTER TABLE [dbo].[Somethings]  WITH CHECK ADD  CONSTRAINT [FK_Somethings_Items] FOREIGN KEY([ItemId])
    REFERENCES [dbo].[Items] ([ItemId])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a card-game application which makes use of Single Table Inheritance. I have
I have a rails app that requires multi-table inheritance for which I am using
I have a PostgreSQL 8.3 database where table inheritance is being used. I would
I have a legacy database that uses a table per class hierarchy inheritance strategy
I have table inheritance in database: Ticket{TicketId, TicketTypeId, CreatedBy, Title, Description etc.} UserInfo{TicketId etc.}
I have implemented inheritance for two parent classes called Table and Field . Each
I have table in which I am inserting rows for employee but next time
I have table of data that is sorted as follows: Item | Sample |
My database has two tables, question and field. Questions may have many fields, and
I have 2 existing tables in my database. Let's call them Table and Chair

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.