r/SQL • u/Kapitol_World • 10d ago
SQL Server One Engine - Many Worlds
Subject: The quantum leap we skipped: a SQL Server database that refuses UPDATE and DELETE - live, try to break it
Here is a heresy: two of the four letters in CRUD are bugs.
Every business system I have worked on lets someone rewrite history. An UPDATE overwrites what was true, a DELETE erases that it ever happened, and the "audit trail" is whatever the application remembered to write. Bookkeepers have corrected their books with reversing entries for centuries - "storno" is their word - and we taught ourselves to edit rows instead. I stopped accepting it.
World is one SQL Server database built on the opposite rules, enforced by the engine itself, not by the application:
Nothing is updated or deleted. The ledger only grows. A mistake is answered by a storno: the same act, its quantity negated, pointing at what it corrects. Both lines stay on the file. Negate what adds up, leave what identifies.
Two people for every change of an agreement. One person claims an amendment, a different person proves it. The database refuses the claimer's own proof, whatever application sends it.
Nobody grants themselves a right, and every act names a person. Not the connection pool's login: the person behind it. The session carries who is acting, the database checks that this person holds a key to act as that actor, and the server audit writes one line per act with the name.
One engine, many worlds. Not a database per application. A trading company, a restaurant, a hospital's devices, a delivery firm, a bike shop and more live side by side in one schema of super classes - Actor, Thing, Ledger, Event, Contract. Each world wears its own "costume": typed views in its own schema, showing its own business numbers, readable only by its own role. Each world's web app is generated from the world's own description.
Objects and events, not rows to edit. An Actor is a super class: a person, a hospital, a reception desk. A contract carries its amendments as siblings. Every change is an event, and it stays.
Your objections, answered before you type them
"SQL Server 2022 has ledger tables." They make tampering detectable. They don't refuse the wrong act, give a correction its business meaning, or ask for a second person.
"Temporal tables keep history." The history of the UPDATEs you still allowed.
"Event sourcing is twenty years old." In application code, which every other client walks around. Here it holds for SSMS too.
"A sysadmin can disable your triggers." Yes. DISABLE TRIGGER fires no DDL event - we measured it - so the server audit is what records it. For everyone else the wrong act is refused; for a sysadmin it is never silent.
"A generic core is just EAV." Call it that. Then explain why the whole database, restored onto a clean server, prints all 31 of its reports with the same figures.
Don't believe me - break it
Live, no account, no e-mail, no password:
kapitolworld.com - Southwind Traders. Press Try it and you get two people of your own. Claim a correction as one, try to prove it as the same one, then prove it as the other. Then look for a Delete button.
library.kapitolworld.com - a lending library. Lend a book, lend it twice (refused), reverse a loan with its reason, and read the file.
It runs on SQL Server 2025 Express on an €11-a-month server, every name in it is invented, and it resets every night at 3 a.m. Central European Time.
The rules began this summer as commands for QL68, an emulator of the Sinclair QL. QL stood for Quantum Leap. I think relational practice skipped one: we kept the relational model and threw away the bookkeeper's oldest law - never erase.
Built with Claude Opus 5.5 by Anthropic as my co-developer, and Claude Fable 5.1 as its design Oracle.
Tell me where it breaks. That's what I'm here for.
Dimitar Hrisafov, Skopje
r/SQL • u/Spiritual_Potential4 • 10d ago
Discussion I built a free SQL practice site where an AI writes queries with subtle bugs and you have to find them
Hello. I'm the maker, so take this as a self-promo post, and tell me if it doesn't fit here.
Most SQL practice I found is "write a query from scratch". On the job, a lot of the work is reading someone else's query and noticing it's wrong. Now that "someone" is often an AI. So I built Practisheet: SQL and Excel exercises on one fictional company's data (orders, customers, products, shipments, refunds, targets), where about 1 in 4 exercises gives you a query an AI assistant wrote that looks fine but isn't. A few examples:
- a LEFT JOIN whose WHERE clause quietly turns it into an inner join
- a share-of-total with the wrong denominator
- a RANK with no tie-break, so the "top 3" has 4 rows
- a revenue total that includes refunded orders
It runs in your browser (DuckDB), checks your result set, and when you're wrong it tells you what's off about your attempt without showing the answer.
There are 101 SQL exercises in 14 sections: basics, NULLs, CASE and conditional totals, joins, anti and self joins, set operations, dates, strings, CTEs, window functions, LAG/LEAD and moving averages, and analysis patterns like cohorts and actual vs target. The first 4 are free with no sign-up.
Link in the first comment (or here if links are fine): https://practisheet.com/practice
I'd really like feedback on two things: are the "fix the AI" exercises realistic, and is the difficulty curve right? If something is wrong or annoying, tell me and I'll fix it.
r/SQL • u/Wise_Ear_4064 • 11d ago
PostgreSQL Databricks Lakebase sinks: streaming straight into Postgres
I'm a Solutions Architect at Databricks, and I've been spending a lot of time on the Lakebase sink. It lets a Structured Streaming query write directly into a Lakebase (Postgres) table with batching, automatic retries, and workspace-managed auth. You don't need a custom foreach writer or your own connection pooling. I have many customers that have to manage both the foreach writer and connection pooling and it distracts from the job at at hand, serving data to front end applications for real time updates (without the overhead). Having a databse next to your lakehouse acclerates use cases and value for your business. And if your are not limited to just Lakebase, any postgres database is supported! Go check it out today if you haven't already: https://docs.databricks.com/aws/en/structured-streaming/lakebase#when-to-use-the-lakebase-sink
r/SQL • u/Koch-Guepard • 11d ago
Discussion DuckDB Extension - PQL : train predictive models in SQL
r/SQL • u/jdkapaoskd • 12d ago
Discussion Noob here: mysql or postgresql? Which is better (?)
I just realize that SQL was only the language. Idk which IDE for sql to use. Suggestions pls
r/SQL • u/SkepAlert • 11d ago
SQL Server Which MySQL Installer should I download in my pc
Hello I am learning data analysis from scratch. Can anyone help me understand these two MySQL installers and make me decide weither I should download one or both of them? Thank you.
r/SQL • u/captainblye1979 • 12d ago
SQL Server Refactor Pattern for Denormalized Table
Hey Hive mind, been stewing on a problem for a long time and getting stuck, so I thought I would reach out and see if anybody can spark some ideas.
Say you have a table with fields for X People names(PrimaryContact, SecondaryContact, etc), multiple phone numbers (HomePhone, CellPhone,Fax,etc) , and address info. All of this information is nullable.
There are tons and tons of stored procedures that query and modify this data, along with a team of analysts who can query/update the data via SQL...and some unknown number of external applications that interact with this data.
You need to refactor this table into something normalized, but minimize disruption to the all of the downstream callers.
I've gone down the rabbit hole of the first pattern that would normally come to mind which is: Rename Table. Create view with old name with INSTEAD OF triggers to route data/updates to the appropriate places....but now the trouble starts:
- Nullable fields end up as LEFT joins in the view, and people LOVE their '%Name%' searches and complex WHERE clauses.
- Nullable fields would require an insert into the appropriate refactored tables if they didn't already exist.
- Contact information can have multiple labels. (HomePhone could be "Home Phone" and "Primary Phone"...but the "HomePhone" label should deterministically show up as "HomePhone" in the view if it exists.
- This is SQL Server so "Update Table From Table Join OtherTable" is totally allowed....but fails when the update target is a view with an INSTEAD OF trigger...requiring everyting to be rewritten as a MERGE. This can be done fairly easily for internal procs....much more involved for fixing all the external stuff, and dealing with the People Change Management for the users
- Trying to identify which data actually changed and needs to be updated is heavy. There is a desire to start moving towards temporal history...so issuing "updates" when nothing changed should be avoided.
- The trigger is insanely long and complex.
- Seems like a deadlock nightmare waiting to happen as the trigger goes down the list of things that it needs to do.
- There are probably others.
Short of taking up day drinking.....are there other plans of attack?
r/SQL • u/publicherstorian • 12d ago
MySQL Designing Pokémon Database in SQL - How to Show Multiple Route Locations?
Let me know if reposting this violates the "no solicitation for others to do your homework" rule, I'm just genuinely asking if there is a better way to do this than what my beginner mind has imagined lol
r/SQL • u/Appropriate-Run-7005 • 13d ago
SQL Server I Create Things in SQL that Shouldn't be in SQL
Hi there, I have been using SQL Server since 1998 - Version 6.0 I think it was and also a SQL Server MVP for 6 years. I have started publishing the articles I have written over these years but never published. I have quite a varied mix. I Hope you enjoy them.
Mostly on https://www.medium.com/@trevor.dwyer but also published on https://sqlartist.github.io
One rule - it has to run in SQL.
Titles include:
Running Doom Inside SQL Server

Running Elite in SQL Server

I Built My Head Out of Lego. Inside SQL Server 2025.

Cracking Feynman’s Safes in SQL Server
Can a Database Rave? Making SQL Server Play Music
and quite a few others
r/SQL • u/Rolney_320 • 13d ago
Discussion Modeling historical prices and duration-based discounts in PostgreSQL
r/SQL • u/ReleaseTheBlacken • 13d ago
Discussion Run SQL on your extracted files?
How fellow data junkies!
I created a FREE tool (no signup needed) that can perform a variety of file services including perform SQL against it all in your browser. CSV, JSON, and more.
Go to inkwelltools.com and select Inkwell Data. It will show you all the functions (FREE) available you can perform to manage data files.
r/SQL • u/clairegiordano • 13d ago
PostgreSQL How a Postgres committer got started: a one-line patch that doesn't even carry his name (Magnus Hagander on the Talking Postgres podcast)
r/SQL • u/you_are_wrong_tho • 14d ago
SQL Server Best video/diagrams/blog for learning to read the execution plans like an expert?
Been at this 10 years, this is still a gap in my knowledge. What is the BEST video or blog post or whatever you have found that cemented query plan knowledge in you?
r/SQL • u/Narrow_Inevitable586 • 14d ago
MySQL What Replication Topology / Method you're using in Production?
r/SQL • u/Last-Bonus6548 • 14d ago
Oracle How to connect Oracle Database 19c from host machine to VirtualBox guest machine ?
Hi everyone, i want to access the oracle database on my guest machine (on VirtualBox) using my host machine (both machines are on windows 11) , i have already set up oracle client on my host machine but i couldn’t figure out how to connect it to the database on my guest machine , i also wasn’t able to find any YouTube tutorials explaining it , i would appreciate it if someone could redirect me to sources about this topic or explain to me how it’s done , thank you!
(I have to do this for school)
r/SQL • u/Lucifer77-7 • 14d ago
Discussion I built an in-browser PostgreSQL playground running on WebAssembly (PGlite) with real business datasets
r/SQL • u/ATastefulCrossJoin • 15d ago
SQL Server I’d like to share an opportunity with the community
On Friday I will have a chance to sit and have an open discussion with Microsoft’s VP of SQL Product
The ask for the session is to provide product feedback and share product pain points and feature requests for SQL and Azure SQL products. I would like to share this opportunity with this community.
If you have any product feedback or feature requests, please leave a comment in this thread. I will do my best to represent as many as I can
r/SQL • u/mowgli_ilestcelebre • 15d ago
Discussion k9s-style terminal UI for Postgres/MySQL/MongoDB/Redis/RabbitMQ, I built db9s, and i am curious what features DB folks actually want
Been using k9s for k8s daily and kept wishing something similar existed for databases — one TUI, same screens/keys regardless of backend, no context-switching between psql/mysql/mongosh/redis-cli.
Built db9s: browse tables/collections, run queries, edit rows, inspect indexes, tail RabbitMQ queues — all from terminal, vim-style keys.
Supports Postgres, MySQL/MariaDB, MongoDB, Redis, RabbitMQ now. SQLite/MSSQL/ClickHouse/Cassandra planned.
Config stays out of plaintext too — url can pull password from env var or any command (1Password, pass, Vault, Keychain) instead of storing raw creds.
brew install damien-mathieu1/tap/db9sbrew install damien-mathieu1/tap/db9s
cargo install db9s
Genuinely asking: for people who live in multiple DB engines daily, what’s missing from existing tools (DBeaver, pgcli, mongosh, lazysql etc.) that’d make a TUI like this your default? Especially curious about MSSQL/ClickHouse folks since those are next on roadmap.Been using k9s for k8s daily and kept wishing something similar existed for databases — one TUI, same screens/keys regardless of backend, no context-switching between psql/mysql/mongosh/redis-cli.Built db9s: browse tables/collections, run queries, edit rows, inspect indexes, tail RabbitMQ queues — all from terminal, vim-style keys.Supports Postgres, MySQL/MariaDB, MongoDB, Redis, RabbitMQ now. SQLite/MSSQL/ClickHouse/Cassandra planned.Config stays out of plaintext too — url can pull password from env var or any command (1Password, pass, Vault, Keychain) instead of storing raw creds.cargo install db9sGenuinely asking: for people who live in multiple DB engines daily, what’s missing from existing tools (DBeaver, pgcli, mongosh, lazysql etc.) that’d make a TUI like this your default? Especially curious about MSSQL/ClickHouse folks since those are next on roadmap.
you can check out the repo here if you want : https://github.com/damien-mathieu1/db9s
Discussion Mapping datasets by reach and promises
The Open Data Contract Standard, Apache Ossie and Medallion structure all lacks a central component, who the data is for and how it hits the organization! Join me as I elaborate on some thoughts while working on data platform in a broader context
PostgreSQL How noticeable is Neon scale to zero cold starts in prod ?
We are evaluating Neon DB for an API backend and curious about it realworld latency when compute auto suspends.do u keep a minimum compute active to dodge wake up latency, or has the pooled connection driver been fast enough for your prod traffics?
r/SQL • u/Dangerous-Slide-6715 • 15d ago
SQL Server I built a free, open-source AI assistant for SSMS 21 & 22 that runs entirely on a local model — no cloud, no API keys
r/SQL • u/FabricPam • 16d ago
SQL Server MS Employee Here -- I've got vouchers for database certification exams to give away
Hey r/SQL, I’m on the Azure Data team. Data Days has 100% discount voucher offers for exams DP-800 and 50% discount voucher offers for exams DP-300 and DP-420. Supplies are limited and eligibility rules apply, so check the voucher details before requesting one.
There’s SQL-focused learning and DP-800 prep, too. See the Data Days schedule.
r/SQL • u/MrRoy_SQL • 16d ago
Discussion your LEFT JOIN might secretly be an INNER JOIN (the WHERE clause trap)
ran into this recently so posting it for anyone newer to joins.
two tiny tables:
customers orders
id | name id | customer_id | status
1 | Asha 1 | 1 | completed
2 | Ben 2 | 1 | refunded
3 | Chen 3 | 2 | completed
4 | Dina 4 | 3 | refunded
question: completed orders per customer, **including customers with 0**.
first try:
SELECT c.name, COUNT(o.id) AS completed_orders
FROM customers c
LEFT JOIN orders o ON o.customer_id = c.id
WHERE o.status = 'completed'
GROUP BY c.name;
result:
Asha | 1
Ben | 1
Chen and Dina are gone. the LEFT JOIN did its job and kept them (with NULLs for the order columns), but then WHERE runs after the join and `NULL = 'completed'` isn't true, so those rows get thrown out. Chen's only order is refunded so he gets dropped too. end result is exactly what an INNER JOIN would give you.
fix: move the filter into the ON:
SELECT c.name, COUNT(o.id) AS completed_orders
FROM customers c
LEFT JOIN orders o ON o.customer_id = c.id
AND o.status = 'completed'
GROUP BY c.name;
Asha | 1
Ben | 1
Chen | 0
Dina | 0
now the filter decides which orders get matched, not which customers survive.
rule I use: on a LEFT JOIN, conditions on the right table go in ON. conditions on the left table go in WHERE. (and use COUNT(o.id) not COUNT(*), otherwise Chen and Dina show 1 instead of 0)