r/SQL • • 6m ago

SQL Server T-SQL

1 Upvotes

Hi community, I'm studying computer programming and my database teacher don't know anything about SQL. let's pass to my ask, how can ı learn T-SQL for my education


r/SQL • • 10h ago

SQLite A 60-second SQL test with three traps. Most AIs I've graded fall for at least one

1 Upvotes

I grade AI models on data questions for a living experiment, and the same three mistakes keep showing up. Here's a pocket version: paste it into whatever AI you use and see how it does. The database is SQLite.
sales (sale_id, amount):
1: 412.75 · 2: 268.40 · 3: 529.99 · 4: 145.20 · 5: 876.10 · 6: 233.65
7: 694.30 · 8: 358.55 · 9: 921.00 · 10: 187.45 · 11: 543.80 · 12: 476.25
returns (sale_id, one row per return event, 25 rows):
2, 5, 9, 2, 7, 3, 2, 11, 5, 12, 9, 4, 2, 7, 10, 5, 1, 9, 12, 4, 11, 8, 10, 13, 13
Task: write SQLite SQL returning exactly two columns: returned_sales (how many sales came back) and total_returned_sales (their total value, each sale counted once), and state the two numbers.
Answers, so you can grade it yourself:
Pass: 11 and 5,413.79, exactly two columns, SQL SQLite can run.
Trap 1: a total of 11,860.19 means it joined and summed, so sale 2 was counted 4 times. Counted twice (or four times).
Trap 2: a count of 12 means it counted sale 13, which is in returns but was never sold.
Trap 3: FETCH FIRST, EXTRACT, or more than two columns: wrong database or didn't follow the order.
On the full-size version of this case (500 return rows, 99 sales returned more than once), the counted-twice error invents $31,490.03. I've watched a model miss it twice in graded matches.
Curious what yours answered. Post the number it gave.


r/SQL • • 17h ago

PostgreSQL Self-hosted alternative to Neon's HTTP driver: query your own Postgres via fetch()

1 Upvotes

Connecting serverless and edge functions to self-hosted PostgreSQL can be tricky. Some runtimes have TCP limitations, and opening database connections on every invocation adds overhead.

Neon offers an HTTP driver for its platform, so I built HTTP PostgreSQL Gateway for self-hosted PostgreSQL.

It runs alongside your database and lets you query it using plain fetch().

  • Persistent PostgreSQL connection pooling

  • Scoped API keys mapped to PostgreSQL roles

  • Async queries for long-running operations, so functions don't have to wait for results

  • Atomic batches and transactions

It doesn't replace PostgreSQL or make queries faster. It handles connections and execution outside your serverless functions.

Security: It accepts client-supplied SQL, so use least-privilege roles and restrict network access. The project is new and hasn't had much external review yet.

Repo: https://github.com/http-postgres/http-postgres

How are you connecting self-hosted PostgreSQL to serverless or edge functions today? Feedback welcome.


r/SQL • • 17h ago

Discussion Database design

Thumbnail reddit.com
1 Upvotes

r/SQL • • 1d ago

Discussion Why you shouldn't do application-level sharding

Thumbnail
planetscale.com
32 Upvotes

r/SQL • • 1d ago

Discussion Should I stick to standard SQL or use DBMS-specific features?

6 Upvotes

Different DBMSs have their own functions and features. For example, PostgreSQL supports every() function, which isn't available in MySQL.

Is it better to stick to standard SQL as much as possible, or should I take advantage of DBMS-specific features? What are the benefits of staying close to the SQL standard?


r/SQL • • 1d ago

Discussion Anyone here have experience tutoring SQL? How did you start?

7 Upvotes

I would like to begin tutoring SQL to earn some money. I'm not exactly sure where to start though. I don't want to just tutor SQL, I'd like to do Python as well. Should I aim for a specific niche or just teach it zero to hero style?


r/SQL • • 1d ago

Discussion DBerio update: what I changed after your feedback on my SQL client

0 Upvotes

About a month ago, I posted my SQL client, DBerio, here and asked for feedback. A lot of you took the time to reply, and your comments helped shape this update. Same disclaimer as last time: I'm a solo developer from Korea, this is self-promo, and I use a translator to write.

Things you asked for

  • u/MrRoy_SQL asked for a visual EXPLAIN. The Profiler tab now shows PostgreSQL, MySQL and MariaDB plans as a tree, highlighting the slowest step and points to check. You can also summarize a plan on one page and print it or save it as a PDF.

  • u/vincent_sch pointed out that EXPLAIN ANALYZE runs the statement, so analyzing an UPDATE would change data. On PostgreSQL, measured plan runs now use a read-only transaction, so the server blocks writes. Statements containing functions that a read-only transaction can't stop, such as ending a session, ask for confirmation first. Thanks for catching that. It was a real hole.

  • DROP, TRUNCATE and ALTER … DROP statements run from the editor now ask for confirmation. If the connection is marked as production, you also have to type the target name.

