SQL Tables
Basics
You can easily diagram entity-relationship diagrams (ERDs) in D2 by using the sql_table
shape. Here's a minimal example:
Each key of a SQL Table shape defines a row. The primary value (the thing after the colon) of each row defines its type.
The constraint value of each row defines its SQL constraint. D2 will recognize and shorten:
constraint | short |
---|---|
primary_key | PK |
foreign_key | FK |
unique | UNQ |
But you can set any constraint you'd like. It just won't be shortened if unrecognized.
You can also specify multiple constraints with an array.
Foreign Keys
Here's an example of how you'd define a foreign key connection between two tables:
When rendered with the TALA layout engine or ELK layout engine, connections point to the exact row.
Example
Like all other shapes, you can nest sql_tables
into containers and define edges
to them from other shapes. Here's an example: