PDA

View Full Version : Master-detail


jonmich
Apr 4, 2005, 04:15 AM
I have a relationship between a table vehicle and conditions of vehicles.
Now my question is how can I show the conditions if you select the vehicle by a LOV.
The vehicle table is master and conditions is detail but I don't really know how to do it.
I hope that someone can help me?

LTheobald
Apr 4, 2005, 05:07 AM
My SQL isn't great so I just give you some info on what you need to look for. What you need is a join. The simplest kind looks like below:


SELECT table1.Name, table2.Model WHERE table1.ID = table2.ID

In this example imagine you have two tables. Table 1 has all the details of a companies customer. Table 2 contains details of what car they drive. The above statement will retrieve the names of all the customers and what model of car they drive. The table1/2 prefix is only needed when the tables have fields of the same name. They also help illustrate the point though.

Other things you might want to search on Google for are inner and outer joins, along with left and right joins.

ScottGem
Apr 4, 2005, 05:51 AM
Specifics on how you do this depends on the platform you are working in. But I can give you some general points. Every table should have a primary key field. This field should uniquely identify the record. The field should be static, meaning its value would never change. There is a debate over the using natural or surrogate keys. A natural key is one that may have meaning to the object. For example a VIN. A surrogate key is a system generated value. I personally prefer using surrogate keys. If you would like more info on this debate let me know.

To relate one table with another, you use a Foreign Key. The FK is a field in a table that contains the value of the PK in the related table. For example, the VIN in your vehicle table might be 12345. Your conditions table would have a field that stores the VIN and each condition attributable to vehicle 12345 would have that value as its FK.

Like I said earlier, where you go from here depends on the platform you are using and how you want to display things. If you want to do it in a report, you would create a query that joins the 2 tables and then use that as the basis of your report.

jonmich
Apr 4, 2005, 06:04 AM
I am working in oracle forms 6i.
I have to make an application, the meaning of this question is that I can choose a vehicle by a LOV and then I have to see al its conditions but I don't know how to do it.
I always have to press the 'execue query' button.

ScottGem
Apr 5, 2005, 05:30 AM
I have no experience with Oracle forms. I suggest you check their site for forums that support that.

I suspect you need to do something that synchronizes the forms or uses a subform or whatever the equivalent is for Oracle forms.