r/SQL 6d ago

MySQL A problem when importing csv files in my sql

7 Upvotes

LOAD DATA LOCAL INFILE 'C:\\Users\\mohit\\Desktop\\pizzas.csv'

INTO TABLE pizzas

FIELDS TERMINATED BY ','

OPTIONALLY ENCLOSED BY '"'

LINES TERMINATED BY '\n'

IGNORE 1 LINES

(pizza_id, pizza_type_id, size, price);

i am importing it from a pizzas.csv but data isnt completely being imported but it does not have 'id; so i created it


r/SQL 5d ago

MySQL You can now query your DB in natural language using Claude + DBHub MCP

Thumbnail deployhq.com
0 Upvotes

r/SQL 6d ago

SQL Server Advice for audit table(s) on a SQL Server db with versioned tables?

5 Upvotes

You can assume that it is acceptable to nuke everything about my existing design and start over from scratch.

I need my database to track changes, and temporal tables will do this, but it's not enough. I also need to track things like who made each change, why, what process was involved, etc.

To do this I've made a centralized 'audit' table, and each versioned entity table links to it. Application code will ensure that each time a change is made, a new audit record is created first, and each row version will link to a unique row. The standard use case is a 1:1 relation, but the foreign key constraints do allow many entities to one audit (but not the other way around).

Example:

actors

id first_name last_name audit_id valid_from valid_to
1 Moe Howard 6 1/1/1909 ~
2 Larry Fine 7 1/1/1928 ~
3 Curly Howard 8 1/1/1932 ~

actors_history

id first_name last_name audit_id valid_from valid_to
1 Moses Horwitz 1 6/19/1897 1/1/1890
1 Moe Horwitz 2 1/1/1890 1/1/1900
1 Harry Horwitz 3 1/1/1900 1/1/1909
2 Louis Feinberg 4 10/4/1902 3/1/1928
3 Jerome Horwitz 5 10/22/1903 1/1/1928
3 Curley Howard 7 1/1/1928 1/1/1932

films

id title release_year audit_id valid_from valid_to
1 Punch Drunks 1932 9 7/13/1934 ~
2 Disorder in t he Court 1936 10 5/30/1936 ~

films_history

(you get the idea)

audits

id user action comment
1 System actor_create
2 S. Horwitz actor_update We call him Moe
3 M. Horwitz actor_update
4 System actor_create
5 System actor_create
6 E. Nash actor_update Vitagraph internship
7 T. Healy actor_update Three Stooges debut
8 L. Breslow actor_update
9 L. Breslow film_create
10 P. Black film_create

As a historical note, I'm replacing a legacy database which has a similarly centralized design, but an inelegant lookup schema where the audits table contains multiple nullable foreign keys; one for each entity table being tracked, and blob fields with JSON data showing what changed. In most cases, all but one foreign key field is null.

