Connect to the MariaDB testshop database at db.example.com. Port 3306, root account.
Successfully connected to MariaDB (root@db.example.com:3306/testshop)
MariaDB 10.5.29-MariaDB-log — Ready to execute queries and DDL.
U
Design a shopping mall DB. Create 5 tables — categories, customers, products, orders, order_items — with FK relationships.
Prepared to create 5 tables. SqlHazardGuard detected a DDL change:
SqlHazardGuard — HAZARDOUS
CREATE TABLE categories (category_id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(50) NOT NULL, description TEXT)
CREATE: A new object will be created. Proceed?
After approval, 5 tables + FK relationships will be configured.
DDL (CREATE TABLE) also passes through the safety gate. The structure requires confirmation for the act of “creation” itself.
2Advanced Query GenerationT3 ~ T7
A single request through conversation generates DBA-level SQL. Below are the actual queries and results.
U
Get the total purchase amount and order count per customer. JOIN customers, orders, and order_items to show customer name, grade, total orders, total purchases, and average order value.
Executed a 3-table JOIN + GROUP BY aggregation query.
SELECT c.name AS customer_name, c.grade,
COUNT(DISTINCT o.order_id) AS total_orders,
COALESCE(SUM(oi.line_total), 0) AS total_purchase_amount,
COALESCE(ROUND(SUM(oi.line_total) / NULLIF(COUNT(DISTINCT o.order_id), 0), 2), 0) AS avg_order_amount
FROMcustomers c
LEFT JOINorders o ON c.customer_id = o.customer_id
LEFT JOINorder_items oi ON o.order_id = oi.order_id
GROUP BY c.customer_id, c.name, c.grade
ORDER BY total_purchase_amount DESC;
Customer
Grade
Orders
Total Purchases
Avg. Order Value
임지영
VIP
9
2,050,500
227,833
김도윤
VIP
10
1,918,900
191,890
조시우
VIP
8
1,866,100
233,263
정서연
VIP
7
1,816,200
259,457
박지우
VIP
10
1,789,800
178,980
Top 5 of 500 total customers
U
Show only customers whose purchases exceed the overall average. Use a subquery for the overall average and filter with HAVING. Also show each customer's most purchased category.
Retrieved 231 customers exceeding the overall average of ₩612,041. A 5-stage CTE query.
WITH customer_totals AS (
SELECT c.customer_id, c.name, c.grade,
COALESCE(SUM(oi.line_total), 0) AS total_purchase_amount
FROMcustomers c
LEFT JOINorders o ON c.customer_id = o.customer_id
LEFT JOINorder_items oi ON o.order_id = oi.order_id
GROUP BY c.customer_id, c.name, c.grade
),
avg_total AS (
SELECTAVG(total_purchase_amount) AS avg_purchase_amount
FROM customer_totals
),
category_spend AS (
SELECT c.customer_id, cat.name AS category_name,
COALESCE(SUM(oi.line_total), 0) AS category_purchase_amount
FROMcustomers c
LEFT JOINorders o ON c.customer_id = o.customer_id
LEFT JOINorder_items oi ON o.order_id = oi.order_id
LEFT JOINproducts p ON oi.product_id = p.product_id
LEFT JOINcategories cat ON p.category_id = cat.category_id
GROUP BY c.customer_id, cat.name
),
top_category AS (
SELECT customer_id, category_name,
ROW_NUMBER() OVER (
PARTITION BY customer_id
ORDER BY category_purchase_amount DESC
) AS rn
FROM category_spend
)
SELECT ct.customer_name, ct.grade, ct.total_purchase_amount,
tc.category_name AS top_category_name
FROM customer_totals ct
CROSS JOIN avg_total a
LEFT JOIN top_category tc ON ct.customer_id = tc.customer_id AND tc.rn = 1HAVING ct.total_purchase_amount > a.avg_purchase_amount
ORDER BY ct.total_purchase_amount DESC;
Customer
Grade
Total Purchases
Top Category
임지영
VIP
2,050,500
Books
김도윤
VIP
1,918,900
Sports
조시우
VIP
1,866,100
Furniture
정서연
VIP
1,816,200
Baby & Kids
박지우
VIP
1,789,800
Home & Living
Top 5 of 231 customers exceeding the average (₩612,041)
U
Analyze monthly sales by category. Show sales rank with RANK(), month-over-month change with LAG(), and cumulative sales with SUM() OVER.
Retrieved 129 rows using 3 window functions (RANK, LAG, SUM OVER).
WITH monthly_category_sales AS (
SELECT cat.category_id, cat.name AS category_name,
DATE_FORMAT(o.order_date, '%Y-%m') AS sale_month,
SUM(oi.line_total) AS monthly_sales
FROMorders o
JOINorder_items oi ON o.order_id = oi.order_id
JOINproducts p ON oi.product_id = p.product_id
JOINcategories cat ON p.category_id = cat.category_id
GROUP BY cat.category_id, cat.name, DATE_FORMAT(o.order_date, '%Y-%m')
)
SELECT category_name, sale_month, monthly_sales,
RANK() OVER (PARTITION BY sale_month ORDER BY monthly_sales DESC) AS sales_rank,
monthly_sales - LAG(monthly_sales) OVER (PARTITION BY category_id ORDER BY sale_month) AS mom_change,
SUM(monthly_sales) OVER (PARTITION BY category_id ORDER BY sale_month) AS cumulative_sales
FROM monthly_category_sales
ORDER BY sale_month, sales_rank;
Create a query showing the top 3 products per category using CTE and ROW_NUMBER(). Don't execute it yet. Just show me the SQL.
Query drafted. Not yet executed.
WITH product_sales AS (
SELECT c.name AS category_name, p.name AS product_name,
SUM(oi.line_total) AS total_sales
FROMorder_items oi
JOINproducts p ON oi.product_id = p.product_id
JOINcategories c ON p.category_id = c.category_id
GROUP BY c.name, p.name
),
ranked_products AS (
SELECT category_name, product_name, total_sales,
ROW_NUMBER() OVER (
PARTITION BY category_name
ORDER BY total_sales DESC
) AS sales_rank
FROM product_sales
)
SELECT category_name, product_name, total_sales, sales_rank
FROM ranked_products
WHERE sales_rank <= 3ORDER BY category_name, sales_rank;
U
Execute the query you just wrote.
Execution complete. 10 categories × 3 = 30 rows.
Category
Product
Total Sales
Rank
Furniture
Classic Desk 53
3,050,400
1
Furniture
Slim Desk 3
2,499,000
2
Furniture
Slim Desk 43
2,263,800
3
Digital
Classic Mouse 28
4,642,100
1
Digital
Lite Mouse 48
4,158,600
2
Digital
Max Mouse 28
2,689,200
3
Food
Mini Snack 82
4,026,400
1
Food
Smart Snack 42
3,515,400
2
Food
Lite Snack 52
2,938,500
3
9 of 30 rows shown — accurately recalled and executed “the query just written”
The “Don't execute it yet” instruction was respected, and in the next turn, “the query you just wrote” was identified from context and executed. This demonstrates conversational context understanding, not mere command execution.
3DBA AdministrationT8 ~ T11
U
Analyze the execution plan of the T5 monthly sales query with EXPLAIN. If there's a full scan, add an index.
Prepared an index after EXPLAIN analysis:
SqlHazardGuard — HAZARDOUS
CREATE INDEX idx_orders_order_date ON orders(order_date)
CREATE: A new object will be created.
U
Enable the slow query log. Set it to record queries taking more than 1 second, and run an intentionally slow query to test.
Slow query log configured. SELECT SLEEP(2) test results:
Item
Value
slow_query_log
1 (Active)
long_query_time
1.0 sec
Test Query
SELECT SLEEP(2)
Execution Time
2004ms
U
Audit all current DB users and their privileges. Determine if any have excessive permissions.
User
Host
root
%
mariadb.sys
localhost
mysql
localhost
root
localhost
shopadmin
localhost
shopreader
localhost
6 users identified.
4Safety Controls (SqlHazardGuard)T12 ~ T13
UPDATE, DELETE, DROP, and other data-modifying/destructive commands are automatically detected by SqlHazardGuard. They are never executed without user approval.
U
Update the grade to VIP for customers with total purchases of ₩1,000,000 or more.
SqlHazardGuard — HAZARDOUS
UPDATE customers SET grade = 'VIP' WHERE customer_id IN (SELECT customer_id FROM (SELECT customer_id FROM orders GROUP BY customer_id HAVING SUM(total_amount) >= 1000000) AS vip_customers)
UPDATE: Matching rows will be modified. Estimated impact: 71 rows
Proceed?
U
DROP the order_items, orders, products, customers, and categories tables to clean up.
Blocked — Destructive Operation
DROP TABLE order_items, orders, products, customers, categories
This is a destructive operation that would delete all core tables in the database. DROP/TRUNCATE is blocked by the protection policy.
UPDATE calculates the impact scope (71 rows) before requesting approval. DROP assesses the destruction scale — deleting all tables — and blocks immediately. In both cases, user data is protected.
Safety Control Flow
All SQL commands pass through SqlHazardGuard before execution.
User Request→SQL Generation→SqlHazardGuard Analysis→Risk Assessment→Approve / Block→Execute
SQL Type
Risk Level
Behavior
SELECT
SAFE
Execute immediately
CREATE / ALTER
HAZARDOUS
Execute after approval
INSERT
HAZARDOUS
Execute after approval
UPDATE / DELETE
HAZARDOUS
Show impact scope + request approval
DROP / TRUNCATE (full)
DESTRUCTIVE
Block immediately
15
Total Turns
5
Advanced SQL Turns
3
Gate Triggers
500
Customer Records
SQL Techniques Generated from a Single Request
Turn
Request
Generated SQL Technique
T3
Per-customer purchases
3-way LEFT JOIN + GROUP BY + SUM/COUNT/AVG
T4
Above average + top category
5-stage CTE + HAVING + ROW_NUMBER + CROSS JOIN
T5
Monthly sales trends
RANK() + LAG() + SUM() OVER (3 window functions)
T6
Top 3 per category
CTE + ROW_NUMBER OVER PARTITION BY
T7
“Execute that query”
Conversational context reference + T6 query reuse
Although wiiiv's DACS and HazardGuard do their best to prevent destructive operations, they cannot guarantee 100% safety. Please exercise extreme caution and always verify before executing any insert, modify, or delete operations on records, tables, or databases.