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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:20:53+00:00 2026-06-12T11:20:53+00:00

I have a table with two int values that are IDs. On their own

  • 0

I have a table with two int values that are IDs. On their own these IDs can show up any number of times in the table, but together they should only ever appear once.

Is there a way to make a pair of values unique and still allow the individual values to show up multiple times?

As a follow up, if this is possible can the pair of values be used as a key? I currently have a 3rd column for a unique auto increment value for my key.

  • 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-12T11:20:54+00:00Added an answer on June 12, 2026 at 11:20 am

    It’s called a composite key.

    If you want to change your actual PK to a composite one, use

    Alter table <your table> drop PRIMARY KEY;
    Alter table <your table> drop COLUMN <your autoincremented column>;
    
    Alter table <your table> add [constraint <constraint name>] PRIMARY KEY (<col1>, <col2>);
    

    You can also just add a unique constraint (your PK will be the same, and unique pairs… will have to be unique).

    alter table <your table> add [constraint <constraint name>] unique index(<col1>, <col2>);
    

    Personnally, I would recommend the second solution (simple PK + unique constraint), but that’s just a personal point of view. You can google for pros and cons arguments about composite keys.

    The part between [] are optional.

    EDIT

    If you wanna do this in the create table statement

    For a composite pk

    CREATE TABLE Test(
        id1 int NOT NULL, 
        id2 int NOT NULL,
        id3 int NOT NULL,
        PRIMARY KEY (id1, id2)
    );
    

    For an unique index

    CREATE TABLE Test1(
        id1 int NOT NULL AUTO_INCREMENT, 
        id2 int NOT NULL,
        id3 int NOT NULL,
        PRIMARY KEY (id1),
        UNIQUE KEY (id2, id3)
    );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a DB table with two int columns that are not nullable, but
i have two table: declare @t1 table (id int) declare @t2 table (id int)
I have two SQL statements: CREATE TABLE legs(legid INT PRIMARY KEY AUTO_INCREMENT NOT NULL,
I have two tables which looks something like this Table Queue int ID; string
So I have two tables structured like so: CREATE TABLE #nodes(node int NOT NULL);
I have two tables like, CREATE TABLE [dbo].[entry] ( [id] [int] NULL, [service] [int]
I have two tables: codes_tags and popular_tags. codes_tags CREATE TABLE `codes_tags` ( `code_id` int(11)
So here's the setup. I have two tables: CREATE TABLE dbo.TmpFeesToRules1(Name varchar, LookupId int)
I have a table that's PK is an int field. My problem is I
I have a table with day/time values that are split into date and an

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.