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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:14:58+00:00 2026-05-31T13:14:58+00:00

I have an assignment where I am to create two tables within a database.

  • 0

I have an assignment where I am to create two tables within a database. The tables looks like this;

ContactPerson (ID, Forename, Surname, Email, PhoneNumber)
Company (ID, CompanyName)

Now my problem is that I have to link a ContactPerson to a specific company, but I can’t have them in the same table.

I understand that I can use the join statement to show both tables in one query but I need the database to know which person is linked to which company when I implement this databse into my asp.net project.

How do I do this?

  • 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-31T13:14:59+00:00Added an answer on May 31, 2026 at 1:14 pm

    You did say “specific” company so I’m assuming you have one company per person.

    Put a column in the user table called CompanyID…

    ALTER TABLE ContactPerson
    ADD CompanyID int 
    

    (assuming your ids are ints)
    and then create the following foreign key:

    ALTER TABLE [dbo].ContactPerson
        ADD CONSTRAINT [FK_ContactPerson_Company] 
        FOREIGN KEY (CompanyID)
        REFERENCES Company (ID) 
    

    Shark is correct if you want a many to many relationship.

    To get all people in a company:

    SELECT
    *
    FROM
    ContactPerson
    WHERE
    CompanyID = x

    You don’t HAVE to apply the foreign key constraint, but if you don’t, you can accidentally put invalid data in. All a “Constraint” does is enforce a rule for you, in other words “making sure sql knows which people are in which company” as your question suggests you need to do.

    The above query would work without the Foreign key constraint, but then your database doesn’t “know” about the relationship.

    ..and if I try and insert a person with a companyid that doesn’t exist, SQL will throw an error (this is a good thing).

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

Sidebar

Related Questions

This is a practice assignment where I have to create a table space with
I have a database assignment which I have to create some relational algebra for
I am working on an assignment and have to create two classes, one represents
This may seem like a stupid Question but i have two cubes being rendered
I have an assignment to create a GUI using MATLAB GUIDE and am having
I have a small assignment in C. I am trying to create an array
I have two tables Employee ID | Name | Department ---------------------- 121 |Name1 |
I have an assignment in which I need to create a function that tells
Have a homework assignment in which I'm supposed to create a vector of pointers
I've got a homework assignment where I have a base class Package, and two

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.