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

  • Home
  • SEARCH
  • 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 3594080
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T19:39:48+00:00 2026-05-18T19:39:48+00:00

I’m putting together my own database and from examples I’ve seen, Foriegn Key can

  • 0

I’m putting together my own database and from examples I’ve seen, Foriegn Key can also be set as Primary Keys.

I was creating my Tables so that all of my FK were also PK. Is this wrong? When should a FK be a PK? Does it have to be a PK?

Primary Key’s make sense in their own table… as the Id and Identity. But when using the Id is another table, does it have to be a PK as well?

  • 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-18T19:39:49+00:00Added an answer on May 18, 2026 at 7:39 pm

    A Foreign Key should only be the Primary Key when your trying to create a 1 to 1 or 1 to zero/1 mapping.

    Example:

    I have a Person table, an Employee table, and a Contractor table. All Employees are people, all Contractors are people and every Person is either an employee or a Contractor

    Essentially you would end up with something like this.

    alt text


    In response to your people have multiple addresses you should create an association table. Here is a diagram.

    alt text

    As you can see now every person can have many addresses and since each Employee is a person then every Employee can have many addresses. This is the same for Contractor as well.


    Edited: Here is the Change Script from SQL Server

    BEGIN TRANSACTION
    SET QUOTED_IDENTIFIER ON
    SET ARITHABORT ON
    SET NUMERIC_ROUNDABORT OFF
    SET CONCAT_NULL_YIELDS_NULL ON
    SET ANSI_NULLS ON
    SET ANSI_PADDING ON
    SET ANSI_WARNINGS ON
    COMMIT
    BEGIN TRANSACTION
    GO
    CREATE TABLE dbo.Address
        (
        AddressId bigint NOT NULL,
        Address nvarchar(50) NULL,
        City nvarchar(50) NULL,
        State nvarchar(50) NULL
        )  ON [PRIMARY]
    GO
    ALTER TABLE dbo.Address ADD CONSTRAINT
        PK_Address PRIMARY KEY CLUSTERED 
        (
        AddressId
        ) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    
    GO
    ALTER TABLE dbo.Address SET (LOCK_ESCALATION = TABLE)
    GO
    COMMIT
    BEGIN TRANSACTION
    GO
    CREATE TABLE dbo.Person
        (
        PersonId bigint NOT NULL,
        Name nvarchar(50) NULL
        )  ON [PRIMARY]
    GO
    ALTER TABLE dbo.Person ADD CONSTRAINT
        PK_Person PRIMARY KEY CLUSTERED 
        (
        PersonId
        ) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    
    GO
    ALTER TABLE dbo.Person SET (LOCK_ESCALATION = TABLE)
    GO
    COMMIT
    BEGIN TRANSACTION
    GO
    CREATE TABLE dbo.PersonAddress
        (
        PersonId bigint NOT NULL,
        AddressId bigint NOT NULL
        )  ON [PRIMARY]
    GO
    ALTER TABLE dbo.PersonAddress ADD CONSTRAINT
        PK_PersonAddress PRIMARY KEY CLUSTERED 
        (
        PersonId,
        AddressId
        ) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    
    GO
    ALTER TABLE dbo.PersonAddress ADD CONSTRAINT
        FK_PersonAddress_Person FOREIGN KEY
        (
        PersonId
        ) REFERENCES dbo.Person
        (
        PersonId
        ) ON UPDATE  NO ACTION 
         ON DELETE  NO ACTION 
    
    GO
    ALTER TABLE dbo.PersonAddress ADD CONSTRAINT
        FK_PersonAddress_Address FOREIGN KEY
        (
        AddressId
        ) REFERENCES dbo.Address
        (
        AddressId
        ) ON UPDATE  NO ACTION 
         ON DELETE  NO ACTION 
    
    GO
    ALTER TABLE dbo.PersonAddress SET (LOCK_ESCALATION = TABLE)
    GO
    COMMIT
    BEGIN TRANSACTION
    GO
    CREATE TABLE dbo.Employee
        (
        EmployeeId bigint NOT NULL,
        EmployeeNumber nvarchar(50) NULL
        )  ON [PRIMARY]
    GO
    ALTER TABLE dbo.Employee ADD CONSTRAINT
        PK_Employee PRIMARY KEY CLUSTERED 
        (
        EmployeeId
        ) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    
    GO
    ALTER TABLE dbo.Employee ADD CONSTRAINT
        FK_Employee_Person FOREIGN KEY
        (
        EmployeeId
        ) REFERENCES dbo.Person
        (
        PersonId
        ) ON UPDATE  NO ACTION 
         ON DELETE  NO ACTION 
    
    GO
    ALTER TABLE dbo.Employee SET (LOCK_ESCALATION = TABLE)
    GO
    COMMIT
    BEGIN TRANSACTION
    GO
    CREATE TABLE dbo.Contractor
        (
        ContractorId bigint NOT NULL,
        ContractorNumber nvarchar(50) NULL
        )  ON [PRIMARY]
    GO
    ALTER TABLE dbo.Contractor ADD CONSTRAINT
        PK_Contractor PRIMARY KEY CLUSTERED 
        (
        ContractorId
        ) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    
    GO
    ALTER TABLE dbo.Contractor ADD CONSTRAINT
        FK_Contractor_Person FOREIGN KEY
        (
        ContractorId
        ) REFERENCES dbo.Person
        (
        PersonId
        ) ON UPDATE  NO ACTION 
         ON DELETE  NO ACTION 
    
    GO
    ALTER TABLE dbo.Contractor SET (LOCK_ESCALATION = TABLE)
    GO
    COMMIT
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.