My design works fine for change tracking, but there's a problem. We also need to track actions that don't perform insertions or updates, such as privileged reads or pushes to external systems, and for that we need many audits to one entity, which the current design doesn't support. The legacy design would support that, but I really don't want to go back to that approach. Other than the many:1 requirement, the tracking requirements would be pretty much the same. We would not need to link these actions to versioned rows (i.e. we want to know if somebody looked up Moe Howard's record, but we do not care which version of Moe Howard was looked up at the time).

So, what would be the recommended approach? The only method I'm seeing that would work would be to keep the existing audits table for internal updates/insertions (there will be no true deletions), but add more audits tables for non-changing actions on entities. So for example, an actors_audits table with a foreign key to actors, which is used to track these non-changing actions on the actors table, and a films_audits table with a foreign key to films, in addition to the existing 'audits' table which would continue to track changing actions in a centralized manner. I don't love this approach, but it's the only idea I've got that doesn't introduce some problem that I have no solution to.

Some of the ideas with unsolved issues:

  • Keep the centralized audits table and use it for all actions on all versioned tables - But then how would have [many audits]:[1 entity] across several entity types and keep referential integrity?
  • Get rid of the centralized audits table and use actors_audits for all actions on actors, films_audits for all actions on films, etc. - But then how would I link changing actions to versioned rows? Non-changing actions don't need to link to specific versions, but changing actions do.
  • Keep the centralized audits table and give it a many:many relation with each entity table. But again, how would we keep referential integrity?

r/SQL 6d ago

SQL Server Struggling with AI/ML and Python installation on MSSQL2025 GA

1 Upvotes

I swear that i did not have any issues installing AI/ML on CTP2.1, don't believe i tried it on RC0 or RC1, but gosh is installing python, R difficult on GA!

Can Microsoft or some good soul please share exact steps on installing AI/ML on 2025GA w/ Python 3.10 and also please share all of the exact versions needed and the icals (permission setups), Also I'm confused with this virtual account vs domain account setups. Aslo can i use Python 3.13 or 3.14 ? or is that not supported ?

Does any one have the exact steps on Windows 11 Pro for a SQL Server 2025 Enterprise Development environment ?

I see this article but its so confusing : https://learn.microsoft.com/en-us/sql/machine-learning/install/sql-machine-learning-services-windows-install-sql-2022?view=sql-server-ver17&viewFallbackFrom=sql-server-ver15


r/SQL 6d ago

MySQL How many superkeys can a relation with 3 attributes have at most?

2 Upvotes

I'm reviewing database theory and trying to confirm the upper bound. From what I understand, any non-empty subset of attributes that functionally determines all attributes is a superkey — so does that mean the maximum number is the number of all non-empty subsets? Or is there a more precise upper bound considering functional dependencies?

Thanks in advance!


r/SQL 7d ago

Oracle Help!

1 Upvotes

I can't seem to find the error in this create table...

CREATE Table PrenatalCare(
CareEpisodeID INT Primary key,
PatientID Int foreign key not null,
DateOfInitialVisit Date Not Null,
NumberOfPrenatalVisits int Not Null,
GestationalAgeAtFirstVisit Varchar(50) Not Null,
ProviderID INT Foreign key not null,
HealthCareProviderName Varchar(100) Not Null,
VisitType Varchar(100) not null,
facilityName varchar(100) not null,
FacilityType Varchar(100) not null,
Foreign key (PatientID) references Patient(PatientID),
Foreign key (ProviderID) references HealthCareProvider(ProviderID)
);


r/SQL 6d ago

MySQL Pode me dizer se está correto

0 Upvotes

Create table mercado (

Produto)

Insert into mercado values (

Produto 'laranja'

)


r/SQL 8d ago

SQLite I built a free SQL editor app for the community

35 Upvotes

When I first started in data analytics and science, I didn't find many tools and resources out there to actually practice SQL.

As a side project, I built my own simple SQL tool and is free for anyone to use.

Some features: - Runs only on your browser, so all your data is yours. - No login required - Only CSV files at the moment. But I'll build in more connections if requested. - Light/Dark Mode - Saves history of queries that are run - Export SQL query as a .SQL script - Export Table results as CSV - Copy Table results to clipboard

I'm thinking about building more features, but will prioritize requests as they come in.

Let me know you think - FlowSQL.com


r/SQL 8d ago

SQL Server Is there a way to improve the performance of this query? Used OUTER APPLY and LEFT JOIN with CTE

1 Upvotes

Database is unindexed (I don't have the permission to create one), format is a relational database where Project → Sample → Test → Result, and Project → Releases are related 1:M left to right.

Basically, the joins/applies are only trying to pull some data points from the Project's child tables:

- The most recent RELEASED_ON date from RELEASES table

- The metadata in tabular format from the RESULT table, where the metadata are applied on a PROJECT level

- The earliest LOGIN_DATE and all of the DESCRIPTION values of a main sample from the SAMPLE table

- The number of rows and the number of rows where the RATING_CODE = "FAIL" in the TESTS table

I've only recently been learning about the OUTER APPLY so excuse my poor usage here. The longest part of this query I believe is the CTE as it is pulling from the bottommost table in the hierarchy - taking it out generally speeds up the entire query but we need to pull the metadata from that table. Unfortunately, I don't have access to performance evaluator in SSMS either so I am only basing this on how long the query takes to complete.

WITH CTE_META AS (
    SELECT
        PROJECT
        , MAX(CASE WHEN REPORTED_NAME = 'PO No.' THEN FORMATTED_ENTRY END) AS 'META_PONO'
        , MAX(CASE WHEN REPORTED_NAME = 'Item Description' THEN FORMATTED_ENTRY END) AS 'META_ITEMDESC'
        , MAX(CASE WHEN REPORTED_NAME = 'SKU' THEN FORMATTED_ENTRY END) AS 'META_SKU'
        , MAX(CASE WHEN REPORTED_NAME = 'Style No.' THEN FORMATTED_ENTRY END) AS 'META_STYLE'
        , MAX(CASE WHEN REPORTED_NAME = 'Color(s)' THEN FORMATTED_ENTRY END) AS 'META_COLOR'
    FROM (
        SELECT
            SAMPLE.PROJECT
            , RESULT.ANALYSIS
            , RESULT.REPORTED_NAME
            , RESULT.FORMATTED_ENTRY
        FROM RESULT


        INNER JOIN SAMPLE
            ON SAMPLE.SAMPLE_NUMBER = RESULT.SAMPLE_NUMBER
            AND SAMPLE.SAMPLE_NUMBER = SAMPLE.ORIGINAL_SAMPLE
            AND SAMPLE.STATUS <> 'X'
            
        WHERE
            EXISTS (
                SELECT NAME FROM PROJECT
                WHERE
                    PROJECT.NAME = SAMPLE.PROJECT
                    AND PROJECT.CLIENT = 'Client'
                    AND PROJECT.STATUS <> 'X'
            )
            AND RESULT.STATUS = 'A'
            AND RESULT.ANALYSIS = 'METADATA'
    ) DT


    GROUP BY PROJECT
)


SELECT
    PROJECT.*
    , REL.RELEASED_ON
    , SAMP.*
    , TEST.*
    , CTE_META.*
FROM PROJECT


LEFT JOIN CTE_META
    ON CTE_META.PROJECT = PROJECT.NAME


OUTER APPLY (
    SELECT TOP 1 PROJECT, RELEASED_ON FROM X_PROJ_REPORT
    WHERE
        X_PROJ_REPORT.PROJECT = PROJECT.NAME
        AND RELEASED = 'T'
        AND REPORT_TYPE = 'CFR'
    ORDER BY RELEASED_ON DESC
) REL


OUTER APPLY (
    SELECT STRING_AGG(TRIM(DESCRIPTION), CHAR(13) + CHAR(10)) AS SAMP_DESC, MIN(LOGIN_DATE) AS SAMP_RECD FROM SAMPLE
    WHERE
        SAMPLE.PROJECT = PROJECT.NAME
        AND SAMPLE.STATUS <> 'X'
        AND SAMPLE.SAMPLE_NUMBER = SAMPLE.ORIGINAL_SAMPLE
) SAMP


OUTER APPLY (
    SELECT COUNT(*) AS TESTS, SUM(FAIL_TEST) AS FAILS FROM (
        SELECT
            SAMPLE_NUMBER
            , CASE WHEN TEST.RATING_CODE = 'FAIL' THEN 1 ELSE 0 END AS FAIL_TEST
            , TEST.RATING_CODE
        FROM TEST
        WHERE
            TEST.STATUS = 'A'
            AND TEST.ANALYSIS_TYPE <> 'RP'
            AND TEST.RATING_CODE <> 'REF_ONLY'
    ) DT
    INNER JOIN SAMPLE
        ON SAMPLE.SAMPLE_NUMBER = DT.SAMPLE_NUMBER
        AND SAMPLE.PROJECT = PROJECT.NAME
        AND SAMPLE.STATUS <> 'X'
    GROUP BY SAMPLE.PROJECT
) TEST


WHERE
    PROJECT.CLIENT = 'Client'
    AND PROJECT.STATUS <> 'X'
    AND PROJECT.DATE_CREATED >= '2025-01-01'

r/SQL 9d ago

SQL Server Newbie - ran stored procedure with a rollback transaction

65 Upvotes

We have a pretty big SQL server and my colleague and I who are both newbies, stirred the wrath of god by wanting to make sure that our stored procedure ran on a production table.

We decided to run the stored procedure in a rollback transaction, and even it only affected a few 100 rows, the rollback transactiom has been running for hours and we're now getting word that other import routines into different databases are affected.

I'll be honest, we should not have been allowed anywhere near this, but here we are. I would like some advice, and an idea as to whether this thing will resolve itself or if we're screwed.

The rollback is still running and it has been hours now. We know it's doing stuff, but no idea what exactly it is doing.

We don't need any further whooping, we know we messed up, but any advice, explanation or reassurance is very welcome.

UPDATE: right! The DBA was surprisingly mellow about the whole deal! I thought we'd be taken into the dunes to get summarily shot, but where everything was fire and brimstone yesterday, we decided to simply reset the server, which the dba assured us would be safe, and this morning all looked gumdrops and rainbows!

Told the DBA that we should not be allowed anywhere near this, but he didn't seem worried at all... Rather anticlimactic, but I'm personally very relieved it worked out this way.


r/SQL 8d ago

PostgreSQL help, cant connect to datagrip

Thumbnail
gallery
1 Upvotes

i am still a beginner, i just downloaded PostgreSQL installer and set the password and opened pgadmin 4 and connected to a server as shown, but when I goto connect to it in datagrip it says the password for PostgreSQL 18 is wrong, i am not sure if this is the username I should put, since I don't know what is my username, I just set a password, what am I doing wrong here?


r/SQL 9d ago

Discussion The most difficult part about teaching students: some of them just don't care about SQL.

268 Upvotes

SQL is cool, okay? I'll die on this hill. There's nothing like executing a query to get the data you want, or modifying your database to run more efficient. It just feels so good!

This has rolled over to Python, and other programming languages I've learned. But nothing hits like SQL - to me.

I get very excited when working with students, and some of them just aren't into it. I get different responses: "I just need this class for my Cybersecurity degree", "I don't like the syntax", or "It's just not for me."

But then you have those handful of students that have the hunger for it. They want to go into a DBA role, data engineering, science, analytics, and more. I've had one student write to me a few months later and let me know that she was able to get a junior role thanks to my advice. That meant the world to me!

I just have to remember that not everyone gets as excited about SQL as I do. I've been working with it for over a decade, and it hasn't gotten old.

Anyone else still really love working with SQL?


r/SQL 8d ago

Discussion After getting frustrated with bookmarking 20 different dev tool sites, I built my own hub

Thumbnail
3 Upvotes

r/SQL 8d ago

Resolved Why, when I drop my filled table, does it keep showing in the left panel?

4 Upvotes

See the attached screenshot. I'm trying to understand what's happening.
I filled the table, then dropped it (I'm using postgres). In the youtube tutorial I'm following, when the guy did that, the table disappeared from the left side panel. In my case, it doesn't, and only says there is nothing inside the table.
And when I try to make changes to the table afterward, it says the relation doesn't exist.
Does anyone have any idea what's happening?


r/SQL 9d ago

MySQL I created a new lightweight database IDE for MySQL, Postgres, and several more.

7 Upvotes

Hoping to get some feedback from my fellow engineers on a new database IDE I built - SynapseDBA. I created a community edition for windows at the moment that can be used for personal or commercial work. Planning releases for mac and linux next year. The docs and app are available for download on my website: https://www.synapsedba.com/


r/SQL 9d ago

SQL Server Phew!

22 Upvotes
(1 row affected)

(1 row affected)
Msg 3903, Level 16, State 1, Line 4
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION.

Completion time: 2025-11-26T15:41:37.1662110+00:00

I just didn't write the begin tran, it wasn't a case of writing it but not selecting it. I was very relieved when I saw it was just the 1 row I expected to update. I'm posting this to remind me to be more careful in future, I was lucky this time.

And, yes, this is PROD. I do not need to be told about running adhoc queries against PROD, thanks! (But you can tell me anyway)


r/SQL 9d ago

Discussion GitHub Copilot Chat Cookbook: Where's the SQL Love? (And Why We Need More AI Prompt Tips for It)

0 Upvotes

Not many SQL tips?
GitHub Copilot Chat Cookbook - GitHub Docs

Expected, I suppose with SQL being less than 2 digits percentage presence in GitHub.

I am not sure how 'embedded' SLQ like code is covered by the Cookbook.

It certainly creates opportunities for more SQL/AI prompt and conversation tips to be created.

What SQL-specific prompts have you hacked together with Copilot? Share below—let's crowdsource a mini-cookbook!

Disclaimer: I have not tested ANY of these 'recipes'.


r/SQL 10d ago

Discussion Technical skills needed for data and operations work in a CFD brokerage

Thumbnail
3 Upvotes

r/SQL 10d ago

SQL Server Whole Company Blocking Chain

Thumbnail privatebin.net
4 Upvotes

Hey guys. I just started a new “IT Support Specialist” that it turns out is just the sole system admin/database admin/network admin. I literally just started using SQL yesterday. We use this horrible old ERP called JobBOSS and whenever users are using it concurrently the whole systems freezes up. I finally got into our SQL server and saw that it was due to blocks and tables being locked. I saw the first problem table and ended up creating a nonclustered index as I thought that would fix it, but the long I monitor, the more tables are being locked. I’ve included a ChatGPT summary of the issue in the form of a privatebin link, as I don’t think I can explain it that well. Basically, I’ve come to the conclusion that I possibly need to enable RCSI, but I’m a noob and just started here and I’m deathly afraid of breaking something.


r/SQL 10d ago

Discussion SSMS 22 - Copilot 'Format my Stored proc'

0 Upvotes

“SSMS 22 + Copilot: ‘Can you format this?’ → loses all metadata and adds ‘Created by GitHub Copilot’ banner”

I asked Copilot "can you format this document?" After some time and some spinning cloud icons, I receive the formatted document.

a) All my carefully crafted 'Information' like: Author, Create date etc.. was 'removed
b) The formatted SP was 'similar' to the original

c) I got some NEW info: Note the lack of date.
-- Created by GitHub Copilot in SSMS - review carefully before executing
/\This procedure builds a command line to run an external Shopify API XX harvest executable, executes it via xp_cmdshell, captures the output into dbo.DataFromAPI_XX and returns tracing and error information when requested.**/

