Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2007
    Posts
    6

    Question Unanswered: pk <--> fk error

    structure of this post:
    - the querie
    - the error
    - the question
    - dtb layout


    Code:
    SET DATEFORMAT dmy;
    
    INSERT INTO tblAddress (fkCityId, strAddressFull)
    SELECT pkCityId,'test2straat_2'
    FROM tblCity 
    WHERE strCityName = 'Appels';
    
    INSERT INTO tblCustomer (fkCustomerLanguageId, fkCustomerGenderId, strCustomerName, strCustomerFirstname, dtCustomerBirthDate) 
    SELECT pkLanguageId, pkCustomerGenderId,'test2','testing2','7/03/2007 15:51:05' 
    FROM tblCustomerGender, tblCustomerLanguage 
    WHERE tblCustomerGender.strCustomerGenderName ='Male' and tblCustomerLanguage.strLanguageAbbrev ='Dutch';
    
    INSERT INTO tblCustomerAddress(fkCustomerId, fkAddressId) 
    SELECT c.pkCustomerId, a.pkAddressId 
    FROM tblCustomer AS c, tblAddress AS a 
    WHERE c.strCustomerName = 'test2' and c.strCustomerFirstname = 'testing2' and  c.dtCustomerBirthDate = '7/03/2007 15:51:05' and a.strAddressFull ='test2straat_2';
    
    INSERT INTO tblAddressCategorie(fkAddressId, fkCategorieAddressId) 
    SELECT c.pkCategorieAddressId, a.pkAddressId 
    FROM tblAddress AS a, tblCategorieAddress AS c 
    WHERE c.strCategorieName = 'Invoice' and a.strAddressFull = 'test2straat_2';
    
    INSERT INTO tblAddressCategorie(fkAddressId, fkCategorieAddressId) 
    SELECT c.pkCategorieAddressId, a.pkAddressId 
    FROM tblAddress AS a, tblCategorieAddress AS c 
    WHERE c.strCategorieName = 'Privat' and a.strAddressFull = 'test2straat_2';

    the picture shows the part of the dtb that is envolved

    the error:
    Code:
    (1 row(s) affected)
    
    (1 row(s) affected)
    
    (1 row(s) affected)
    Msg 547, Level 16, State 0, Line 18
    The INSERT statement conflicted with the FOREIGN KEY constraint "FK_tblAddressCategorie_tblAddress1". The conflict occurred in database "C:\DOCUMENTS AND SETTINGS\DDP\BUREAUBLAD\STAGE_DENNIS\DATABANK\HDMPADMIN.MDF", table "dbo.tblAddress", column 'pkAddressId'.
    The statement has been terminated.
    
    (0 row(s) affected)


    is there somebody who can help, me, i'm juist looking myself blind on the problem...


    thanks, BoardD
    Attached Thumbnails Attached Thumbnails dtbproblem.JPG  

  2. #2
    Join Date
    Jan 2003
    Location
    Massachusetts
    Posts
    5,799
    Provided Answers: 11
    Are the columns in the select statement below reversed?
    Code:
    INSERT INTO tblAddressCategorie(fkAddressId, fkCategorieAddressId) 
    SELECT c.pkCategorieAddressId, a.pkAddressId 
    FROM tblAddress AS a, tblCategorieAddress AS c 
    WHERE c.strCategorieName = 'Invoice' and a.strAddressFull = 'test2straat_2';

  3. #3
    Join Date
    Feb 2007
    Posts
    6
    damn damn damn me....
    thanks... it works now

    greetz BoardD

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •