iTalk data, automation, and AI
Create an ERD Diagram with me: Using draw.io
Wait a minute, what actually is an Entity Relationship Diagram?
Well, Oracle describes an Entity Relationship Diagram as a ‘ visual representation of the data model, showing the entities that are used in a database, the attributes of those entities, and the relationship between them’
It is like a visual representation for pragma table_info(name_of_table) code on SQLite which provides information about the columns (attributes) of a specific table and their data type which is more detailed than what an ERD typically shows.
However, An ERD provides a high-level, visual representation of the database structure and relationships between different entities (tables).
Now let’s create an ERD together
Step 1: Download draw.io
Start by downloading draw.io, which is a free and open-source building diagramming tool, if you haven’t already. Draw.io is one among many other diagramming tools, such as Lucidchart, etc
Step 2: Launch the application
Launch the application. Select “Create a new diagram,” then choose “Blank Diagram,” and click “Create.”
Step 3: Choose the Entity Diagram Template
In the newly created diagram page, you’ll want to select the appropriate template for your Entity Relationship Diagram (ERD).
- Look to the left corner of your draw.io interface and find the “Entity Diagrams” section.
2. Click on it to reveal a list of available diagram templates.
3. Select the first diagram template, typically labeled “Entity Relation.” Clicking on it will automatically place the template on your drawing sheet
Step 4: Rename the Table
In this example, let’s rename the default table to “Loans.”
- Double-click on the default “table” element, usually represented as a rectangle.
- In the text box that appears, replace the default name with “Loans” and press Enter.
Note: A Primary Key (PK) is a unique identifier within a table. It differs from a foreign key, which represents a primary key from another table. This is why it is called a ‘foreign key’
Step 5: Insert Entity Names and Attributes
In the loan table, include the attributes such as “BookID”, “MemberID”, and “LoanDate’’.
Step 6: Customise Text and Style
You can format your table and customise the text and styling. and “ReturnDate”
- Use the “Style” and “Format” tabs in draw.io to modify text size, font, color, and various other formatting options.
- For specific items like “LoanID,” click on the item, go to the “Style” tab, and make text and formatting adjustments based on personal preference
Step 7: Add Rows and Columns
You can add rows and columns.
- Go to the “Arrange” menu.
- Choose options like “Insert Row After,” “Delete,” or “Add Left/Right Column” to adjust the table’s structure according to your design needs.
Step 8: Duplicate Tables
To save time and effort, you can duplicate tables. There are several ways to do this:
a) Use the keyboard shortcut Ctrl + D.
b) Right-click on the table and select “Duplicate.”
c) Hold the control button, click on the table, and drag it to create a duplicate. Customize the duplicate as necessary.
For example, rename it to “BOOKS” and designate “BOOKID” as the Primary Key (PK) , edit the attributes as “Title”, “Author”, and “ISBN”.
Step 9: Connect the Two Tables
draw.io is good for establishing connections between elements, especially when designing data models and infrastructure.
- To connect tables, use the available connectors or lines in draw.io.
- Click on the connector or line tool.
- Drag the line from one entity (table) to another, indicating the relationship between them.
Step 10: Save your ERD Diagram
- Congratulations! You now have your ERD.
- The next step is to print it. Adjust the zoom to your desired appearance, and then save it as a draw.io XML file for future editing.
- To save as an image, remember to note the zoom level as it determines the image’s appearance. Click on “File,” then “Export As,” and adjust the zoom to 85% for the ERD. Additionally, you can consider adding a backdrop (the rectangle) to enhance the visual presentation.
With Step 10, you have successfully built and saved your ERD on your computer for use.
You can recreate an ERD for three different entities by following the same simple steps. I hope you found this guide helpful.
Stay tuned for our next article on how to use draw.io to build a data infrastructure.
Bye for now!
#Dataengineering #database #erd #data #draw.io