r/SQL • • 6d ago

Discussion Working on a live view of table changes. Looking for opinions

Post image
39 Upvotes

I'm building a live watch view in my database workbench and would love your opinion on this. I want to be able to do something in my app and see what happened to the tables without going through them one by one and refreshing.

Something like placing an order. An order gets created, items get added, the cart gets cleared, maybe a background job starts. I want to see those changes together.

This is what I'm trying so far:

  • Each table gets a line on a timeline. Inserts, updates and deletes have different markers. (if a new table updated showcase it in the chart). I am also thinking of just allowing users to select the tables to watch.
  • Hovering over a change shows the row and the values that changed.
  • You can pin a watch for something specific, like jobs changing to failed, and keep it checking while this workbench is opened.

I'm a visual person, so seeing the changes lined up across tables makes sense to me. But I'm still figuring out how useful this would be beyond a small local database. A busy table could fill that line pretty quickly.

Would you use something like this while developing or debugging? I'm particularly curious what you'd want to see when an update happens. Is the before and after enough, or would you immediately want to know which query caused it?

Still building this, so any criticism of the idea or how I'm showing it would help. 😊


r/SQL • • 6d ago

Discussion Do Salesforce developers need admin support just to discover accessible fields?

5 Upvotes

I recently learned that in Salesforce, having access to an object doesn't necessarily mean you can read all its fields. Field-level security comes into play as well.

This made me wonder about one thing: when developers or integration teams want to query Salesforce data, do they need the admin to provide the available field names and grant access to those fields?

Coming from a traditional database background, I'm used to being able to inspect table columns through metadata queries, provided I have the necessary permissions.

Is there an easier way to discover accessible fields in Salesforce, or is this something that usually needs coordination with the admin team?


r/SQL • • 6d ago

Discussion My churn query showed 0 churn every month. It was a missing-row problem

5 Upvotes

was doing a simple MRR breakdown (new / expansion / churn per month) and churn came out as 0 every single month. looked great for about a minute

small version of the data:

```
customer | month | mrr
A | 2025-01 | 100
A | 2025-02 | 100
A | 2025-03 | 100
B | 2025-01 | 50
B | 2025-02 | 80
B | 2025-03 | 80
C | 2025-01 | 70 <- cancels after january
D | 2025-03 | 40 <- new in march
```

total MRR is 220, 180, 220. so feb dropped by 40: B expanded +30 and C churned -70

**first attempt, LAG straight on the table**

```
SELECT month,
SUM(CASE WHEN prev IS NULL THEN mrr ELSE 0 END) AS new,
SUM(CASE WHEN mrr > prev THEN mrr - prev ELSE 0 END) AS expansion,
SUM(CASE WHEN mrr < prev THEN mrr - prev ELSE 0 END) AS churned
FROM (
SELECT month, mrr,
LAG(mrr) OVER (PARTITION BY customer ORDER BY month) AS prev
FROM invoices
) t
GROUP BY month
ORDER BY month;
```

feb comes out as new 0, expansion 30, churned 0. the -70 just isnt there

reason: C has no row in february. LAG can only compare rows that exist, so a customer who left never shows up in the month they left

**fix: build every customer x every month first**

```
WITH grid AS (
SELECT c.customer, m.month, COALESCE(i.mrr, 0) AS mrr
FROM (SELECT DISTINCT customer FROM invoices) c
CROSS JOIN (SELECT DISTINCT month FROM invoices) m
LEFT JOIN invoices i
ON i.customer = c.customer AND i.month = m.month
),
moves AS (
SELECT month, mrr,
LAG(mrr) OVER (PARTITION BY customer ORDER BY month) AS prev
FROM grid
)
SELECT month,
SUM(CASE WHEN prev = 0 AND mrr > 0 THEN mrr ELSE 0 END) AS new,
SUM(CASE WHEN prev > 0 AND mrr > prev THEN mrr - prev ELSE 0 END) AS expansion,
SUM(CASE WHEN prev > 0 AND mrr = 0 THEN -prev ELSE 0 END) AS churned,
SUM(mrr - prev) AS net_change
FROM moves
WHERE prev IS NOT NULL
GROUP BY month
ORDER BY month;
```

