I’m using Five to create a database (in the tables interface). What’s the fastest way for me to create a one-to-many relationship between two tables?
I have one table called Suppliers. and one called Services. I want to have the two tables related, so that one supplier can have many services.
Hi ericky1k1,
Five’s Table Wizard makes it very fast for you to create a one-to-many relationship between tables as all you need to do is select the table to create the relationship with and Five will handle creating the Foreign Key field and index.
Below is a short video to show you how to create the relationship between your Suppliers and Services tables.
Steps to Create a One-to-Many Relationship Between Two Tables
-
Select Tables in the menu.
-
Click the New Table Wizard button in the form app bar.
-
Type Suppliers in the Name field.
-
Click the Add Fields button.
-
Add the required fields and their definitions.
-
Click the Save button in the Table Wizard app bar.
-
Click the New Table Wizard button in the form app bar.
-
Type Services in the Name field.
-
Click the Add Fields button.
-
Add the required fields and their definitions.
-
Click the Next button.
-
Click the Add Relationships button.
-
Click the lookup icon in the Table field and select Suppliers.
-
Click the Save button in the Table Wizard app bar.
I am following the example of building the Portfolio application.
The five tables in the application are now created: portfolio, exchange, sector, stock and stockPrice but during creation I did not create the relationship between the tables. With the tables created I cannot see where I can select a table and create the relationship with other tables. Can you guide me?
Kind Regards,
Lars Jorgensen
Hi Lars,
Just to clarify, did you create these tables through Five’s Table Wizard? Am I correct to assume that these tables are now saved in Five but the relationships between the tables are not created and you want to form these relationships without having to delete your tables and start again?
Unfortunately, once a table is saved in Five, you can not use the Table Wizard to edit the table, however, you can edit the record to create relationships through the Table Form.
With the tables you currently have saved in the Portfolio Application, you will need to edit two of the tables:
-
The Stock table to create foreign relationships with the Exchange and Sector tables, and
-
The StockPrice table to create a foreign relationship with the Stock table.
Edit the Stock Table
-
Navigate to the Tables view.
-
Select the Stock record in the list.
-
Click the Fields tab.
- Click the Add Fields button.
- Type ExchangeKey in the Field ID field.
Note:
If the relationships were formed in the Table Wizard the naming convention for key fields is the name of the table followed by the word ‘Key’. We will keep with these naming conventions here to ensure all your functions and queries work as you progress through the Portfolio documentation.
- Click the lookup icon in the Data Type field and select GUID.
Notes:
- Five uses GUIDs (Globally Unique Identifiers) to uniquely identify the field.
- If you select a GUID, Five will fill in the data size automatically.
-
Click the Required switch.
-
Click the lookup icon in the Display Type field and select _Lookup.
Note:
When it is a foreign key relationship, we establish the display type to be a lookup, this ensures a value is displayed in the field and not the GUID.
- Click the Save button in the form app bar.
-
Repeat this exact process to add the SectorKey field.
-
Click the Indices tab.
- Click the Add Indices button.
-
Type ExchangeKey in the Index ID field.
-
Click the lookup icon in the Key Type field and select Foreign.
-
Click the lookup icon in the Foreign Table field and select Exchange.
-
Click the lookup icon in the Dependent Index field and select ExchangeKey.
- Click the Index Fields tab.
- Click the Add Index Fields button.
-
Click the lookup icon in the Field field and select ExchangeKey.
-
Click the Save button in the form app bar.
- Click the Save button in the form app bar above the list.
-
Repeat this exact process to add the SectorKey index, however, you will be referencing the Sector table.
-
Click the Save button in the form app bar on completion.
Notes:
-
You will be asked in the Table Upgrade window how you would like to fill in the fields for any previous records in the table, simply type 0 for each field.
-
Your relationships will now be established for the Stock table. You will need to perform the same procedure on the StockPrice table to establish the foreign relationship with the Stock table.
When in the Table Wizard you can simply form these relationships by:
- Click the Next button.
-
Click the Add Relationships button.
-
Click the lookup icon in the Table field and select a table.
Five will handle creating all the properties for you this way.
Please keep an eye out for our very soon to be released Version 2.1 as we have a database modeler where you can simply drag the relationships between tables!!!
<
thanks a lot, Jo-Anne for the explanation. Now I see how the relations between the tables are created outside the Table Wizard.
And Yes, I created the tables outside the Wizard but recreated them with the Wizard so I got the relations to work.
You’re welcome Lars. And it’s great to hear you are getting your way around creating tables in different ways in Five!