Question : Append from Access to SQL Server key violation on any second query

I have about 20 tables in Access 2003 that need to be appended to tables in SQL Express 2005. I can run one query just fine, but the second gives me a key violation error. It does not matter what order I do them in, one will work, but no more. If I close and re-open the application, then I can run the next query. And so on--all of the queries work just fine as long as they are the only one I run. What is causing this and how do I fix it? Is there something being kept in some kind of active memory? All of the tables have an autonumber primary key which exists in the original table and has to be appended to the SQL table. I know this is ok because it works for the first query, but no more. I had this same function in a previous version of my application and have no idea what could be wrong now. I'm using the SQL Native Client ODBC driver.

Answer : Append from Access to SQL Server key violation on any second query

Try adding whereclauses as below into the queries

INSERT INTO tblDept ( DeptID, Department )
SELECT tblDept2.DeptID, tblDept2.Department
FROM tblDept2
WHERE tblDept2.DeptID NOT IN (SELECT tblDept.DeptID FROM tblDept)

INSERT INTO tblJobs ( JobID, Title )
SELECT tblJobs2.JobID, tblJobs2.Title
FROM tblJobs2
WHERE tblJobs2.JobID NOT IN (SELECT tblJobs.JobID FROM tblJobs)

OR run DELETE statements prior to running the inserts

DELETE * FROM tblDept;
DELETE * FROM tblJobs;
Random Solutions  
 
programming4us programming4us