Grails Cookbook - A collection of tutorials and examples

Groovy SQL Delete Operation Examples

When a record in a database table is not needed anymore then we may want to delete it. There are two ways of deleting a record. One is called logical delete where the record is still in the table but a marker was set in one of the column to tell the application that uses the table to ignore it. The second one is called physical delete where we really delete the record in the databases. SQL provides the delete statement for physical delete. Below are examples on how to perform delete operation using Groovy SQL.

Groovy SQL Update Operation Examples

There are instances when data on a record should be modified. SQL provides update statements for this purpose. Below are examples on how to perform update operation using Groovy SQL.

Groovy SQL Read Operation Examples

Reading data from database tables is one of the most common task in programming. For RDBMS servers that supports SQL, we can use SELECT statements for this purpose. Below are some examples on how to read data from database tables using Groovy SQL.

Groovy SQL Insert Operation Examples

Another common operation when working with database is inserting data. This is simple to achieve using SQL's insert statements. Below are some examples on how to insert data to a database table using Groovy SQL.

Groovy SQL Create Table Examples

One of the first things we do to a database is to create tables. SQL supports data definition language or data description language (DDL). Using SQL "Create" statements, we can create tables in our database. Below is a simple example on how to use Groovy SQL to create a table in the database.

Groovy SQL Database Connection Examples

When working with database in Groovy, the first thing we want to do is to connect to a database server. We will not be able to read or manipulate data unless we have a connection. Below will show a simple example on how to connect to a MySQL database in Groovy.