How to write SQL with AI Models - Effectively and Painlessly #SQL #aiprompting
Description: Let AI Models Write your SQL for you
How AI can write your SQL for you effectively and easy. No special tools required.
AI models can write your Structured Query Language (SQL) for you.
Simply provide the model with a copy of your table structure along with your prompt.
This is all that is required to get a valid statement response with your SQL query.
1. Below is the table structure I use in this example
CREATE TABLE course (
course_id INT AUTO_INCREMENT PRIMARY KEY,
course_name VARCHAR(300) NOT NULL,
course_description VARCHAR(3000),
course_duration VARCHAR(10),
course_type VARCHAR(2),
course_cost DECIMAL(5,2) NOT NULL);
2. Here is the SQL dump to populate the table
INSERT INTO course (course_name, course_description, course_duration, course_type, course_cost)
VALUES
('HTML', 'Basics building blocks for web pages', '2 days','p', 100.01),
('CSS', 'Add styling and presentation to your web page', '2 days','p', 200.02),
('Photoshop', 'manipulating images Photoshop', '2 days','d', 100.01),
('Creative writing', 'Learn the basics of Creative writing', '1 day','c', 200.02),
('Python', 'Powerful and diverse programming language Python', '2 days','p', 100.01),
('Illustrator', 'Create Illustrations', '2 days','d', 200.02),
('Indesign', 'Powerful design tool', '2 days','d', 100.01),
('JavaScript', 'make your web page dynamic', '2 days','p', 200.02),
('SQL', 'Manipulate date in a database structure', '1 day','p', 100.01),
('PHP', 'Server side programming for web pages' , '2 days','p', 200.02);
3. Here is the AI Prompt
- Write me a SQL Command that display how much to take all courses in the course_type
- The data is located in the MYSQL table
CREATE TABLE course (
course_id INT AUTO_INCREMENT PRIMARY KEY,
course_name VARCHAR(300) NOT NULL,
course_description VARCHAR(3000),
course_duration VARCHAR(10),
course_type VARCHAR(2),
course_cost DECIMAL(5,2) NOT NULL);
4. Here is the AI response
SELECT course_type, SUM(course_cost) AS total_cost
FROM course
GROUP BY course_type; Close description
How AI can write your SQL for you effectively and easy. No special tools required.
AI models can write your Structured Query Language (SQL) for you.
Simply provide the model with a copy of your table structure along with your prompt.
This is all that is required to get a valid statement response with your SQL query.
1. Below is the table structure I use in this example
CREATE TABLE course (
course_id INT AUTO_INCREMENT PRIMARY KEY,
course_name VARCHAR(300) NOT NULL,
course_description VARCHAR(3000),
course_duration VARCHAR(10),
course_type VARCHAR(2),
course_cost DECIMAL(5,2) NOT NULL);
2. Here is the SQL dump to populate the table
INSERT INTO course (course_name, course_description, course_duration, course_type, course_cost)
VALUES
('HTML', 'Basics building blocks for web pages', '2 days','p', 100.01),
('CSS', 'Add styling and presentation to your web page', '2 days','p', 200.02),
('Photoshop', 'manipulating images Photoshop', '2 days','d', 100.01),
('Creative writing', 'Learn the basics of Creative writing', '1 day','c', 200.02),
('Python', 'Powerful and diverse programming language Python', '2 days','p', 100.01),
('Illustrator', 'Create Illustrations', '2 days','d', 200.02),
('Indesign', 'Powerful design tool', '2 days','d', 100.01),
('JavaScript', 'make your web page dynamic', '2 days','p', 200.02),
('SQL', 'Manipulate date in a database structure', '1 day','p', 100.01),
('PHP', 'Server side programming for web pages' , '2 days','p', 200.02);
3. Here is the AI Prompt
- Write me a SQL Command that display how much to take all courses in the course_type
- The data is located in the MYSQL table
CREATE TABLE course (
course_id INT AUTO_INCREMENT PRIMARY KEY,
course_name VARCHAR(300) NOT NULL,
course_description VARCHAR(3000),
course_duration VARCHAR(10),
course_type VARCHAR(2),
course_cost DECIMAL(5,2) NOT NULL);
4. Here is the AI response
SELECT course_type, SUM(course_cost) AS total_cost
FROM course
GROUP BY course_type; Close description
