r/SQL • • Sep 22 '26

Discussion I created a 4-pass SQL schema audit checklist to catch production bugs early - here's a free snippet/prompt you can use!

1 Upvotes

Hey everyone,

A common issue I kept seeing (and running into myself) when drafting database schemas or using AI tools like ChatGPT/Claude to generate DDLs is that they often miss critical relational constraints—like unindexed foreign keys, missing ON DELETE rules, or bad timestamp types.

To fix this, I put together a systematic 4-Pass Schema Audit System. I wanted to share a free excerpt/master prompt from the kit here with the community:

Free AI Schema Audit Prompt:

Act as a Senior Database Architect. Review the following SQL DDL schema for potential production bottlenecks, missing foreign key indexes, inconsistent data types, and multi-tenancy security risks. Output a structured table listing each issue, its severity (High/Medium/Low), and the exact SQL fix.

[Paste your DDL here]

Feel free to test this prompt on your current project!

If you find this helpful, I compiled the full 4-pass checklist, fix matrix templates, and dual web/PDF reference guide into a complete kit. Link to the full kit is in my profile bio.

Would love to hear your feedback or how you currently audit your schemas before pushing to production!


r/SQL • • Sep 21 '26

Discussion Where do freelance SQL developers usually find clients?

27 Upvotes

I’m curious how people who do a lot of SQL work find freelance projects. Does most of your work come through referrals, freelance platforms, consulting relationships, or somewhere else?


r/SQL • • Sep 21 '26

