Escribir consultas SQL con Joule

Objective

After completing this lesson, you will be able to escriba consultas SQL con Joule.

Escribir consultas SQL con Joule

Introducción

Joule puede ayudar a los administradores de bases de datos a escribir consultas SQL comprendiendo las peticiones de lenguaje natural para generar, refinar y explicar consultas. Ayuda a construir consultas complejas y optimizar el rendimiento, mejorando la productividad y reduciendo los errores.

Uso de Joule para escribir consultas SQL

En los siguientes ejemplos de petición, Joule generará código SQL para crear una tabla, generará una sentencia para insertar datos en la tabla creada. Los ejemplos de petición también mostrarán cómo indicar a Joule que cree sentencias SELECT.

Creación y configuración del esquema

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

Joule respondió con el siguiente código:

SQL
1
CREATE SCHEMA "HC200_SCHEMA";

Si desea saber cómo establecer este esquema como esquema predeterminado para utilizar, pregunte a Joule lo siguiente:

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

Joule respondió con el siguiente código:

SQL
1
SET SCHEMA "HC200_SCHEMA";

Crear una tabla e insertar datos

Para obtener el código SQL para crear una tabla en ese esquema, pida a Joule lo siguiente:

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 respondió con el siguiente código:

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

Para insertar algunos registros de datos en esta tabla, pida a Joule lo siguiente:

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

Joule respondió con el siguiente código:

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

Inserté registros adicionales en la tabla HC200_DEMO y ahora la tabla tenía el siguiente aspecto:

Tabla: HC200_DEMO

ProductNumberProductNameBolsa
1"Bicicleta"15
2'Coche'1
3"Bus"12
4"Avión"1

Selección de datos de una tabla

Desea saber qué productos tienen un inventario inferior a 5 artículos, pregunte a Joule lo siguiente:

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 respondió con el siguiente código:

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

Desea saber qué productos tienen un nombre de producto que empieza por "P", pregunte a Joule lo siguiente:

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 respondió con el siguiente código:

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

Resumen

Esta lección muestra cómo Joule puede ayudar a los administradores de bases de datos a escribir rápidamente consultas SQL comprendiendo las peticiones de lenguaje natural. El uso de Joule mejorará la productividad y reducirá los errores.