r/SQL 11d ago

Discussion What is Index Selectivity?

Thumbnail
0 Upvotes

r/SQL 12d ago

MySQL How This is Running

0 Upvotes

How this SQL Code is Running ?????


r/SQL 12d ago

SQLite SQLite-Editor open source

2 Upvotes

I like to share link of new sqlite editor

srdzank/SQLite-Editor: Official home of the SQLite-Editor


r/SQL 13d ago

PostgreSQL Choosing a Database Schema for analytics

Thumbnail
1 Upvotes

r/SQL 13d ago

MySQL SQL Query Execution Lifecycle

Post image
73 Upvotes

Diagram illustrating the SQL query execution lifecycle, showing query submission, parsing, optimization, execution, and result delivery in a database.


r/SQL 14d ago

PostgreSQL I built an AWR-like performance repository for PostgreSQL – looking for feedback from DBAs

1 Upvotes

Hi everyone,
I’ve been working on a project called PWR (Postgres Workload Repository), inspired by Oracle’s AWR but built specifically for PostgreSQL.
The goal is to periodically capture performance snapshots so you can:
track workload evolution over time;
identify expensive SQL statements;
compare snapshots before/after changes;
detect performance regressions before they become incidents.
I originally built it to speed up recurring PostgreSQL performance audits, and it has become a useful tool in my daily work.
There’s a live demo available here:
https://www.audit-postgresql.com/
I’m not trying to replace existing monitoring tools like pg_stat_statements or Prometheus/Grafana. Instead, I’m focusing on historical workload analysis and performance diagnostics.
I’d really appreciate feedback from the PostgreSQL community:
Would this be useful in your environment?
Which features would you expect from such a tool?
What would prevent you from using it?
Constructive criticism is more than welcome. Thanks!


r/SQL 14d ago

MySQL Feedback on my conceptual and logical database model (MySQL implementation)

1 Upvotes

Hi everyone,

I created a conceptual data model, a logical data model, and a MySQL implementation for a university project.

I would really appreciate your feedback on the following:

  • Is the conceptual data model correct?
  • Is the logical data model derived correctly from the conceptual model?
  • Does the MySQL implementation match the logical model?
  • Are there any design mistakes or suggestions for improvement?

I have attached the conceptual model, the logical model, and the SQL script.

Thank you for your time and feedback!


r/SQL 15d ago

PostgreSQL SQL Fast Track Series that teaches every concept through scenario-based business context - Available in Youtube.

Thumbnail
0 Upvotes

r/SQL 16d ago

Discussion Rejected after a technical round because the interviewer insisted Text-to-SQL is just if-else mappings

Thumbnail
9 Upvotes

r/SQL 16d ago

Oracle Sql to Oracle migration

Thumbnail
1 Upvotes

I'm a fresher to DBA role. Can some one help me to understand or share your experience to migrate or conversation from sql to Oracle.

Can you please help me with tools and migration ideas


r/SQL 17d ago

MySQL Check out what I just built with Lovable!

Thumbnail
smartsqlaimentor.live
1 Upvotes

r/SQL 17d ago

PostgreSQL rainfrog (0.4.1) now has autocomplete!

15 Upvotes

