Adding a new record to the database
- Last Updated: March 26, 2025
- 3 minute read
- Corticon
- Version 7.1
- Version 6.3
- Documentation
In this example, let’s assume that you need to model rules that assign a value to Cargo.container based on the value of Cargo.weight received in input.
As you know, the Cargo table in the Transportation database contains three records:
![]()
To add a new record, the value of its manifestNumber (the primary key), must be unique.
Create a Rulesheet named AddRecord.ers that uses the Cargo.ecore Vocabulary and model rules as shown here:
![]()
Since this Rulesheet uses the Cargo.ecore Vocabulary that is mapped to the Transportation database we don’t need to do anything more here. Let’s test this Rulesheet.
Create a Ruletest named AddRecord.ert that uses AddRecord.ers as its test subject.
We want this Ruletest to add a new record to the Transportation database. To enable this, we need to configure the Ruletest’s database access setting, changing it from the default to Read/Update. Select Ruletest > Testsheet > Database Access > Read/Update.
![]()
Next, we need to define input. For this example, let’s create just one instance of the Cargo entity that we want the Rulesheet to process and add to the Cargo table as a new record. Define input data as shown and run the Ruletest:
![]()
As you can see, in the Input, the Cargo entity instance has a unique value (625D) for the manifestNumber attribute, which is the primary key of the Cargo table. Because the entity instance has a unique value for the primary key, it will be added as a new record. If we used an existing value, such as 625A, 625B, or 625C, the existing record with that primary key value would get updated instead.
Let’s look at the new record in the Cargo table. In SQL Management Server Studio, right-click dbo.Cargo and select Select Top 1000 Rows. You should be able to see the following result:
![]()
A new record (highlighted here) has been added. The Rulesheet processed the input, assigned the value STANDARD to Cargo.container and added a new record to the Cargo table using the unique primary key value 625D.