How Do I Create Records In a Database Table Using a SQL Query Object?
A SQL Query object provides a quick way of creating data in a database. This lesson will show you how to use sqlquery_create to do so.
Note: When using sqlquery_create none of the validations or callbacks you've defined for Table objects will be triggered.
Create An Array
The first step is to fill in an array variable with the values you want to insert into the database. The array keys should be the names of the columns in your database table.
## Create array with column values for new database record.
put "My Dog's Car" into theRowA["title"]
put false into theRowA["draft"]
Create The Record
Once you have created the array you just pass it as a parameter to sqlquery_create along with the name of the table you want to create the record in. SQL Yoga will generate the query for you.
sqlquery_create "lessons", theRowA
put the result into theError
put it into theAffectedRows