The INSERT statement conflicted with the FOREIGN KEY constraint

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • waqasahmd
    New Member
    • Nov 2009
    • 13

    The INSERT statement conflicted with the FOREIGN KEY constraint

    Hi

    i have two tables

    1- Person
    2- Account

    In Account table i have key accountID which is a FK in Person table.

    when i run the insert query as


    insert into

    Person(FirstNam e2)

    values ('waq')

    as i did not enter any data for account field so it gives me the eror:


    The INSERT statement conflicted with the FOREIGN KEY constraint "FK_Person_Acco unt". The conflict occurred in database "abc", table "dbo.Accoun t", column 'AccountId'.

    can somebody help me with that as i want to insert the valuse in Person table whether i have accountID or not

    Thanx
  • ssnaik84
    New Member
    • Aug 2009
    • 149

    #2
    since, you are having FK of AccountID in Person table, you must have related record in Account table.
    I suggest you to insert a default record into Account table and use it's ID (AccountID) into Person table as default.

    Comment

    Working...