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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T02:11:05+00:00 2026-05-21T02:11:05+00:00

My insert statement is: INSERT INTO myTable (inst_id,user_id,app_id,type,accessed_on) VALUES (3264,2580,’MyApp’,’Renew’,Now); …where all of the

  • 0

My insert statement is:

INSERT INTO myTable (inst_id,user_id,app_id,type,accessed_on)
VALUES (3264,2580,'MyApp','Renew',Now);

…where all of the values are formatted correctly. The table has the above fields and one other, a long int auto-increment key field. The foreign keys are ‘inst_id’, ‘user_id’, and ‘app_id’.

I am getting this error from Access: access error

…and the following error from VS 2005 when it errors out:

System.Data.OleDb.OleDbException: The changes you requested to the table
were not successful because they would
create duplicate values in the index,
primary key, or relationship. Change
the data in the field or fields that
contain duplicate data, remove the
index, or redefine the index to permit
duplicate entries and try again.

When making this insert query I can look into the database and see that the each of the foreign key values exist in their respective tables and have been for months (for the particular example I am using). These fields are also set so that I can have duplicates, so that is not the issue. Calls of this nature in other tables works great. I do not need to supply the auto-increment key value in the insert query, it adds it for me automatically (like it should).

The weird thing is that if I do this in my code:

try
{
    //Execute the query here...
}
catch
{
    //Execute the same query again
}

…or if I just try and execute this within Access twice, it works.

Has anyone encountered this before? Again, this type of insert works for other tables, all foreign keys are present in their respective tables, the primary key of this table is set as ‘Auto-increment’, and all fields (other than the primary key field of course) are set to allow duplicates.

Any ideas?

EDIT: Largest key before inserting: 343085. Largest key after inserting: 343086. The format is:

id: AutoNumber (Field Size=Long Interger, New Values=Increment, Indexed=Yes - No Duplicates)

inst_id: Number (Field Size=Long Interger, Required=Yes, Indexed=Yes - Duplicates OK)

user_id: Number (Field Size=Long Interger, Required=Yes, Indexed=Yes - Duplicates OK)

app_id: Text (Field Size=255, Required=Yes, Indexed=Yes - Duplicates OK)

type: Text (Field Size=50, Required=Yes, Indexed=No)

accessed_on: Date/Time (Default Value=Now(), Required=Yes, Indexed=No)
  • 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-05-21T02:11:05+00:00Added an answer on May 21, 2026 at 2:11 am

    Going by some old memory here…

    Try putting a timestamp field in your table.

    I can’t remember exactly why that works — something to do with Access having difficulty identifying records / maybe some kind of locking or indexing quirk. I did some research on that several years ago when it happened to one of my tables.

    The key violation the error refers to isn’t a missing key in another table, it’s a duplicate key in the same table. Sometimes, Access gets it’s wires crossed and thinks that the key it’s assigning to the new record is already assigned to another record in the table. I don’t know what causes that to happen. But by putting a timestamp field in the table, it causes Access to think differently.

    It’s a frustrating fix, because I don’t know why it works. And now I have an otherwise useless timestamp field in my table. But so be it.

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

Sidebar

Related Questions

I execute an INSERT INTO statement cursor.execute(INSERT INTO mytable(height) VALUES(%s),(height)) and I want to
If I have a statement like so: cursor.execute(INSERT INTO MYTABLE(name, age, hair_color) VALUES (?,
If I have an insert statement such as: INSERT INTO MyTable ( Name, Address,
SQL statement: INSERT INTO order (`ORDER_ID`,`SALE_CODE`,`CREATED_AT`,`UPDATED_AT`) VALUES ('2646253286','HPHS20','2009-07-11 12:07:40','2009-07-11 12:07:40') Error: You have an
I Have a prepared statement INSERT INTO mst(time) VALUES (?); where time is of
If I try this statement: INSERT INTO TerminalEventChild (id,stringValue) VALUES (64,'version123|'); MySQL fail with
I want to write a SQL statement something like insert into mytable column1=value1 and
String myQuery1 = insert into mytable(mycol) values(myval) \ngo; String myQuery2 = insert into mytable(mycol)
Do you know a java-function to split an INSERT statement INSERT INTO mytable (col1,
I'm using a prepared statement to insert some values into my table. Before doing

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.