Writing SQL queries using Joule

Objective

After completing this lesson, you will be able to write SQL queries using Joule.

Writing SQL queries using Joule

Introduction

Joule can assist database administrators in writing SQL queries by understanding natural language prompts to generate, refine, and explain queries. It helps in constructing complex queries and optimizing for performance, enhancing productivity and reducing errors.

Using Joule to write SQL queries

In the following prompt examples Joule will generate SQL code to create a table, generate a statement to insert data into the created table. The prompt examples will also show how to instruct Joule to create select statements.

Creating and Setting the Schema

Code Snippet
1
Show the SQL to create a schema called HC200_SCHEMA

Joule responded with the following code:

SQL
1
CREATE SCHEMA "HC200_SCHEMA";

If you want to know how to set this schema as the default schema to use, ask Joule the following:

Code Snippet
1
Show the SQL to set the schema to HC200_SCHEMA

Joule responded with the following code:

SQL
1
SET SCHEMA "HC200_SCHEMA";

Creating a Table and Inserting Data

To get the SQL code to create a table in that schema, ask Joule the following:

Code Snippet
1234
Show the SQL statement to create a table named HC200_DEMO in the schema HC200_SCHEMA with the field ProductNumber of the type int, a field ProductName type string and a field Stock type int. Make the field ProductNumber the primary key.

Joule responded with the following code:

SQL
123456
CREATE COLUMN TABLE "HC200_SCHEMA"."HC200_DEMO" ( "ProductNumber" INT PRIMARY KEY, "ProductName" NVARCHAR(255), "Stock" INT );

To insert some data records in this table, ask Joule the following:

Code Snippet
1
Show the SQL to insert the table HC200_DEMO the values 1, Bike, 15

Joule responded with the following code:

SQL
123
INSERT INTO "HC200_DEMO" VALUES (1, 'Bike', 15);

I inserted additional records into the table HC200_DEMO, and now the table looked like this:

Table: HC200_DEMO

ProductNumberProductNameStock
1'Bike'15
2'Car'1
3'Bus'12
4'Plane'1

Selecting Data from a Table

You want to know which products have inventory falling below 5 items, ask Joule the following:

Code Snippet
12
Show the SQL to select the field ProductName and Stock from the table HC200_DEMO where the Stock is below 5 items

Joule responded with the following code:

Code Snippet
123456
SELECT "ProductName", "Stock" FROM "HC200_DEMO" WHERE "Stock" < 5;

You want to know which products have a product name that starts with a "P", ask Joule the following:

Code Snippet
12
Show the SQL to select the field ProductName and Stock from the table HC200_DEMO where the product name starts with a P

Joule responded with the following code:

SQL
123456
SELECT "ProductName", "Stock" FROM "HC200_DEMO" WHERE "ProductName" LIKE 'P%';

Summary

This lesson demonstrates how Joule can help database administrators to quickly write SQL queries by understanding natural language prompts. Using Joule will enhancing productivity and reducing errors.