Documentation

Trace:

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
jvx:client:model:databook:master_detail [2018/02/01 08:20]
admin
jvx:client:model:databook:master_detail [2020/06/08 15:30] (current)
cduncan Edited for English grammar (capitalization, punctuation, correct verb conjugation)
Line 1: Line 1:
-~~Title: Using master/detail relationships~~+~~Title: Using Master/Detail Relationships~~
  
 Master/​detail relationships are used to create relationships between tables or other datasets. The master can also be viewed as a group, whereas the detail contains the individual sets of the group. ​ Master/​detail relationships are used to create relationships between tables or other datasets. The master can also be viewed as a group, whereas the detail contains the individual sets of the group. ​
Line 7: Line 7:
 == Example == == Example ==
  
-Our application handles the administration of countries, states and districts. Tables in the database are created in 3rd NF. The following is an excerpt from the HSQLDB:+Our application handles the administration of countries, statesand districts. Tables in the database are created in 3rd NF. The following is an excerpt from the HSQLDB:
  
 <file sql createdb.sql>​ <file sql createdb.sql>​
Line 37: Line 37:
 </​file>​ </​file>​
  
-As the table definition shows, countries consist of individual states and states are made up of districts. In our application we want to create a form that allows the editing of countries, states and districts, as well as the relationships between them.+As the table definition shows, countries consist of individual statesand states are made up of districts. In our applicationwe want to create a form that allows the editing of countries, states and districts, as well as the relationships between them.
  
 We first create our server objects: We first create our server objects:
Line 169: Line 169:
 The master/​detail relationship between countries and states is created via the foreign key (STATES.CTRY_ID) to the primary key (COUNTRIES.ID). This means that when a country is selected, all associated states are displayed. States that are not assigned to the selected “master” country are not shown. The master/​detail relationship between countries and states is created via the foreign key (STATES.CTRY_ID) to the primary key (COUNTRIES.ID). This means that when a country is selected, all associated states are displayed. States that are not assigned to the selected “master” country are not shown.
  
-When a new state is entered, the correct foreign key is used automatically. The state is therefore assigned to the correct country. ​+When a new state is entered, the correct foreign key is used automatically. The state isthereforeassigned to the correct country. ​
  
 The master/​detail relationship between districts and states is created between the foreign key (DISTRICTS.STAT_ID) and the primary key (STATES.ID). This means that when a state is selected, all associated districts are displayed. Districts that are not assigned to the selected “master” state are not shown. The master/​detail relationship between districts and states is created between the foreign key (DISTRICTS.STAT_ID) and the primary key (STATES.ID). This means that when a state is selected, all associated districts are displayed. Districts that are not assigned to the selected “master” state are not shown.
  
-When a new district is entered, the correct state is used. The district is therefore automatically assigned to the correct state. ​+When a new district is entered, the correct state is used. The district isthereforeautomatically assigned to the correct state. ​
  
 +\\ 
 **<fs 20px>​Note</​fs>​** **<fs 20px>​Note</​fs>​**
  
-A master/​detail relationship does NOT require that a foreign key relationship ​exists ​between two tables. Any columns can be used.+A master/​detail relationship does NOT require that a foreign key relationship ​exist between two tables. Any columns can be used.
This website uses cookies for visitor traffic analysis. By using the website, you agree with storing the cookies on your computer.More information