SQL Creation Overview
SQL Creation through Vibe Coding is a feature where the AI immediately creates a valid query if you explain the data extraction requirements in natural language, without having to manually write complex Join statements or aggregate functions. It is especially useful when statistical data for a bulletin board or complex search conditions are needed.Step-by-Step SQL Creation and Execution
1. Explain the Data Extraction Purpose
Explain to the AI what information you want to obtain based on the data stored in the bulletin board DB.Prompt: “Write an SQL query that pulls the ‘TOP 5 posts with the most comments in the last month’ from our bulletin board DB. The post title and the number of comments should also be output.”
2. Automatic Schema Reference (Context Aware)
The AI reads the entity files (Board.java, Comment.java) or schema.sql within the project to accurately grasp the table and column names before creating the query.
3. Utilization and Verification of DB Tools
The AI doesn’t just show the generated query; if there is a configured DB MCP Tool, it executes the query directly to check the results.- Using Tools: It reports the query results to the user immediately by accessing the local DB CLI or calling a connected DB management tool through
run_terminal_command.
Practical Application Scenarios
Strengthening Search Functionality
Prompt: “Create an SQL query that can search not only by title and content but also by the author’s nickname. Set the search term as an inclusion relationship (LIKE %search%).”
Statistical Data Extraction
Prompt: “Write a statistical query that groups the number of posts created daily by date. I only need data for the last 7 days.”
💡 Tips for SQL Creation and Management
- Request Performance Optimization: After creating a query, request, “Check if this query uses indexes well, and tune it so that its speed doesn’t slow down even if the amount of data increases.”
- Specify Dialect: If you mention the type of DB you are using, such as H2, MySQL, or PostgreSQL, it will be accurately generated with that specific DB’s syntax (functions, paging processing, etc.).
- Security Review: Request a review to ensure there is no risk of SQL Injection in the query generated by the AI, and apply a secure parameter binding method.