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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:39:25+00:00 2026-06-13T14:39:25+00:00

I am using MySQL 5.1.56, MyISAM. My table looks like this: CREATE TABLE IF

  • 0

I am using MySQL 5.1.56, MyISAM. My table looks like this:

CREATE TABLE IF NOT EXISTS `my_table` (
  `number` int(11) NOT NULL,
  `name` varchar(50) NOT NULL,
  `money` int(11) NOT NULL,
  PRIMARY KEY (`number`,`name`)
) ENGINE=MyISAM;

It contains these two rows:

INSERT INTO `my_table` (`number`, `name`, `money`) VALUES
(1, 'S. Name', 150), (2, 'Another Name', 284);

Now I am trying to insert another row:

INSERT INTO `my_table` (`number`, `name`, `money`) VALUES
(2, 'S. Name', 240);

And MySQL just won’t insert it while telling me this:

#1062 - Duplicate entry '2-S. Name' for key 'PRIMARY'

I really don’t understand it. The primary key is on the first two columns (both of them), so the row I am trying to insert HAS a unique primary key, doesn’t it?

I tried to repair the table, I tried to optimize the table, all to no avail. Also please note that I cannot change from MyISAM to InnoDB.

Am I missing something or is this a bug of MySQL or MyISAM? Thanks.

To summarize and point out where I think is the problem (even though there shouldn’t be):
Table has primary key on two columns. I am trying to insert a row with a new combination of values in these two columns, but value in column one is already in some row and value in column two is already in another row. But they are not anywhere combined, so I believe this is supposed to work and I am very confused to see that it doesn’t.

  • 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-13T14:39:26+00:00Added an answer on June 13, 2026 at 2:39 pm

    Your code and schema are OK. You probably trying on previous version of table.

    http://sqlfiddle.com/#!2/9dc64/1/0

    Your table even has no UNIQUE, so that error is impossible on that table.

    Backup data from that table, drop it and re-create.

    Maybe you tried to run that CREATE TABLE IF NOT EXIST. It was not created, you have old version, but there was no error because of IF NOT EXIST.

    You may run SQL like this to see current table structure:

    DESCRIBE my_table;
    

    Edit – added later:

    Try to run this:

    DROP TABLE `my_table`; --make backup - it deletes table
    
    CREATE TABLE `my_table` (
      `number` int(11) NOT NULL,
      `name` varchar(50) NOT NULL,
      `money` int(11) NOT NULL,
      PRIMARY KEY (`number`,`name`),
      UNIQUE (`number`, `name`) --added unique on 2 rows
    ) ENGINE=MyISAM;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have a simple MySQL table that looks like this: CREATE TABLE `my_table`
I've got a MySQL table that looks like this: CREATE TABLE my_facts ( `id`
I have a table: CREATE TABLE `data_table` ( `data_id` INT NOT NULL AUTO_INCREMENT PRIMARY
I am using the Geospatial extension for MySQL. In the MyISAM table listings there
I'm currently using a script from http://davidwalsh.name/backup-mysql-database-php to do a hotcopy like backup of
I have a very simple table CREATE TABLE IF NOT EXISTS `largecache` ( `id`
When using MySQL MyISAM tables, and issuing an ALTER TABLE statement to add a
Using MySQL should I store time data as an Int which would be the
Using MySQL, I have a simple table that logs the IP Address that users
Using MySQL, I have three tables: projects : ID name 1 birthday party 2

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.