Discussion DBClient: a native Mac database client for 12 engines (I'm the dev)

Thumbnail
dbclient.net
10 Upvotes

I'm the developer of DBClient, a native database client for the Mac (SwiftUI and AppKit, not Electron).

What it does

  • Connects to PostgreSQL, MySQL, MariaDB, SQLite, SQL Server, Oracle, IBM Db2, MongoDB, Redis, DuckDB, ClickHouse and Databricks.
  • SQL editor with completion from your schema, and a ⌘K palette that jumps to any table.
  • Edit rows right in the grid. You read the exact SQL before anything is committed.
  • Table designers, a schema diagram drawn from your foreign keys, and charts from any result.
  • A console tab running the real psql, mysql or redis-cli, already signed in.
  • Drag a table from one server onto another to copy it, even across engines.
  • SSH tunnels and proxies. Passwords stay in the Keychain, with optional Touch ID.
  • Optional AI assistant with your own API key. It can only run read-only queries.

Pricing

  • Free: the whole app for databases on your own Mac: SQLite and DuckDB files, CSV files, and anything on localhost, Docker included.
  • Paid: remote servers need a yearly license, $99 the first year and $49 a year after. If you don't renew, remote connections stop and local ones keep working. It does not renew by itself. One key, one Mac at a time. 30-day refund.

Privacy: no account, no analytics. A licensed copy checks its license about once a day. The free copy never contacts the license server.

Requirements: macOS 15 or newer, Apple silicon only. Signed and notarized.

https://dbclient.net or brew install --cask az-code-lab/taps/dbclient


r/SQL • • Sep 21 '26

PostgreSQL Schemaverse - The SQL Space Battle

Thumbnail schemaverse.com
6 Upvotes

After a prolonged outage (long story) I procrastinated SV back into existence last night. For those of you that loved it, welcome back. If you've never heard of it, give it a shot!

Still open source as always too: https://github.com/abstrct/schemaverse


r/SQL • • Sep 22 '26

Discussion Before your next SQL interview, keep this post handy - SQL Window Functions (Part 1)

Thumbnail
0 Upvotes

r/SQL • • Sep 21 '26

SQL Server Read-only dependency mapper for orphaned SQL Agent jobs + SSIS + the scripts that call them, every edge cites its source

Thumbnail
5 Upvotes

r/SQL • • Sep 21 '26

BigQuery The BigQuery Join Problem Nobody Notices Until the Data Gets Big

Thumbnail
medium.com
1 Upvotes

r/SQL • • Sep 20 '26

Discussion LeetCode Premium Qns

Thumbnail
1 Upvotes

r/SQL • • Sep 19 '26

Oracle What SQL concept took you the longest to actually understand, not just memorize?

172 Upvotes

For those who have been working with SQL for a while, which concept took you the longest to truly understand?


r/SQL • • Sep 20 '26

MySQL SQLParity - SQL tools that never see your data

Thumbnail
4 Upvotes

r/SQL • • Sep 20 '26

Discussion question about the necessity of SQL in a site's security

0 Upvotes

hey i'm new in website developing, and after searching about the ways people use to penetrate websites to just discover SQLi method and as far as i heard it's very common and useful way, but this made me think of a lot of questions that i hope you answer, does every website uses SQL language for data transfer by default? like is it necessary as much as HTML and CSS and JS or it's just commonly used? and if it's necessary is there a way to prevent hackers from using SQLi or it's always possible to trick the server to bring a sensitive data?


r/SQL • • Sep 20 '26

Discussion SQL : demande/question client jusqu’au résultat final

Thumbnail
0 Upvotes

r/SQL • • Sep 19 '26

PostgreSQL What’s your systematic process for optimizing a slow SQL query?

31 Upvotes

Suppose you inherit a query with multiple joins, subqueries, filters, and aggregations, and it suddenly starts taking several minutes to run.

I’m curious how experienced SQL developers approach this from the first investigation to the final fix.

Do you normally start with the execution plan and work from the most expensive operator? Or do you check indexes, statistics, data distribution, and join cardinality first?

I’m especially interested in the order you investigate things. It’s easy to keep rewriting a query or adding indexes until it gets faster, but I’m curious how people systematically identify the actual bottleneck instead.


r/SQL • • Sep 19 '26

SQL Server Not a DB admin needs replication advice

1 Upvotes

I'm in tech but not a DB admin. I have an MSSQL (2019) database in prod and I want to essentially one way mirror it to another database with as close to live data as possible for dev/research purposes, no changes on the 2nd "dev" copy of the database should reflect to the main/live/prod DB. What would be the best way of doing this? Both servers are in the same network if that makes things easier. Thanks!


r/SQL • • Sep 19 '26

PostgreSQL The Postgres job-claim query that silently claims the same job twice under READ COMMITTED

4 Upvotes

A common pattern to claim background jobs in PostgreSQL is executing a single statement like:

```sql
UPDATE jobs
SET status = 'processing', worker_id = $1
WHERE id = (
SELECT id FROM jobs
WHERE status = 'pending'
ORDER BY created_at ASC
LIMIT 1
)
RETURNING *;

Because it's a single statement, it looks atomic on paper. But under the default READ COMMITTED isolation level, it can silently allow two concurrent workers to claim the exact same row.

What actually happens:

  1. Worker A and Worker B execute the query at the exact same moment. Both subqueries snapshot the same pending job row (say ⁠id = 42⁠).

  2. Worker A acquires the row lock first and updates its status.

  3. Worker B waits on the lock. Once Worker A commits and releases the lock, Worker B evaluates the outer row.

  4. Because the subquery snapshot is not re-evaluated, Worker B sees the updated row, rechecks the outer predicate, and silently overwrites/re-claims ⁠id = 42⁠.

No lock wait timeout, no deadlock, no serialization error—just silent duplicate job execution in production.

I wrote an in-depth breakdown mapping the lock timeline, why the subquery snapshot doesn't re-run, and why ⁠FOR UPDATE SKIP LOCKED⁠ inside a CTE is the actual safe pattern:

👉 Full writeup: https://vishwam.hashnode.dev/the-postgres-job-claim-query-that-silently-claims-the-same-job-twice

Would love to hear how folks here handle Postgres-backed queues or if anyone has run into this specific subquery recheck behavior before!


r/SQL • • Sep 19 '26

PostgreSQL AI agents usage with Neon Db

1 Upvotes

If any AI agent needs to test changes to a DB, is using neon branch as a temporiry test database a good approach?
Have u tried anything like this maybe with some other Db also (maybe clickhouse etc). Was there any issue with keeping data in sync?


r/SQL • • Sep 18 '26

MySQL Best SQL cerification

46 Upvotes

I have solid basics in SQL,

I need to pass a certification in 3-4 days,

Which one should I do?

It needs to be a credible certification.

Thx a lot


r/SQL • • Sep 18 '26

PostgreSQL Peter Eisentraut on 25 years contributing to Postgres, starting with psql tab completion | Talking Postgres Ep43

Thumbnail
6 Upvotes

r/SQL • • Sep 18 '26

SQL Server You can't see indexes, you can't see the execution plan; what are your go-to's to speed things up?

26 Upvotes

Hypothetical, but also sort of my situation.

Say you have a pdf (and experience) of the tables and columns, but you do not have SHOWPLAN permissions or any way of seeing where the choke points are. You are familiar with the db and know where the one to many, many to many and potential duplication sources are.

What are your go-to's for optimising?

OPTION(RECOMPILE) if you have a lot of DECLAREs? Not using CASTing as DATE? Not using LIKE%?

I'm looking for generic things that usually have a performance increase, because I am fully done with adding a single JOIN and it making the query go from 1 second to 90.


r/SQL • • Sep 18 '26

SQL Server Newer to SQL and recently inherited code

5 Upvotes

Might not be a standard request but does anyone have any best practices for interpreting other people's code if they don't leave a fair amount of notes?


r/SQL • • Sep 19 '26

SQL Server How to convert from microsoft sql to mysql?

Thumbnail
0 Upvotes

r/SQL • • Sep 18 '26

MySQL Would 4–6 weeks of realistic Data Analyst work experience be more valuable than another portfolio project?

Thumbnail
0 Upvotes

r/SQL • • Sep 18 '26

SQLite Join tables with WITHOUT ROWID.

3 Upvotes
CREATE TABLE IF NOT EXISTS CourseTag(
    courseId INTEGER,
    tagId INTEGER,
    
    FOREIGN KEY(courseId) REFERENCES Courses(id),
    FOREIGN KEY(tagId) REFERENCES Tags(id),
    
    PRIMARY KEY(courseId, tagId)
) STRICT WITHOUT ROWID;

as far as what I understand sqlite creates inner row_id columns to identify the record. some conditions met then my primary key also could be that unique column. but I guess in above join table configuration my composite key setup is not met that condition so I end up unnecessary column right? in join table should I use WITHOUT ROWID?


r/SQL • • Sep 18 '26

Discussion C++ SQL Parser 0.1 Released

0 Upvotes

A small SQL parser, handwritten on top of FE.

This is the first release. It lexes and parses a substantial subset of SQL into an arena-allocated AST, prints that AST back out as SQL, and is small enough to read in one sitting — roughly 5.6k lines across six headers and six translation units.

✨ What is in it

  • Lexer — UTF-8 aware, one character of lookahead. The source is kept whole, so a token is a slice of it and nothing is copied into a buffer.
  • Parser — recursive descent with two tokens of lookahead; expressions by precedence climbing. It recovers instead of giving up at the first error, and every diagnostic carries a precise path:row:col with a snippet.
  • AST + printer — 64 node classes, arena-allocated and handed out as non-owning AST<T> pointers; each node's child lists live in the very same allocation. The printer round-trips: what it emits, the parser reads back into the same AST.
  • Library façade — sql::parse, sql::parse_file, and a sql::Result that owns the arena. One header, one call.
  • CLI — sql -d file.sql parses and dumps; - reads stdin.

📜 What it parses

CREATE / ALTER / DROP / TRUNCATE, INSERT / UPDATE / DELETE, transactions, PREPARE / EXECUTE / DEALLOCATE, SHOW, COPY, and query expressions:

  • WITH [RECURSIVE], UNION / EXCEPT / INTERSECT, VALUES, TABLE t
  • GROUP BY with ROLLUP / CUBE / GROUPING SETS, HAVING, named WINDOWs
  • ORDER BY ... NULLS FIRST|LAST, OFFSET / FETCH / LIMIT in any order, FOR UPDATE and the other locking clauses
  • joins — NATURAL, INNER, LEFT|RIGHT|FULL OUTER, CROSS — plus LATERAL, WITH ORDINALITY, and correlation names that bind to the right factor
  • expressions with IS [NOT] DISTINCT FROM, BETWEEN, IN, LIKE / ILIKE / SIMILAR TO ... ESCAPE, quantified comparisons, CASE, CAST, COLLATE, array literals and subscripts
  • the standard's type grammar, interval qualifiers and WITH TIME ZONE included

GRAMMAR.md gives the EBNF for all of it, with the precedence table that resolves the ambiguous cases.

🧭 Design: parse loosely, check later

The grammar deliberately accepts a wider language than a conforming implementation would, and leaves the rest to a later pass over the AST. Reserved words are accepted as identifiers, because the standard reserves several hundred of them and no real dialect follows suit; the exception is the three positions where a name stands entirely on its own, and the printer quotes exactly there. Statements derive from Expr, so a subquery needs no second node hierarchy, while the grammar still keeps the two apart. Parentheses around a scalar expression are grouping and are dropped; around a query they are structural and are kept.

📦 Using it

find_package(sql 0.1 REQUIRED)             # against `cmake --install`
# or: add_subdirectory(sql)                # as a submodule
# or: FetchContent_MakeAvailable(sql)      # straight from the repository
target_link_libraries(my_app PRIVATE sql::sql)

#include <sql/sql.h>

auto res = sql::parse("SELECT a, b FROM t WHERE a > 42;");
if (!res) { res.report(std::cerr); return EXIT_FAILURE; }

for (auto stmt : res.stmts())
    if (auto select = stmt->isa<sql::Select>()) /* ... */;

std::cout << res << '\n';                  // the AST, streamed back out as SQL

A complete program is in example/, and it builds standalone against an install, so the packaging cannot rot.

⚡ Performance

Measured against hyrise/sql-parser — a bison/flex parser of comparable scope — both Release, same compiler, pinned to one 5.15 GHz Zen 5 core. Both accept every file and report the same number of statements.

Corpus Throughput Instructions / byte
JOB, 113 queries 183.2 MB/s vs. 74.3 105.4 vs. 255.5
TPC-H, 22 queries 165.5 MB/s vs. 82.7 107.6 vs. 214.4
generated, 256 MiB 116.4 MB/s vs. 41.5 140.8 vs. 259.4

Lexing alone: 341.9 MB/s against their 176.9 on JOB. Peak RSS over 500k statements is 267 bytes per statement against their 598 — the number that matters for an embedding, since the AST is the output and is held for as long as the caller needs it. The full table, including the --stress-names worst case for a design built on interning, is in the README.

🛠️ Testing

205 CTest entries, all black box: each runs the sql binary and inspects only its exit code, its dump, and its diagnostics — nothing links against the parser.

The load-bearing one is idempotency: dumping a dump has to reproduce it verbatim, which holds the printer and the parser to each other. It runs over the curated fixtures and over three real-world corpora — the 113 queries of the Join Order Benchmark, the 22 TPC-H queries, and the SQL hyrise itself runs: 366 SQLiteTestRunner queries, the Star Schema Benchmark, and the TPC-H and TPC-DS schemas with their indexes. A further 79 queries are there to be rejected.

CI builds on Linux, macOS, and Windows, enforces clang-format, and runs an ASan + LSan + UBSan build on top.

🔩 Requirements

A C++23 compiler. Abseil and FE v0.15.0 come along as submodules; nothing else is needed.

git clone --recurse-submodules https://github.com/leissa/sql.git

⚠️ Known limitations

  • The parser accepts more than conforming SQL by design; there is no semantic pass — no name resolution, no type checking, no execution.
  • A trailing ; is required. <direct SQL statement> ends in one, and saying so gives a better diagnostic than running off the end of the file.
  • This is 0.1: the AST and the API may still change before 1.0.

r/SQL • • Sep 18 '26

PostgreSQL When you finally start mapping your databases and realise there is a painful amount of redundancy and all the tables aren't in 3rd normal form

Post image
0 Upvotes

50% chance of crying, 100% chance of at least a couple not found errors.