Migrator
execute()
Signature
Section titled “Signature”execute() — returns void
Available in: migration
Category: Migration Functions
Description
Section titled “Description”execute() allows you to run a raw SQL query directly from a migration file. This is useful when you need to perform operations that aren’t easily handled by the built-in migration methods like createTable() or addColumn(). Only available in a migration CFC
Parameters
Section titled “Parameters”| Name | Type | Required | Default | Description |
|---|---|---|---|---|
sql | string | yes | — | Arbitary SQL String |
Examples
Section titled “Examples”<cfscript>
function up() {
transaction {
// Execute a raw SQL statement
execute(sql="INSERT INTO users (firstname, lastname, email) VALUES ('John', 'Doe', 'john@example.com')");
}
}
</cfscript>