Generating triggers
Multiplicity
constraints
Objecteering SQL
Designer uses triggers to map multiplicity constraints in associations, for
Oracle, Sybase and SQL Server.
Multiplicity constraints are checked by a trigger before and after
insertion for Sybase and SQL Server, and after insertion for Oracle.
For further
information on using triggers to map multiplicity constraints, please refer to
the relevant annex at the end of this user guide.
Figures 39 and
40 show an example of the use of triggers to map multiplicity constraints.
Figure 39 shows the starting model and Figure 40 the physical model.

Figure 39. The
starting model

Figure 40. The
physical model
The generated
SQL file is as follows:
/*******************************************************/
/* Objecteering/SQL Designer 1.1.g for
SQLServer */
/* Generation of "MPD_modele"
Package. */
/*******************************************************/
/*******************************************************/
/* Generation of "Curve" table */
/*******************************************************/
BEGIN tran
go
CREATE TABLE Curve(
idCurve
INTEGER NOT NULL ,
measure
INTEGER NULL )
go
COMMIT tran
go
/********************************************************/
/* Generation of "Point" table */
/********************************************************/
BEGIN tran
go
CREATE TABLE Point(
idCurve
INTEGER NULL ,
idPoint
INTEGER NOT NULL ,
x INTEGER NULL ,
y
INTEGER NULL )
go
COMMIT tran
go
/*********************************************************/
/* Generation of <MPD_modele> Package table
primary key */
/* constraints */
/*********************************************************/
BEGIN tran
go
ALTER TABLE Curve ADD
CONSTRAINT
Curve_PK PRIMARY KEY (idCurve)
go
CONSTRAINT
Point_PK PRIMARY KEY (idPoint)
go
COMMIT tran
go
/*********************************************************/
/* Generation of
"TI_agregate_of_Point_INSERT" trigger on */
/* "Point" table */
/*********************************************************/
BEGIN tran
go
CREATE TRIGGER TI_agregate_of_Point_INSERT
ON Point
FOR INSERT
AS
IF
NOT((SELECT COUNT(*)
FROM
Point, inserted
WHERE
Point.idCurve = inserted.idCurve ) <= 4)
BEGIN
ROLLBACK
TRANSACTION
RAISERROR
20501
"Point : May not insert element, agregate_of_Point_FK maximum
cardinality constraint violation"
END
go
COMMIT tran
go