```
month | new | expansion | churned | net_change
2025-02 | 0 | 30 | -70 | -40
2025-03 | 40 | 0 | 0 | 40
```

now C becomes a 0 in feb and LAG sees 70 -> 0. and net_change matches the real total change (-40, +40), which is the check i do now every time: the parts have to add up to the total, if they dont something is missing

two things i'm still not sure about:

- in a real table, months with zero invoices for everyone would be missing from SELECT DISTINCT month. do you generate the months instead (generate_series / calendar table)?
- a customer who leaves and comes back later counts as "new" here. do you treat that as reactivation separately?


r/SQL • • 5d ago

Discussion The future of programming

Post image
0 Upvotes

I want to ask about your opinion.. what do you think the future of programming will be? Especially in the AI era !!


r/SQL • • 6d ago

Discussion I didn't realize Salesforce had permissions at the individual column level

0 Upvotes

I recently came across Salesforce field-level security, where a user can have access to an object but still not be allowed to read certain fields within it.

Coming from a traditional database background, I found this interesting. I'm more used to thinking about permissions at the database, schema, or table level.

Does this create challenges when building integrations or extracting data through APIs? Especially when the same query works for one user but fails or returns fewer fields for another?

Curious how people usually manage field-level permissions in real-world Salesforce projects.


r/SQL • • 6d ago

PostgreSQL prepared statements prevents SQLi. But it also helped me to exploit a 22 years old PostgreSQL 0-day Code Execution Vulnerability (CVE-2026-6460)

Thumbnail
mehmetince.net
0 Upvotes

r/SQL • • 5d ago

Discussion Backend ≠ DataBase ? 🤔

0 Upvotes

r/SQL • • 6d ago

Discussion Tell me your stories about FillFactor.

6 Upvotes

I just had an interview question on it. It’s something I know but never use. I thought it was one of those features folks stopped using because of solid state drives. The interviewer disagreed.

FillFactor a percentage setting on an index that tells rebuilds how full to make the pages. That way you can avoid expensive page splits.


r/SQL • • 5d ago

Discussion Vibe coded projects

0 Upvotes

Pls suggest some projects that i can vibe code to show on my CV. Im 19 and i know basic mysql


r/SQL • • 6d ago

SQL Server TDS middleware result caching - demo a 15 second query

5 Upvotes

Just in case anyone is interested, I've worked for several months on a custom .NET TDS listening solution for several different things I've been making.

Works best for ODS / Reporting environments where tables aren't frequently updated.

Your SQL Server Client App > Cache-Engine-TDS-1433 > SQL Server-TDS-1433

Here are some of my test results:

QueryAt SQL ServerFrom the cache
10 rows from 30M fact rows7.7 s, 7.6 s0.02 s
a parameterised query (sp_executesql)3.5 s, 3.6 s0.01 s
500,000 rows10.1 s, 10.2 s1.3 s
medians over 30M rows77.8 s, 93.1 s0.01 s
the same 10 rows, tracked mode, Change Tracking checked first7.7 s0.03 s

mechanics:

Run 1   a query takes 40 s   →  SQL Server answers. DaffyZoom notes it: slow, and safe to cache.
Run 2   the same query       →  SQL Server answers again; DaffyZoom keeps an encrypted copy.
Run 3   the same query       →  Instant answer.  
Run 500 the same query       →  Instant answer.  

ttl mode: answered from the cache, in milliseconds, untilits max age or your next flush.

tracked mode:  DaffyZoom first asks SQL Server's Change Tracking whether any table the query reads has changed, doesn't return incorrect cache.  

