web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Answered

Record in table [tableName] already exists - Parent and child tables

(0) ShareShare
ReportReport
Posted on by 67

Hi!

I have problem with unique values in table.

I have 2 tables:

Parent Table:

table 50900 ParentTable
{
    Caption = 'Parent Table';
    DataClassification = ToBeClassified;

    fields
    {
        field(1; "Parent No."; integer)
        {
            Caption = 'No.';
            DataClassification = ToBeClassified;
        }
        field(2; "Parent Name"; Text[10])
        {
            Caption = 'Parent name';
            DataClassification = ToBeClassified;
        }
    }
    keys
    {
        key(PK; "Parent No.")
        {
            Clustered = true;
        }
    }
}

Child table:

table 50901 ChildTable
{
    Caption = 'Child table';
    DataClassification = ToBeClassified;

    fields
    {
        field(1; "Parent No."; Integer)
        {
            Caption = 'Parent No.';
            DataClassification = ToBeClassified;
            TableRelation = ParentTable."Parent No.";
        }
        field(2; "Child Name"; Text[20])
        {
            Caption = 'Child Name';
            DataClassification = ToBeClassified;
       }
    }
    keys
    {
        key(PK; "Parent No.")
        {
        }
    }
}


I want relation between this two tables one-2-many : ParentTable-2-ChildTable.

When I try to insert second record to ChildTable i get error "The record in table ChildTable already exists. Identification fields and values: Parent No..='1'.

I think that problem is with key on child table. I tried to set property Unique = false, but it didn't help.

Record in tables should look like this:
PARENT:
1;John
2;Emily

CHILD:
1;Emma
1;Lily
2; Steve
2;Patrick


Any solutions?

Best regards.

I have the same question (0)
  • Verified answer
    DAnny3211 Profile Picture
    11,423 Super User 2026 Season 1 on at

    Hi

    the child table key should be

     keys

       {

           key(PK; "Parent No.;, "Child Name")

           {

           }

       }

    check my answer if it helped you, thanks

    DAniele

  • Verified answer
    pankaj.k Profile Picture
    1,020 on at

    Hi Alzack,

    Customization for Child Table: 

    you need to add one more filed "Line No."   data type must be Integer.

    add "Line No." in Primary key.   key(PK; "Parent No.","Line No.") 

    that will resolve your problem.

  • Verified answer
    YUN ZHU Profile Picture
    102,857 Super User 2026 Season 2 on at

    Hi Alzack18, I like your profile image.

    As mentioned by other experts, for Child table, you need to add another field as part of its primary key.

    You can find some examples in the standard.

    Ship-to Address (222): In addition to Customer No., there is also a Code field, and these two form a primary key. This way no errors will occur.

    pastedimage1672185894721v1.png

    pastedimage1672185915534v2.png

    Hope this helps as well.

    Thanks.

    ZHU

  • Alzack18 Profile Picture
    67 on at

    Thank you all for response!

    Problem solved. I added new field "Line Num". Now the pair of these fields is always unique and does not generate a problem :)

    My PK looks like this:

    key(PK; "Parent No.", "Line Num"){}

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 563 Super User 2026 Season 2

#2
YUN ZHU Profile Picture

YUN ZHU 374 Super User 2026 Season 2

#3
Grigorios Mavrogeorgis Profile Picture

Grigorios Mavrogeorgis 331 Super User 2026 Season 2

Last 30 days Overall leaderboard

Featured topics

Microsoft Training Manuals

Product updates

Dynamics 365 release plans