Skip to main content

What is the correct way to draw a relationship in Lucid Chart that will result in valid SQL Server syntax for a foreign key to a compound primary key? 

For instance, if I have two tables

Child.Id1 and Child.Id2 form a foreign key to the compound primary key (Id1, Id2) in Parent.  I can draw two individual lines from Parent to Child to indicate the relationship,

 

but this produces SQL that is not valid


CREATE TABLE AParent] (
  Id1] int,
  rId2] int,
  bDesc] varchar(255),
  PRIMARY KEY (AId1], Id2])
);

CREATE TABLE TChild] (
  (Id1] int,
  tId2] int,
  nId3] int,
  PRIMARY KEY (PId1], Id2], IId3]),
  CONSTRAINT FK_Child.Id1]
    FOREIGN KEY (Id1])
      REFERENCES Parent](EId1]),
  CONSTRAINT     FOREIGN KEY ( Id2])
      REFERENCES bParent](Id2])
);

The correct syntax would be more like

CREATE TABLE Child] (
  EId1] int,
  bId2] int,
    PRIMARY KEY (3Id1],   CONSTRAINT ]FK_Child.Id1_Id2]
    FOREIGN KEY (dId1],       REFERENCES ]Parent]();

 

Furthermore, if I create these tables directly in SQL Server with the correct relationship and import them into Lucid using the ERD import, they draw out with the two lines connecting the entities.  If I then export the ERD again to SQL Server, it creates the same invalid SQL as above with the two independent foreign keys.  

I’m fairly new to Lucid, so I may be missing something obvious and any help is appreciated.

Thanks!

 

Hi @ncheatum, thank you for posting in the Community! Just to make sure that we are on the same page, please review our ERD article from the Lucid Help Center, and let me know if you have any questions about the intended functionality of ERDs in Lucidchart.

A few things I’d like to confirm, are you creating your ERD manually or importing from SQL Server? Are you trying to export your ERD using one of the following options? This information will help me take a closer look at what you’re experiencing. Thanks!
 

 


Hi @Leianne C,

Thank you for your reply.

Yes, I am using the Export functionality in the screenshots you provided. 

I’ve tried both creating tables in Lucid and importing them from SQL Server, but the original scenario was importing tables from SQL Server with no relationships and adding them in Lucid.

After I saw the SQL created by the export, I did some experimenting and created the Parent/Child table set in the original post directly in Lucid.  I created the tables and relationships in SQL Server and imported those into Lucid to see how they would be represented.

 

 


Hi @ncheatum, thanks for following up with that information! Since this may require me to take a closer look at what you’re experiencing, I’m going to move our conversation to a private support ticket. Please keep an eye out for an email from Lucid Support! 


Reply