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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:41:13+00:00 2026-06-12T13:41:13+00:00

Let say that I have table TableA(ColumnCode, ColumnA2, ColumnA3, ColumnA4, ColumnA5). Note: ColumnCode(PrimaryKey)is not

  • 0

Let say that I have table TableA(ColumnCode, ColumnA2, ColumnA3, ColumnA4, ColumnA5).

Note: ColumnCode(PrimaryKey)is not autoincrement. What I want to prevent is following scenario:

INSERT INTO TableA VALUES(1111, 'val1a', 'val2a', 'val3a', 'val4a', 'val5a')

Next insert is with the same values but different ColumnCode:

INSERT INTO TableA VALUES(1234, 'val1a', 'val2a', 'val3a', 'val4a', 'val5a')

The thing is that I want to prevent inserts like this, where I might have these situations of inserting same values just for another ColumnCode.

Any idea?

Note2: Next insert is not a problem because I’m not inserting ALL the same column values!!!

INSERT INTO TableA VALUES(1456, 'val1a', 'val2a', 'val3a', 'val32a', 'val654a')

As shown, set(ColumnA2, ColumnA3, ColumnA4, ColumnA5) of values is not a duplicate. ColumnA4 and ColumnA5 values are different. So, for me, a duplicate is only when all four of ColumnA values are in table under any ColumnCode.

Hope I cleared my question a bit?

  • 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-12T13:41:15+00:00Added an answer on June 12, 2026 at 1:41 pm

    You might want to take a look at using SQL UNIQUE Constraint

    The UNIQUE constraint uniquely identifies each record in a database
    table.

    The UNIQUE and PRIMARY KEY constraints both provide a guarantee for
    uniqueness for a column or set of columns.

    A PRIMARY KEY constraint automatically has a UNIQUE constraint defined
    on it.

    Note that you can have many UNIQUE constraints per table, but only one
    PRIMARY KEY constraint per table.

    Have a look at the following example ….

    SQL Fiddle DEMO

    CREATE TABLE TABLE1(
      col1 varchar(50) PRIMARY KEY,
      col2 varchar(50),
      col3 varchar(50),
      col4 varchar(50),
      CONSTRAINT uc UNIQUE (col2,col3,col4)
     );
    

    this should work:

    INSERT INTO TABLE1 VALUES('1','1','1','1');
    INSERT INTO TABLE1 VALUES('2','1','1','2');
    

    this should fail:

    INSERT INTO TABLE1 VALUES('1','1','1','1');
    INSERT INTO TABLE1 VALUES('2','1','1','1');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

let's say that I have a table called Items (ID int, Done int, Total
I have this table: id feed_id ... Let's say that I have 500 rows
Let's say I have a table that has user_id, date, score, and every user
Let's say I have a MySQL table that is something like this: software table:
Let's say I have 3 MySQL table. A song db called songs that has
So let's say I have a compound index on a table that indexes 4
Let's say I have String Table that have a few strings (like mother, father,
Let's say I have records in a MySQL table that have a unix timestamp
Let's say that we have one table with a field called sales_total and another
Let's say that I have the following code: SELECT * FROM table where company

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.