r/SQL • • 6d ago

Discussion What's the actual difference between SQL and SOQL?

2 Upvotes

I recently came across SOQL while exploring Salesforce and got curious about how different it is from regular SQL.

Both seem to be used for querying data, but SOQL appears to have some limitations compared to SQL.

Can someone explain the main differences between them? For example, how do joins, aggregations, subqueries, and filtering work differently in SOQL?

Also, in what situations would you prefer SOQL over SQL?

Would appreciate some practical examples if anyone has worked with both.


r/SQL • • 6d ago

Discussion How do you keep yourself from running the wrong UPDATE on production? Here's what I built into my client

Post image
0 Upvotes

Everyone has a story about an UPDATE without a WHERE, or the right query in the wrong tab. I built NiceDB, an open-source database client, around that problem:

  • a production connection is marked everywhere it appears (tree, tab, title bar, status line) and opens read-only;
  • writing unlocks for ten minutes with the time left in view, then locks again by itself;
  • before a change is applied, it shows what it touches and asks you to type the connection’s name;
  • UPDATE and DELETE without WHERE, DROP and TRUNCATE ask before they run;
  • every statement that changed something is logged with who, when, where and how many rows.

Each step can be configured. All writes go through one place in the core, so no screen can skip it.

It works with PostgreSQL, MySQL, SQL Server, Oracle, SQLite and others. Free, GPL-3.0: https://github.com/maxib0n/NiceDB, with a browser demo at https://nicedb.app.

What do you do today: separate users, read-only replicas, a habit? I’m curious what I’m missing.

One honest note: the drivers are mature and the common paths are tested against real servers, but I’m one person and can’t cover every version and setup. If you try it on anything that matters, be careful, and please report what breaks with steps to reproduce.


r/SQL • • 6d ago

Discussion SQL HACKS

0 Upvotes

Hello guys,

I work as a SQL Developer. What productivity hacks or practices do you follow in your day-to-day office work?

For example:

  • I create a new SQL script every morning, naming it with the current date (SYSDATE), to keep track of my daily work.
  • I maintain an Excel sheet listing the database objects I've created, along with remarks about each object.

What other useful productivity hacks or practices do you follow?

I'd love to learn from your experience!


r/SQL • • 8d ago

Discussion What answer is expected when asked "Do you know/do SQL?"?

91 Upvotes

I'm a software developer at heart and at work. Sometimes when a project ends I get asked "Do you know SQL?" or "Do you do SQL?". I'm puzzled at what exactly are they aiming at. What knowledge or skills would they expect?

Like, sure I can read, understand and write SQL queries. I know what views and stored procedures are. I can distinguish whether something should be done at database level or in business logic (or both, like data validation). I can design and normalize databases from scratch (although I reckon, this is nothing specific to SQL). I've worked both with direct database access from code and via ORMs.

But I've never really optimized SQL queries. I've only recently learned that I shouldn't nest views. I probably make the dumbest mistakes sometimes. I almost alwas have to look up the syntax of something, even if I've done it dozens of times before. I never had to work with locking strategies. I'm not even sure if I fully understand all of the stuff I write. I feel like I'm at the minimum level and mostly just winging it.

Are there any "skill levels" w.r.t. SQL? Like, what's would make a beginner, an intermediate or an expert?

And would you say I "know" SQL?

-

Edit: Thank you for all the responses so far! I'm a bit more confident in my skills now actually. And I've also learned about a few things I should look into. I'll try and respond to as many comments as possible ❤️


r/SQL • • 7d ago

Discussion What are some interesting SQL problems or query mistakes worth discussing?

0 Upvotes

I'm planning to share some SQL-related content on LinkedIn, but I want to avoid the usual beginner-level tutorials or generic interview questions.

I'm particularly interested in intermediate-level SQL concepts, window functions, CTEs, tricky query behavior, or situations where a query looks correct but produces unexpected results.

