• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 339
  • Last Modified:

SQL error violation of PK_constraint

I have Access front end and SQL back end database. I am trying to synch 2
tables together, insert records from table1 into table2 if they do not exist
in table2, if they exist, then update.
The primary key is set to the empID. I have some records that need to be
inserted into table2, however, I am getting an error that can not insert Null
value, empID column does not allow nulls.
The records do not have any fields that are null so I am not sure what is
going on.
When I try to append those records in access, they append fine. But I really
need to get this to work in SQL. Can someone give me an advise on what may be
going on?

3 Solutions
We don't know your data and environment so the easiest solution is to start the SQL Server Profiler and look what command and values is Access trying to insert.
Chris LuttrellSenior Database ArchitectCommented:
It sounds like the insert statement is not providing the value for empID for table2, it should be something like this:
insert into table2 (empID, othercols)
select empID, othercols
from table1
where not exists (select 'x' from table2 where table1.empID = table2.empID)

        go to (in Viual Studio), Tool,
                                            DataBase and table conception,
                                            Options of Scema and Table,

                                            untick the 6th checkbox from the top: Avoid Record modification ...

mind that my Visual Studio is not in english, so, I might have the Menu's name mispelled.
Hope this'll help
HarterAuthor Commented:
I would like to thank experts pcelba, CGLuttrell and Kelevra for responding to my question. I ended up rewriting my sp per CGLuttrell's suggestion.
thanks a lot!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now