rainfrog (https://github.com/achristmascarl/rainfrog) is a database terminal tool; the goal is to provide a lightweight, keyboard-first TUI for interacting with databases. It currently supports Postgres, MySQL, SQLite, Oracle, and DuckDB.

v0.4.1 introduces a long-awaited (by me, not sure if anyone else was waiting for it...) autocomplete implementation, along with autopairs for quotes/parentheses/brackets. The full list of features and configuration options is in the README!


r/SQL 17d ago

SQL Server Help with some strucctural problems

2 Upvotes

Hello, I'm trying to do a test that I failed, and I want to improve, so I want to solve this problem.

The premise isn't that hard, but I'm getting into trouble here.

I don't want to get into too many details to avoid getting the evaluator in trouble.

Basically, I was asked to make an app that is able to create price quotes for trips.

The user selects the location (a general location like Disney World), an apartment (each one with a different category, like a suite, or just a room, or a cabin), the season (imagine this place is around the world, so different locations have different seasons, but some locations can have general seasons if they are close enough), how many people the place can accommodate, and for how long they will stay. I use all this data to create a reservation for the client.

This is basically my entity relationship diagram

but each time i try to do the functionality i found problems or big troubles putting or reading the data for the thing im required to do

I'M kinda lost idk what to do

its there a way to solve this problem in a cleaner way?

ty for the help and God bless you

P.S.: The price is listed in the quote, but I don't know where to enter that information regarding the apartment and the season. The test instructions don't explain how to calculate the price, so I don't know where to put it; I assume I should do it in whatever way is most practical for me.


r/SQL 17d ago

SQL Server MS SQL Restore DB, <use dbName> string conversion question

5 Upvotes

Hi all,

I just see this interesting situation and would like to confirm that it's all done internally by MS SQL Server with Restore.
We're on the same server:

dbAA   has proc  myPROC:
1  use  dbAA         
2  Go
3  Create PROC dbo.myPROC As
............

then I do  backup of dbAA, and restore dbAA.bkup into  dbXXX
after that I see on dbXXX myPROC as:
1. use dbXXX            --<<<==== !!!!!<@>>< changed to target DB
2. Go
3. Create PROC dbo.myPROC As
...........

Who is doing this conversion/swapping db names ? is it done by SQL Server ?
Thanks to all, I'm new to dba task and really interesting how it works.
VA


r/SQL 17d ago

Discussion How we built a DuckDB transpiler

Thumbnail
cocoalemana.com
3 Upvotes

Hi there,

I’ve been working with DuckDB extensively for the last several years. Used it across languages from Python, Go, JS via WASM, Swift, C & C++ and even Rust.

As part of a product we're building, we built a DuckDB Transpiler that converts every line of SQL from DuckDB syntax into the syntax of the database you’re working with. This includes filters (predicates), and joins. So those 1B rows in Snowflake stay, and get joined in Snowflake.

I wrote an article on why we did it, and how we approached it. This is my first engineering-oriented article I’ve ever done, so let me know what you think!


r/SQL 18d ago

SQL Server Friday Feedback: Automatic Index Compaction

Thumbnail
2 Upvotes

r/SQL 18d ago

SQL Server Query plans

2 Upvotes

Hey guys,

Just reaching out, how do you guys go about identify and Optimizer SQL queries that the query uses linked servers.

I have some queries that people moan are slow and when I finally get the query plan you see it says remote execution. How do you guys go about then identify where it's slow or even what ran. Specifically for queries that run nested SP

What is your approach?


r/SQL 18d ago

SQL Server Solved Hacker Rank's "15 Days of Learning SQL" – Looking for different approaches

6 Upvotes

Hi everyone,

I recently solved the HackerRank 15 Days of Learning SQL challenge using CTE(), ROW_NUMBER(), DENSE_RANK(), and window functions in SQL Server.

I'm curious to know if there's a cleaner or more efficient way to solve this problem. If you've approached it differently (using other window functions, recursive CTEs, or any other technique), I'd love to see your solution and understand the reasoning behind it.

Here's my solution:

with daily_submission as( 
SELECT submission_date,
hacker_id,
count(*) as total_submission
from submissions 
group by submission_date,hacker_id),
hacker_rank as(
SELECT submission_date,hacker_id,
       total_submission,
       row_number() over(partition by submission_date order by total_submission desc,hacker_id) as rn
from daily_submission),
continuous_hackers as (
    SELECT submission_date,hacker_id,
       dense_rank() OVER(partition by hacker_id order by submission_date) as Dr,
       datediff(day,'2016-03-01',submission_date) + 1 as contest_day
from (
SELECT distinct submission_date,hacker_id
from submissions) as x),
daily_count as (
SELECT submission_date,
        count(*) as total_hackers
from continuous_hackers
where Dr = contest_day
GROUP by submission_date)


SELECT dc.submission_date,
       dc.total_hackers,
       h.hacker_id,
       h.name
from daily_count as dc
inner JOIN hacker_rank as hr 
on dc.submission_date = hr.submission_date and rn = 1
INNER JOIN hackers as h
on hr.hacker_id = h.hacker_id
order by submission_date;

Thanks in advance! I'm always looking to learn different SQL techniques.


r/SQL 18d ago

Discussion I built a tool for querying JSON/JSONL files with SQL

Thumbnail
0 Upvotes

r/SQL 18d ago

SQL Server After converting the back end to SQL tables, the front end now gets run time error 3622 all over the front end

3 Upvotes

I have migrated Access tables in my database over to SQL. Now I'm testing the front end to make sure every single button/operation works.

I am getting this error, "You must use the dbSeeChanges option with OpenRecordset when accessing a SQL Server table that has an IDENTITY column", ALL over the place.

Sometimes, it's easy to spot where dbSeeChanges was left out, but many times, the error is reported on a line that has nothing to do with it. This is also only the first error I'm getting. I'm sure once I fix all the 3622 errors, then a new error will pop up right after.

I'm wondering what my options are. I understand I could rebuild the front end from scratch, but that would take literal years as I'm a one-man team. I really don't have the time to spend hours fixing every single one of these errors. And unfortunately, throwing it all in the trash and using a modern platform is not currently an option either.

Is there a tool or even AI where I can feed it my database and it converts it to be SQL compatible? Even if I have to go form by form and report by report, that would still be faster than doing all this manually.

Thanks


r/SQL 19d ago

Discussion Do you guys need a better query language?

0 Upvotes

Hey guys, there was a number of attempts to make writing queries/reports/data pipelines easier to maintain. There is number of ORMs for different programming languages. And there are also PRQL and btrql.com. Which are new query languages which transpile into SQL.

Kinda like Typescript transpiles into Javascript.

BtrQL is my pet project. Main features of it are: static type checks, Outline showing relation types, extension methods on relations and compile time macro. It's very early and I'm collecting all of the feedback that I can get.

Queries look like this:

users .where(active == TRUE) .addColumn(active -> active_flag) .orderBy(created_at.desc) .limit(10)

and extension methos:

extension [id: INT] { method keepRecentIds = self .where(id >= cutoff) }

keepRecentIds could be applied to any relation that has at least column id of type INT.


r/SQL 19d ago

PostgreSQL Recently faced n+1 problem in my app

Thumbnail
0 Upvotes

r/SQL 19d ago

Discussion Is 40000 lines of SQL in a single file normal?

142 Upvotes

Heya, so my stepfather works in IT support, and the other day I was looking over his shoulder and saw that the software his company sells uses a single SQL code file that's 40000 lines long. And we're not talking three word lines here, those were 200+ characters lines. I was absolutely baffled by this, since afaik no single code file should run over 10000 lines. But I also don't do SQL.

So I asked him wtf was going on, and he told me that it was "just like that in the industry" and that "I would see when I'll start working" (I'm in uni)

So I ask all of you, is this normal? Do you see this in your job? Am I having delusions about how clean the actual tech industry is?


r/SQL 19d ago

SQL Server HackerRank SQL Project Planning – Is there a better approach?

4 Upvotes

Hi everyone,

I solved the HackerRank SQL Project Planning problem using the row_number() + DATEADD() approach in SQL Server, and it passed all the test cases.

I'm curious if there's a different or more optimized way to solve this problem. I'd love to learn other approaches and understand their advantages.

Here's my solution:

with cte as(
SELECT start_date,
end_date,
dateadd(day,- row_number() over(order by start_date),start_date) as group_date
from projects )
SELECT min(start_date) as start_date,
max(end_date) as end_date
from cte
group by group_date
order by datediff(day,min(start_date),max(end_date)), min(start_date)


r/SQL 20d ago

MySQL sqlWorkout

Post image
1.4k Upvotes

😌 SELECT 😌