The master/detail relationship between two tables is widely used. It is therefore important to provide a simple way for database application developers to implement it. Let's take a look at how to implement this feature.
If we establish a master/BOM relationship between "Department" and "Employee". The Department table contains the following fields: Depno, Depname, and Location. Depno is a numeric primary key, and the other two fields are string types.
The Employee table contains the following fields: EmpNo, EmpName, Job, Manager, and Depno. EmpNo and Depno are numeric fields, and EmpName and Job are string fields. EmpNo is a primary key and Depno is a foreign key that binds "Employee" and "Department".
This is required to display and edit data tables.
ODAC provides two methods of binding data tables. The first code example shows the binding of two Toradataset components (Toraquery, Tsmartquery, toratable, or Torastoredproc) to a master/detail relationship through a parameter.
procedure TForm1.Form1Create(Sender: TObject);
var
Master, Detail: TOraQuery;
MasterSource: TDataSource;
begin
// 创建主数据集
Master := TOraQuery.Create(Self);
Master.SQL.Text := 'SELECT * FROM Department';
To create a detail dataset
Detail := TOraQuery.Create(Self);
Detail.SQL.Text := 'SELECT * FROM Employee WHERE DepNo = :DepNo';
// 主表通过 TDataSource 组件来连接明细表
MasterSource := TDataSource.Create(Self);
MasterSource.DataSet := Master;
Detail.MasterSource := MasterSource;
Open the main dataset and the detail dataset
Master.Open;
Detail.Open;
end;