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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:52:16+00:00 2026-06-17T04:52:16+00:00

I have a table, which includes an ENUM field. I would like for a

  • 0

I have a table, which includes an ENUM field. I would like for a particular value of ENUM to require uniqueness with the reference ID column. So let’s say I have this:

`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`type` ENUM('single','multi') NOT NULL,
`refid` INT UNSIGNED NOT NULL,
`extra` TEXT,
PRIMARY KEY (`id`)

I want (type,refid) to be a unique key, but only if type is single. This can’t be done with conventional keys, so I figured I would use a Trigger to detect insertion of a row, check if type='single', look for a row with type='single' and refid=new.refid, and throw a duplicate entry error if one is found.

I’m using MySQL 5.5, so SIGNAL SQLSTATE is available to me. Can I use this to fire a Duplicate Key error in order to process the ON DUPLICATE KEY UPDATE part of the query, and if so, how?

As an alternative, I could update the row in the Trigger and return a generic error condition, but I think it would be nicer (or at least more intuitive) to have ON DUPLICATE KEY UPDATE work.

  • 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-17T04:52:16+00:00Added an answer on June 17, 2026 at 4:52 am

    REPLACE INTO. Derp! Forgot all about that.

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

Sidebar

Related Questions

I have a table of names and addresses, which includes a postcode column. I
I have a table which includes an identity column but i cant remove the
I have a table where one column may contain data which includes extended ASCII
In a certain TABLE, I have a VARTEXT field which includes comma-separated values of
I have a table which includes an integer type column named sequence, which does
I have a database with a table which includes among others, one column of
I have a membership table, which includes MemberID(int), Username(varchar16), Password... etc. How would I
I have daily scheduled task that queries a table which includes column named AttemptDate
I have an html table, which includes let's say 1 row and 5 cells
I have a database that has a table called matchstats which includes a column

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.