Tables and Attributes
The table name is displayed in the header.
When you are creating tables, choose a name that reflects the entity your table represents.
The table has a list of attributes, which represent the different data you want to record. For example, the Teacher table records the Department, Address and Name of teachers.
It might be better to start here with an example that didn’t include a reference to another table, then introduce an example with a foreign key reference when you get to explaining how they work.
You can see that the Address and Name attributes have the word "String" next to them. PhixFlow needs to know what type of data the attribute contains. To make it easy to create an attribute, PhixFlow sets the type to string by default. It is important that you change the attribute to reflect the nature of your data. For example, an attribute of Telephone Number should be integer.
To see or change the data type for an attribute, click on it's name in the table to open it's properties panel on the right.
To refer to an attribute, it's a good idea include the table name. For example, the attribute Name occurs in several tables, so you can specify: Teacher.Name, Student.Name or SchoolDept.Name.
Relationships and Foreign Keys
Sometimes we want to have the same data in different tables. For example, both the Teacher and ClassRoom tables need to have the name of a department. The ERD represents these relationships using a line that joins the SchoolDept table to the ClassRoom table and to the Teacher table (screenshot below).
One-to-many and Many-to-one
PhixFlow always draws a relationship line from a primary key to foreign key. This makes little sense unless the line has an obvious direction, and now that we're using the crow's foot notation there is no obvious direction. This represents a one-to-many relationship. The "many" end of the line has several lines. For example, one teacher runs many courses. A many-to-one relationship is implied when you read a relationship in the opposite direction. For example, a department has many teachers, and several teachers work for one department.
This doesn't really explain why one-to-many / many-to-one are important. You might want to include worked examples showing the data you will get if you build a view starting with Teacher and a similar view starting with SchoolDept. You should also cover the importance of the 'Primary' table (the starting table in a joined view, in particular that you will only be able to edit fields that came from the Primary table, and only then if you haven't followed a one-to-many relationship.
Many-to-many
To create a many-to-many relationship, you need an intermediate table that has foreign key attributes from each of the tables you want to have a relationship. For example, many students take many courses. A many-to-many relationship is shown below, using the intermediate table called CourseAttendee.
- A course is attended by many students
- A student takes many courses.
Again, I think this would benefit from a worked example showing that you get records with combinations of records from each table.
Why ERDs are Important
The ERD's tables, attributes and relationships define the logical structure of the data that your application uses.
However, a table has attributes that you may not want an application user to see, such as UIDs or audit data. When you are creating views to display data in your application, you may want to combine attributes from different table s into one view. For example, your application might want to show:
- Course Name
- Department Name
- Teacher Name
- Number of Students
Each of these attributes comes from a different table. The relationships that you create between tables in an ERD make it possible for PhixFlow to create views using attributes from different tables. For example:
Course Table - 1 relationship to Teacher Table
- Course.Teacher to Teacher.UID and display name Teacher.Name
Course Table - 2 relationships to Department Table (Tech check: this is true??)
- Course.Teacher to Teacher.UID
- Teacher.Department to SchoolDept.UID to SchoolDept.Name.
A Note About Data Records
An ERD defines the table, attribute and relationships. It does not show any data records. If you think of an Excel spreadsheet, an ERD shows the name of the worksheet (table) and the titles of the columns (attributes) but not the rows of data.
You can:
- either define an ERD before adding any data to PhixFlow. In this case you create the tables, attributes and relationships; see Defining Data Structures using ERDs
- or you can load data from external sources first. You can then drag tables into the ERD and simply add the relationships; see Setting Up Data for an overview and links.
If you are working with tables that have records, to see them:
- In the ERD, click on a table to open its properties.
- In the properties toolbar, click . More Options
- Select View Chart.
- PhixFlow displays a the default grid view listing all the data records.