16x Prompt for SQL

Use 16x Prompt to generate SQL scripts for querying and managing databases.

ChatGPT Coding - Generate SQL Scripts

16x Prompt allows you to add source code context and formatting instructions into the prompt for ChatGPT coding.

Code Context Integration

Customizable Formatting

Optimal Prompt Structure

GPT-4 & Claude 3

Final Prompt Preview

Token Limit Tracking

Boost Productivity

Generate Better Code

16x Prompt screenshot

You can use 16x Prompt to generate SQL scripts for querying, updating, and managing databases.

Here we use a sample database with two tables, bill and receipt, to demonstrate the use cases.

Sample Bill Table Sample Receipt Table

Update

Update status column in Bill table based on Receipt table

We want to update the status column in the bill table based on the information in the receipt table.

Step 1: Enter Task Instruction in the 16x Prompt app.

Write MySQL 5.7 code to update status column in `bill` table with information from `receipt` table.
 
If the bill is fully paid, then the status should be updated to 'PAID'.
 
If the bill is partially paid, then the status should be updated to 'PARTIAL'.
 
If the bill is not paid at all, then the status should be updated to 'UNPAID'.

Step 2: Drag and drop SQL files into the 16x Prompt app.

You should see the Final Prompt in 16x Prompt:

Script to update SQL table using 16x Prompt

Step 3: Generate SQL code using ChatGPT.

You can either copy paste the final prompt into the ChatGPT, or send it via API to get the SQL code.

Here is the ChatGPT (ChatGPT Classic) Output:

UPDATE bill b
LEFT JOIN (
    SELECT bill_id, SUM(amount) AS total_paid
    FROM receipt
    GROUP BY bill_id
) r ON b.id = r.bill_id
SET b.status = CASE
    WHEN r.total_paid IS NULL THEN 'UNPAID'
    WHEN r.total_paid < b.amount THEN 'PARTIAL'
    WHEN r.total_paid >= b.amount THEN 'PAID'
END;

After running this SQL script, the status column in the bill table will be updated based on the information in the receipt table:

MySQL Workbench Output

Reference Links:

Download 16x Prompt

Join 500+ users from top institutions, banks, consulting firms and tech companies.