---
name: sql-best-practices-bb6818b4af16
description: Use this skill when writing SQL queries — selects, joins, aggregations, window functions, or schema modifications. Apply whenever SQL is needed to ensure correctness, safety, and performance.
category: data_analysis
---

# SQL Best Practices

**Query quality:**
- Use `SELECT col1, col2` — never `SELECT *` in production code.
- Use CTEs (`WITH`) for readability instead of deeply nested subqueries.
- Filter early: apply `WHERE` before `JOIN` when possible to reduce data scanned.
- Use `EXPLAIN` / `EXPLAIN ANALYZE` to inspect query plans for slow queries.

**Safety:**
- Always use parameterized queries from application code — never string interpolation.
- Wrap destructive operations (`DELETE`, `UPDATE`, `DROP`) in a transaction.
- Test on a staging/dev environment before running on production.

**Naming:** `snake_case` for tables/columns, descriptive names, consistent pluralization.


---
Source attribution: aiming-lab
Original project: https://github.com/aiming-lab/MetaClaw
License: MIT
License information: https://opensource.org/license/mit
Original upstream instructions; downloaded from Mega AI Hub.

## Upstream license notice

MIT License

Copyright (c) 2026 Gabriel Moreira

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.



# Mega AI Hub resource metadata

Creator / publisher: aiming-lab
Original project: https://github.com/aiming-lab/MetaClaw
Attribution basis: Upstream repository explicitly recorded in package mirror path

Fields of work: Data & Analytics, Development & Engineering, Operations
Roles: Business Process Analyst, Data Analyst, Data Scientist, Database Administrator, ML / AI Engineer
Specialties: Cross Platform, Database
Tools: MongoDB, MySQL, Sql Server, PostgreSQL, SQLite
Country applicability: Country not specified
Classification basis: Source catalog labels
Instruction SHA-256: 6f9995e3ef7509fe455bdd2c1f31cc6ef3f50d41924b0cad613ccf695674dea7
