16x Prompt for SQL

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

ChatGPT Coding - Generate SQL Scripts

16x Prompt helps developers manage source code context and craft prompts for complex coding tasks on existing codebases.

Code Context Management

Custom Instructions

Complex Tasks

API Integrations

Prompt Management

GPT-4o & Claude 3.5

Token Limit Tracking

No Black Box

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 4000+ users from tech companies, consulting firms, and agencies.