Results 1 to 6 of 6
  1. #1
    Jen0dorf is offline Competent Performer
    Windows 10 Access 2013 32bit
    Join Date
    Jul 2015
    Location
    UK
    Posts
    453

    key violations

    Hi



    I have two tables with identical field names and field proporties -

    One table has field BaptismID which is an auto number and a Primary Key, table 2 does not have this field.

    I need to append table 2 to table 1

    Using the query below

    Code:
    INSERT INTO tbl_Baptism ( ChurchId_fk, FicheNo, PageNo, BirthDate, DateOfBaptism, YearOfBaptism, FullDateOfBaptism, ChildsName, Surname, Sex, Parents, Abode, Occupation, Minister, Notes )
    SELECT [Baptisms 1813-1914].ChurchId_fk, [Baptisms 1813-1914].FicheNo, [Baptisms 1813-1914].PageNo, [Baptisms 1813-1914].BirthDate, [Baptisms 1813-1914].DateOfBaptism, [Baptisms 1813-1914].YearOfBaptism, [Baptisms 1813-1914].FullDateOfBaptism, [Baptisms 1813-1914].ChildsName, [Baptisms 1813-1914].Surname, [Baptisms 1813-1914].Sex, [Baptisms 1813-1914].Parents, [Baptisms 1813-1914].Abode, [Baptisms 1813-1914].Occupation, [Baptisms 1813-1914].Minister, [Baptisms 1813-1914].Notes
    FROM [Baptisms 1813-1914];
    I get the error message "due to table key violations"

    What have I missed? How do I trouble shoot this error?

    thanks

    Ian

  2. #2
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,837
    the message implies you have set a field to not allow duplicates in your destination table

  3. #3
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,837
    or in your relationships you have a one to many - perhaps the churchFK for one or more records does not have a corresponding record/value in the tblChurches

  4. #4
    Jen0dorf is offline Competent Performer
    Windows 10 Access 2013 32bit
    Join Date
    Jul 2015
    Location
    UK
    Posts
    453

    updates

    Hi

    As usual really appreciate the help, you were correct in that if I remove the ChurchId_Fk field from the query it all works perfectly.

    If I then create another query to update the ChurchID_fk field to 7 - which is the value from my churches table I again get the key error.

    So How do I append the records from
    Baptisms 1813-1914 to tblBaptisms?

    tblchurch has a one to many with tblBaptism and I have manually added the entry in tblChurch setting the churchID to 7

    Each parish can have multiple churches and each church can have multiple baptisms

    thanks

    Ian
    Attached Thumbnails Attached Thumbnails relationship.jpg  

  5. #5
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,837
    did you see my second post? are all the churches identified by churchfk in tbl_church? If not, you need to add them in before running your query

    Easy way to find out - run this query - if it comes back with any records, then the ChurchId_fk either needs to be updated to a church that does exist, or add the church into tbl_Church and then update ChurchId_fk

    Code:
    SELECT  [Baptisms 1813-1914].*
    FROM [Baptisms 1813-1914] LEFT JOIN tbl_Church ON [Baptisms 1813-1914].ChurchId_fk =  tbl_Church.ChurchID
    WHERE  tbl_Church.ChurchID is null

  6. #6
    Jen0dorf is offline Competent Performer
    Windows 10 Access 2013 32bit
    Join Date
    Jul 2015
    Location
    UK
    Posts
    453

    Update

    Hi

    many thanks, I did see your second post and checked and it appeared ok.

    However when I ran your query it showed records so I went back and checked again and realised I had used the wrong church Id.

    Note to self - always make a list!

    cheers

    Ian

Please reply to this thread with any new information or opinions.

Similar Threads

  1. key violations in append queries
    By louise in forum Queries
    Replies: 4
    Last Post: 06-07-2016, 08:55 AM
  2. Key Violations in an Append Query
    By petefc in forum Queries
    Replies: 1
    Last Post: 11-30-2012, 01:47 PM
  3. Key Violations
    By Daryl2106 in forum Access
    Replies: 5
    Last Post: 10-02-2012, 02:34 PM
  4. Database help, key violations
    By dhicks19 in forum Queries
    Replies: 6
    Last Post: 05-10-2012, 05:06 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums