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

The Archive Base Latest Questions

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

I have a table with a unique index across two columns user_id and country_id

  • 0

I have a table with a unique index across two columns user_id and country_id

I have added a new column deleted_at so I can delete rows whilst keeping the data.

I would now like to update the unique key so that it is based on user_id, country_id and where deleted_at IS NULL. Is this possible, if so how?

+----+---------+------------+------------+
+ id | user_id | country_id | deleted_at |
+----+---------+------------+------------+
+  2 |    3    |      1     |     NULL   |
+  3 |    3    |      1     | 2012-10-16 |
|  4 |    3    |      1     | 2012-10-15 |
+----+---------+------------+------------+

Using the above as reference, rows could not be added because of id 2, however if row 2 was not set a new row could be created.

  • 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-12T23:08:42+00:00Added an answer on June 12, 2026 at 11:08 pm

    Modifying your table mytable should do the trick:

    alter table mytable drop index user_country;
    alter table mytable add 
    unique index user_country_deleted (user_id, country_id, deleted_at);
    

    Edit: I was too quick. According to CREATE INDEX Syntax this works only for BDB storage.

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

Sidebar

Related Questions

I have a table with unique index on two columns, id_parent and sort_order to
I have a table with a 12-column UNIQUE index. \d sales shows sales_uq UNIQUE,
I have a table with 3 columns. Each has a unique index. I'd like
I have a table with a unique key for two columns: CREATE TABLE `xpo`.`user_permanent_gift`
I have a table 'posts' in database which has non-unique index on user_id (Key:
I have a table and I'm trying to add a unique index on two
I have a table with several columns and a unique RAW column. I created
I have a table with columns defined under a unique index. When inserting data
I'm using Hibernate 4.0.1.Final. I have a table with a unique constraint column …
I have a table in my schema that has a unique constraint on 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.