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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:34:15+00:00 2026-06-17T11:34:15+00:00

I have this table: create table comment_check ( record_id int ( 10 ) unique

  • 0

I have this table:

create table comment_check (
record_id int ( 10 ) unique not null AUTO_INCREMENT ,
member_id int (10) not null unique , 
has_question_comment bool ,
has_business_comment bool 
);

And this upsert:

INSERT INTO comment_check
(member_id , has_question_comment )
VALUES
(4815162342, 1 )
ON DUPLICATE KEY UPDATE
has_question_comment = 1

But what I am confused about is I have two keys, the record_id , and the member_id which is the real key. When I create the table, should I label the member_id column as key? And how can I distinguish between the two keys (member_id and record_id) in the query?

Thanks!

  • 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-17T11:34:16+00:00Added an answer on June 17, 2026 at 11:34 am

    There is no need to distinguish between them.

    Whichever key throws a “duplicate key” exception will be the one that MySQL uses for the update.

    In your case, since you are not providing a value for the record_id column, and that column is defined as AUTO_INCREMENT, MySQL is going to generate a unique value for that column. So, it’s not possible that your statement will cause a “duplicate key” exception on the record_id column.

    It will be the “member_id” column that throws the duplicate key exception, so MySQL will perform an update equivalent to:

    UPDATE comment_check
       SET has_question_comment = 1
     WHERE member_id = 4815162342
    

    Actually, the value supplied for member_id in your statement will likely be interpreted as 2147483647, given that the value exceeds the maximum value for an INT.


    In the more general case, where either column would throw a duplicate key exception, e.g.

    INSERT INTO comment_check (record_id, member_id) VALUES (101,1111),(202,2222);
    
    INSERT INTO comment_check (record_id, member_id) VALUES (101,2222)
      ON DUPLICATE KEY UPDATE has_question_comment = 1
    

    either of the two columns can throw a “duplicate key” exception, the behavior (AFAIK) is not well well defined as to which row will get updated, whether its:

       ... WHERE record_id = 101
    

    -or-

       ... WHERE member_id = 2222
    

    I believe it depends on which error gets thrown first. And the MySQL specification (AFAIK) does not specify the order in which those unique constraints gets checked. (It may differ based on the storage engine.)

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

Sidebar

Related Questions

I have this table CREATE TABLE `codes` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
I have this table: CREATE TABLE `test` ( `ID` int(11) NOT NULL auto_increment, `text`
I have this table: CREATE TABLE `point` ( `id` INT(11) NOT NULL AUTO_INCREMENT, `siteid`
i have this table create table eveniment( + evenimentId bigint not null auto_increment primary
I have this sql statement: CREATE TABLE [dbo].[User]( [UserId] [int] IDENTITY(1,1) NOT NULL, [FirstName]
I have this table CREATE TABLE [dbo].[friend_blocked_list]( [subdomain] [varchar](50) NOT NULL, [un] [nvarchar](50) NOT
I have this table: CREATE TABLE IF NOT EXISTS `produtos` ( `id` int(11) NOT
Given this table: CREATE TABLE [Comments] ( [Id] [int] IDENTITY(1, 1) NOT NULL, [Text]
I have a table like this: CREATE TABLE IF NOT EXISTS `session` ( `id`
I have the following table CREATE TABLE IF NOT EXISTS `task` ( `id` int(10)

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.