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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:50:01+00:00 2026-05-28T13:50:01+00:00

Here is my scenario on SQL Server 2008 R2 : This is my first

  • 0

Here is my scenario on SQL Server 2008 R2:

This is my first table:

CREATE TABLE [dbo].[Foos](
    [FooId] [int] IDENTITY(1,1) NOT NULL,
    [Name] [nvarchar](50) NULL,
 CONSTRAINT [PK_Foos] PRIMARY KEY CLUSTERED 
  (
    [FooId] ASC
  )
) ON [PRIMARY]

This is the second table which has a relationship to Foos table:

CREATE TABLE [dbo].[Bars](
    [BarId] [int] IDENTITY(1,1) NOT NULL,
    [FooId] [int] NOT NULL,
    [Name] [nvarchar](50) NULL,
 CONSTRAINT [PK_Bars] PRIMARY KEY CLUSTERED 
  (
    [BarId] ASC
  )
) ON [PRIMARY]

Go

ALTER TABLE [dbo].[Bars]  WITH CHECK ADD  CONSTRAINT [FK_Bars_Foos] FOREIGN KEY([FooId])
REFERENCES [dbo].[Foos] ([FooId])
ON DELETE CASCADE
GO

But it is not one to one. What should I do to force this to be one to one relationship? Should I use check constraints?

  • 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-28T13:50:02+00:00Added an answer on May 28, 2026 at 1:50 pm

    Add a unique constraint to FooId in Bars.

    However, you don’t need BarID then because they have the same key. So it looks like this

    CREATE TABLE [dbo].[Bars] (
        [FooId] [int] NOT NULL,
        [Name] [nvarchar](50) NULL,
    
        CONSTRAINT [PK_Bars] PRIMARY KEY CLUSTERED (FooId),
    
        CONSTRAINT [FK_Bars_Foos] FOREIGN KEY([FooId]) 
               REFERENCES [dbo].[Foos] ([FooId])
               ON DELETE CASCADE
    )
    GO
    

    However again, you don’t need Bars at all: it is one table…

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

Sidebar

Related Questions

Here is the scenario: SQL Server 2000 (8.0.2055) Table currently has 478 million rows
In SQL Server 2008, I have a scenario where I have a table with
Here's the scenario: TABLE 1 (client table. imported into sql server via a csv
Here is the scenario: IIS 6 and SQL Server 2005 on same machine: I
Here's the scenario: You have an ASP.Net application supported by a Microsoft SQL Server
I'm still a learning user of SQL-SERVER2005. Here is my table structure CREATE TABLE
I feel like this behavior should not be happening. Here's the scenario: Start a
Here's the scenario: I want to be able to support both SQL Server CE
im using sql server 2008. my scenario is as follows. there is a user
Here's my scenario: Using SQL Server sessions (due to web farm) customErrors is On

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.