Other changes

  • Long text and JSON from the result grid now open in a larger Value Editor, with line numbers, search, JSON error locations and an editable JSON tree. Big integers and long decimals keep their exact digits.

  • There's a dark mode now.

  • If a connection drops, it reconnects when you expand the object browser or open a table, as well as when you run a query.

  • Fixed a bug where "Discard Edit" in the grid saved the value instead of discarding it. Sorry about that one.

  • Commit, Rollback and autocommit no longer hang while a long query is running.

Searchable query history across connections and a side-by-side diff of two result sets are still on my list. I haven't finished them yet.

Since 1.2.0, the app sends basic usage statistics: days opened, app version, OS and language. It never sends query text, connection details, table names or data, and you can turn statistics off in Settings.

DBerio is available on Mac and Windows and supports MySQL/MariaDB, PostgreSQL, SQLite and Redis. The free version includes every feature, with up to 3 saved connections and 2 open at once.

If you find a bug, notice something that feels off, or have a feature in mind that would make you switch, please comment here or send me a DM. The fixes above started with comments like those, so please keep them coming.


r/SQL • • 21h ago

Discussion How practical are ERDs when coding?

0 Upvotes

It was my belief in the beginning of 2025 that this project would help ppl who work with databases. There were three main ideas I thought should be different from how it's been done for decades:

  1. There should be no proprietary syntax.

  2. ERDs must be rendered on the fly while coding (so no need for a separate tool or website)

  3. Cursor on a code segment must render that exact schema instantaneously (vs. rendering giant schemas all at once).

What's you perspective on this in 2026?


r/SQL • • 1d ago

Discussion Where do you actually write most of your SQL these days?

0 Upvotes

Curious how much this has shifted lately — feels like more people are moving across different types, but maybe that’s just my bubble. If you picked Other or switched recently, what made you switch?

716 votes, 2d left
SSMS
DBeaver
DataGrip (or other JetBrains IDE)
VS Code (plus, any SQL extension)
Web console (Azure, AWS, Supabase, etc.)
Other: CLI, pgAdmin, Workbench… (comment)

r/SQL • • 21h ago

BigQuery Is SQL becoming obsolete?

0 Upvotes

I had an interest with sql when mentioned by a minor subject of mine and its relation to my current major management accounting. I would like to learn and add that to my future resumé but I can help but feel its useless now because of AI where english words are automatically translated into codes. So is there a demand for this in the future? Or should I focus my resources elsewhere?


r/SQL • • 1d ago

SQL Server Wire level intelligent response caching solution for SQL Server - Change Tracking Mode

3 Upvotes

Hey, I've posted before on some of my custom TDS listener stuff. All custom TDS wire protocol in c#. I think this one is probably my most useful one so far. I had posted one earlier on the first cut TTL mode, but this demo covers the more sophisticated one, the change tracking mode.