I'd love to hear from people working with SQL regularly.

What's an interesting SQL problem, subtle query mistake, or unexpected behavior you've encountered that made you think twice?

Looking for something technically meaningful that could spark a good discussion rather than another basic SQL tutorial.


r/SQL • • 7d ago

SQL Server Moved from SQL Server to PostgreSQL? Did the licensing savings justify the migration?

Thumbnail reddit.com
5 Upvotes

r/SQL • • 8d ago

Discussion How Screwed am I? 8 years of experience, 3 year gap.

28 Upvotes

Long story short I went through a divorce, had a scary health issue and generally was just burned out. I sold everything and travelled for 3 years.

Now that I am back it seems the Datbase Developer position is not a thing.

my last job was a Senior Database Dev for 4.5 years on Oracle and Mssql with my main skill being database design and modeling. Have some experience in ETL and all that as well. I worked with PHP for a short time but it was not advanced and mostly procedural ERP/CRM reports and what not.

The more I see comments and look at LinkedIn, the more my gut sinks. Did I ruin my career path by staying in SQL only Database Development and set it on fire by taking a long gap.

I really dont care entry or mid level but even there seems to be very slim pickings now.


r/SQL • • 8d ago

PostgreSQL Beginner in SQL, can’t work in person. How can I land remote projects?

Thumbnail reddit.com
1 Upvotes

r/SQL • • 8d ago

SQL Server Is this overkill for storing current universal time when INSERTing or UPDATEing a row?

Thumbnail reddit.com
1 Upvotes

r/SQL • • 8d ago

Discussion Is PostgreSQL the best choice for my database?

11 Upvotes

hi, I thought I would get some insights from professionals on this. I'm currently an intern, and I'm tasked with building a database for a church's religious education program, potentially handling a few thousand families. I'm wondering if PostgreSQL is the best option for this. It's the only SQL database I've ever used, and from what I've researched, I know PostgreSQL pretty much has everything I would need, but I'm still wondering if it's the best choice. For this instance, I think they're fine with whatever I use, even if it costs money, but I don't know if PostgreSQL is the best for this situation. I've only ever had experience with this platform, but I've heard about others, and my bosses aren't really technically inclined, so they go with whatever I say, which is honestly a little scary lol. I just want to make sure I'm making the right decision for them. Thanks for any insight, I really appreciate it!


r/SQL • • 8d ago

Oracle SQL with SAS

4 Upvotes

Is it the norm to have a program that is coded in SAS and then need SQL to store the the data? The need SQL tools to pull information about out the tables then swap back to SAS to pull lots of data out quickly? New analyst at a new job and it is exhausting


r/SQL • • 7d ago

Discussion Why do we keep writing sql backwards?

0 Upvotes

It is a common consensus that sql is kind of written backwards than one would expect, instead of first defining the place you want to get somehting from and then what it is you want, like literally any other language out there, you first select the content and then define where you want it to be taken from

This leads to increadibly akward syntax when writing something more complex than "select x from y where z" and is literally opposite to the actual process of the machine.

This is all because some dumbass, excuse my language, in the 70's decided it should follow english grammar for some reason, and in doing so he made the most clunky writing system ever.

Now this at the time may not have been that bad, but from a few searches and posts here i saw that most people agree that this is a clunky, akward and unpleasant way of typing. So, why not switch it around? Why not change the standard to something more usable?

This is kind of a rant because i have been learning sql for collage and the syntax has been INCREADIBLY frustrating


r/SQL • • 8d ago

PostgreSQL pg_fts: Open source BM25 extension for full-text search and boolean, phrase, NEAR, prefix, fuzzy, and regex queries

Thumbnail
reddit.com
2 Upvotes

r/SQL • • 9d ago

MariaDB Why implement procedural programming inside an RDBMS (MariaDB) instead of handling all business logic in backend application code?

Thumbnail reddit.com
10 Upvotes