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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T13:28:14+00:00 2026-06-10T13:28:14+00:00

I’ve read several posts on SO about creating one-to-one relationship: how do i create

  • 0

I’ve read several posts on SO about creating one-to-one relationship:

how do i create a real one-to-one relationship in sql server

is there ever a time where using a database 11 relationship makes sense?

Database design 1 to 1 relationship

but I would be pleased to have your advice on this basic case: I have a USER and a COMPANY tables. Each USER can have 0 or 1 COMPANY.

Is it better to use two tables with the following relationship:

USER_COMPANY

RELATIONSHIP

or did I have just to use only one table with all fields needed:

USER

Thanks for your explanation.

Note: I’m using SQL Server (with Manager Studio to set it up) and plan to use EF.

Update: In order to be more explicit, what I’m trying to achieve is the following:
A user can own or doesn’t own a company. If he owns a company he is the sole person working for it.

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-10T13:28:16+00:00Added an answer on June 10, 2026 at 1:28 pm

    Since it is possible for a user not to own a company, this is not a true “1 to 1” relationship.

    In fact, this is “1 to 0..1”, and you can model it in one of the two ways:

    1. Have everything in one table:

      enter image description here

      Note how COMPANY_ID is both UNIQUE (preventing multiple users from owning the same company) and NULL-able (allowing for the users that don’t own a company). The separation of USER_ID and COMPANY_ID is what allows company-level foreign keys (i.e. allows child tables to reference company, while preventing them from referencing company-less users).

      If there are no company-level FKs, you can omit the COMPANY_ID altogether.

      You’ll also need a CHECK to ensure no other company field can be set unless COMPANY_ID is set (or at the very least that the correct subset of company fields is non-NULL).

    2. Have two tables:

      enter image description here

      We can’t just have PKs of these two tables also be FKs (in both directions) because MS SQL Server does’t support deferred constraints that would be needed to resolve the chicken-and-egg problem when inserting new data, nor it would correctly model the “1 to 0..1” relationship (it would model “1 to 1” and not allow company-less users).

    Which one of these two strategies should you choose depends largely on the number of companies compared to users:

    • If most users own a company, choose (1).
    • If there are many more users than companies, choose (2).
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am reading a book about Javascript and jQuery and using one of the
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
I don't have much knowledge about the IPv6 protocol, so sorry if the question
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
I'm trying to create an if statement in PHP that prevents a single post
I have a bunch of posts stored in text files formatted in yaml/textile (from

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.