Full Open Source Code (MIT): https://github.com/TroBeeOne/DaffyZoom
Nuget Install and Instructions: https://www.nuget.org/packages/Daffyzoom
Hour long podcast on how it works (it's ~98% correct but it made a couple mistakes): https://www.youtube.com/watch?v=mwMDmuLjCCY

What it does:

- It solves the problem of 1000+ repeated slow queries that are hitting stale tables. It also helps you identify those slow queries so you can 'actually fix' the indexes, plans, the proper way.

- Sits on the wire in-between client and SQL server

- On the return from SQL Server message it tee's the call, one sync back to client, another async to my caching system. If a repeat query (above 5 second default setting) if tables haven't changed, it now returns instant cache, 0 seconds. if table changed? it reruns the 7 second query and updates the cache on the way back..

- I have data warehouse mode, ttl, just caches everything repeated. with expiration.

- I have change tracking mode (this is the demo I'm showing today). This caches unless a change is made, then it runs the query as normal and refreshes cache.

- Change Tracking Mode requires change tracking enabled on target tables for repeated query. You might think, well, we're now hitting SQL Server 2 times? Yes, but the check is a microsecond. And if you're serving cache from a 10 second query instantly, and ppl are hitting that report at 8am 1000 times, you saved some compute time and made your clients super happy!

- I DO support Entra Service Credentials, but I do not support MFA. I also don't support kerberos yet, I could, but that would require me setting up a domain controller VM, and with little interest so far, no incentive.

Anyway, I haven't tested this in a major production environment yet, so if you do choose to try it, as with anything, test it well and let me know if you find issues.

Here's the demo, cheers. If you try it and run into questions or have issues, let me know. It only caches long queries. It doesn't poll SQL Server for all queries, only the slow ones. It doesn't cache things with getdate() or CRUD related operations obviously. Its all in the documentation / code.


r/SQL • • 1d ago

PostgreSQL Text column is storing accented text weirdly

Thumbnail reddit.com
0 Upvotes

r/SQL • • 1d ago

PostgreSQL Self-hosted alternative to Neon's HTTP driver: query your own Postgres via fetch()

Thumbnail
reddit.com
0 Upvotes

r/SQL • • 1d ago

PostgreSQL If JOIN combines tables, why do we have so many different types of JOINs?

0 Upvotes

I understand how joins work in SQL, but I've always wondered why we need so many variations like INNER JOIN, LEFT JOIN, RIGHT JOIN, and FULL OUTER JOIN.

At the end of the day, we're just joining two tables based on a condition. Is the difference mainly about deciding which rows to retain when there isn't a match, or is there more to it than that?

Curious how others think about this, especially when working with real-world queries. Is there a particular join type you find yourself using most often, and why?


r/SQL • • 2d ago

SQL Server Negative reseed risks

8 Upvotes

One of the Sqlserver tables had an int identity column and maxed out the value. Team planned to reseed the identity from the lowest-ve value so that it can run on the same datatype for another 5 or 6 years. I am thinking that this would be a costly mistake if they plan to migrate this data into a new platform. The original solution was to change this to a bigint. Since this field has 300+ fks all those need to be dropped and recreated. What could possibly go wrong by choosing a -ve value reseed? I see the daily seed count is topping approximately 1 to 1.5million ids.


r/SQL • • 3d ago

PostgreSQL Foreign keys for array column elements

7 Upvotes

Postgres foreign keys can't check the elements of an array column, so a
product_ids bigint[] can hold ids that don't exist, and deleting the referenced
row leaves them dangling.

I wrote an extension that enforces it with triggers:

SELECT anyfk.add('orders(product_ids)', 'products(id)');

Feedback welcome.

https://github.com/Vinnu124/pg_anyFK


r/SQL • • 2d ago

PostgreSQL Have u run Databricks Lakebase for AI agent RAG…

0 Upvotes

If you have, how did Postgres vector + BM25 search hold up in prod As compare to a dedicated vector DB, specially on cold starts?


r/SQL • • 3d ago

PostgreSQL Where did I go wrong?

Thumbnail
gallery
25 Upvotes

For context, photos 1-2 show the original prompt + my answer. Photo 3 shows the solution. The output is somewhat similar to the correct answer, but not quite the same.

When I move the "status = 'Completed'" either to the "WHERE" section or to the JOIN section as "AND status = 'Completed'" it solves the problem, but not sure exactly why.


r/SQL • • 3d ago

MySQL Two production CAP traps I rarely see covered in interview guides (MySQL Group Replication reads & Cassandra QUORUM)

2 Upvotes

Most CAP explanations stop at labeling MySQL "CP" and Cassandra "AP", which falls apart once you look at default configs:

1. MySQL Group Replication is CP on writes, not reads by default. A 2-of-3 majority commit guarantees two nodes certified the transaction, but the third node can still lag slightly while applying its queue. Because group_replication_consistency defaults to EVENTUAL, a normal read on that lagging node still returns stale data unless you route critical reads to the primary or enable BEFORE_AND_AFTER.

2. Cassandra W=QUORUM + R=QUORUM is not strict linearizability. If a coordinator writes to R1 and crashes before reaching R2/R3, the client sees a write error — yet a subsequent quorum read hitting R1 triggers read-repair and resurrects the "failed" write. True linearizability requires Paxos Lightweight Transactions (SERIAL).

If anyone prefers a visual walkthrough of these failure modes alongside the 2018 GitHub 43-second partition and PACELC, I put together an animated deep dive here: https://youtu.be/17j1S5OOOAM


r/SQL • • 4d ago

PostgreSQL Databricks Agent memory pipelines can now run always-on (Beta)

6 Upvotes

Disclosure: I'm a Solutions Architect at Databricks.

Agent memories can lag behind conversations. If a user corrects your agent on which revenue source to use, that fix might not reach memory until the next ~24-hour scheduled run.

Memory pipelines distill facts, preferences, and corrections from session history into a memory store backced by Lakebase. They can now run always-on, so they process conversations as they happen.

  • Fresher memory: corrections can show up in later conversations the same day.

  • Hands-off: no runs or schedules to manage.

  • Incremental: each run processes only what's new since the last checkpoint.

A run starts for an actor when one of their sessions has 10+ new items, or has at least one new item and 30 minutes of inactivity.

Things to know:

  • Maintenance applies to all of an actor's memories, including ones the agent saved directly.

  • It's in Beta.

To turn it on:

agentbricks memory pipeline update <pipeline-id> --trigger always-on

Has anyone tried memory pipelines yet? Are you using Lakebase today? Are you running them on a schedule or always-on? To try it today, install databricks-agentbricks 0.7.0+. The identity creating the pipeline needs access to both stores and the distillation model.


r/SQL • • 5d ago

PostgreSQL So for my SQL schema should I make it so my post table has an array filled with tags (3 at most) and I search for those tags using ARRAY_CONTAINS or should i just make a table for tags and link the posts as a foreign key?

5 Upvotes

Which one is more efficient?


r/SQL • • 5d ago

SQLite Belay - formal verification for SQLite statements

Thumbnail
vihren.dev
7 Upvotes

r/SQL • • 4d ago

SQL Server Friday Feedback - increasing the number of steps in the histogram

Thumbnail reddit.com
1 Upvotes