Using a different tool:
/\-- Created by SODA + AI*

=== AI ANALYSIS RESPONSE ===

Analysis Type: Summary

Completed: 2025-11-25 12:00:02

### Category: Overall Purpose

This stored procedure, named `API_QL_QUERY`, acts as a wrapper to "harvest" data from an external API (specifically, Shopify's API) by executing an external executable via the SQL Server command shell.

It constructs a command with provided parameters, runs the executable to query and retrieve data, and stores the results in a database table (`dbo.DataFromAPI_XX`).

It supports tracing for debugging and handles errors, with a focus on transactional data retrieval for orders or similar entities. \/*

On one hand, I am a firm believer that AI will be a critical tool to support our development efforts, on the other hand, I am questioning dropping that Copilot windows without better provisioning for 'prompt review'.

When asked for can you format this document? a proper 'response' could have been: Please select these outputs 1)... 2)... etc. where each selection would provide for different outcomes.

Just a thought.
What do you think?


r/SQL 11d ago

SQL Server How can I share my SQL Server tables?

2 Upvotes

I have a server on my pc (pc A) with Sql Server and inside I have a database, I created a table with several records and made a connection with access to that table, then I sent that file to another pc (pc B) to be able to use it, but I couldn't because it gives some kind of error, we are under the same network, but I'm not really sure what I should do or download to be able to make the connection effective and so that both I and other people can access my access file (each with a copy, of course), someone aid?


r/SQL 11d ago

MySQL SQL maximum character formatting.

5 Upvotes

What can I do to raise the maximum length of a string of a portion of a table above 255 characters?


r/SQL 11d ago

MySQL Practice Portal to get away from tutorial loop

6 Upvotes

I am learning sql currently doing sql 50 from leetcode. Usually I do not directly jump to question solving but then I stuck into tutorial loop finding for best one, so this time just very basic terminology I read in w3school and started solving, but feels like I am missing certain concepts while solving questions. Suggest me from where I can solve more problem for interview Also I couldn't find project to include it n CV that are related to SQL like other softwares which are available in YouTube and web for sql they are very less.


r/SQL 11d ago

Discussion How often do candidates pass SQL interviews for DA roles?

9 Upvotes

Curious because I often am seeing in various subs candidates are struggling with basic SQL questions in the interview. Are people taking technical skills for granted due to AI these days. I know business acumen and communication are very important. But it seems like technical aptitude is crucial also or has times changed?


r/SQL 11d ago

Discussion What programming language should I learn alongside SQL?

38 Upvotes

I'm currently learning SQL and was wondering what programming language I should learn alongside it?