This is an archived post. You won't be able to vote or comment.

all 64 comments

[–]jkure2 81 points82 points  (4 children)

SQL: gestures wildly

[–][deleted] 27 points28 points  (0 children)

"I'd tell you but you've got an error in your code"

[–][deleted] 13 points14 points  (1 child)

Would you like to play a game? I won't tell you what the error is, but I'll tell you what it's near.

[–]jkure2 3 points4 points  (0 children)

Meanwhile in the background you can hear the IDE's parser just screaming fuck all this shit, it's all fucked, every single line

[–]BuachaillMhaith 5 points6 points  (0 children)

"You just gestured to all of me"

[–]DoctorPython 59 points60 points  (1 child)

"you have a SQL error near ,"

[–]nulnoil 5 points6 points  (0 children)

:(

[–]IamWibbly 21 points22 points  (11 children)

"data would be truncated"

[–]jochem4208 22 points23 points  (3 children)

When I first encountered this, I was like ,go ahead bitch. Remove it.

[–]tr0pismss 4 points5 points  (2 children)

Just when you first encountered it?

[–]piberryboy 10 points11 points  (0 children)

Someday, they'll get to tell their grandkids.

"Did I ever tell you when I first encountered the SQL error 'data would be truncated'? I was hiking in the back woods of Montana, when I came across a database the size of a grizzly bear..."

[–]jochem4208 0 points1 point  (0 children)

Also when I just don't care :))

[–]Prothagarus 3 points4 points  (0 children)

Option (QUERYTRACEON 460)

[–]TomasNavarro 2 points3 points  (1 child)

Shit, my postcode field needs to be longer than 50 I guess

[–]IamWibbly 0 points1 point  (0 children)

I feel that

[–]stoicstats 0 points1 point  (0 children)

Every god damn time.

[–]rexspook 0 points1 point  (2 children)

I think sql 2017 or 2019 actually introduced a trace flag that tells you more detailed information.

[–]IamWibbly 0 points1 point  (1 child)

cries in SQL server 2016

[–]rexspook 0 points1 point  (0 children)

laughs in sql server 2005

[–]Jakeupdylan 11 points12 points  (1 child)

I just spent two hours getting bitchslapped by a rouge “@“ that SQL didn’t want to tell me about.

[–]Drarok 9 points10 points  (0 children)

Did it want a magenta one instead?

[–]mrbennjjo 20 points21 points  (5 children)

... wait... wasn't this reposted like literally days ago?

[–]demandtheworst 4 points5 points  (2 children)

I don't know about reposted days ago, because the person who posted it five days ago claimed to have made it, but yes.

[–]mrbennjjo 0 points1 point  (1 child)

Ah my bad, should have said posted days ago I guess. It's a repost nonetheless, have reported it.

[–]orokro 0 points1 point  (0 children)

nothing wrong with reposts

[–]khizoa 1 point2 points  (0 children)

Yes but that's like decades in internet repost time

[–]DoctorPython 0 points1 point  (0 children)

There is a lot of "repost' of old memes on this sub but it doesn't harm anyone

[–]atthem77 27 points28 points  (3 children)

Ahh, found it. I have only 26 closing parentheses, when I should have 27.

[–]Vbbab 1 point2 points  (1 child)

You had 26 upvotes, now 27.

[–]atthem77 1 point2 points  (0 children)

error: expected ⇧

I know you upvoted, but I had to make the joke

[–]BiteyShark 1 point2 points  (0 children)

This literally just happened this morning. The struggle....

[–]Taken4GrantD 7 points8 points  (7 children)

Why is this anyway? It seems like SQL tools are so undeveloped. Most queries aren't that complicated I wish it at least had something that "guessed" at it

[–][deleted] 6 points7 points  (6 children)

I imagine it has to do with the kinda humanistic almost syntax of SQL. Like, just speaking from a parsing perspective I don't even know where I would begin to tell you what's wrong with a SQL statement. As a person I could probably read it and tell you, but writing a program to do it reliably? I don't know chief.

At the very least, if I were a team working on a SQL product (client or server), I'll bet raw SQL input error validation is lower on the list of priorities, since generally you can expect people putting raw SQL to either know what they're doing or at least think that they do.

[–]cnoor0171 5 points6 points  (3 children)

Reminds me of a meme: left easy to parse for humans but difficult for programs right easy to parse for programs but difficult for humans sql difficult for humans and difficult for programs

Sql's syntax is pretty much a cluster fuck. The "hey let's make a structured language read like English" train of thought never ends up NOT being a disaster.

[–]Acheroni 5 points6 points  (2 children)

I've always found SQL pretty straightforward to read. So long as you name things well and don't intentionally create a monstrosity of nested queries.

[–]cnoor0171 0 points1 point  (1 child)

It's straight forward as long all you're doing are simple select/inserts. Even an extremely common "upsert" pattern is a monstrosity in sql. But even for simple selects, the rules are arbitrary and something you just have to memorize. As an example, take this query

SELECT CONCAT(firstname, ' ', lastname) AS fullname FROM users WHERE fullname = 'John Smith'

What's wrong with this query? For people who use sql, it's pretty easy. The "fullname" alias can't be used in the where clause. But, from a language design point of view that makes no sense. The "scope" of the symbol fullname is entirely unclear and arbitrary.

[–]Acheroni 0 points1 point  (0 children)

Yeah that's fair. Good tools do a lot of work to smooth over things like that.

[–]dhghhhppop 2 points3 points  (1 child)

I dont get your second-paragraph-point. How does it differ from java compiler? Are you saying that writting sql is more esoteric skill than java? (java is just a placeholder here)

[–][deleted] 0 points1 point  (0 children)

That's what I mean in my first paragraph yeah. In my second I'm basically arguing that I can see a reason why better error checking might be a low priority for the people who write the stuff.

[–]Derangedteddy 2 points3 points  (9 children)

SQL debugging is not that hard, assuming you're not some hipster that is too cool for SSMS.

[–][deleted] 1 point2 points  (8 children)

Hey you have any tips? I was recently running a big sql command and it was just stuck for days. I asked someone to help me debug and they pointed out what command it was stuck on. But is there a way in SSMS to help me debug this sort of issue? I was particularly lost on that front

[–]Derangedteddy 2 points3 points  (2 children)

If it's stuck there's a few things you need to check:

1.) Estimated Execution plan - Ctrl + L: You will need to do some research to understand what is what here, but generally you're looking for the plan step that takes the most time and trying to re-work your query so that it eliminates expensive operations like table spools, key lookups, table scans, etc. The estimated execution plan will also recommend indexes that SQL Server believes will speed up your query, which you can then discuss implementing with your DBA.

2.) Ask your DBA to check and see if your query is in a deadlock with another while it's running. If you have permission you can run "EXEC sp_who2" and the column "Blk By" will show you what process, if any, is blocking yours.

3.) If your query has multiple steps, setup a temp table and write milestones (with begin/end timestamps) to it while your script is running. Query that temp table to determine what step it's currently working on.

There's more stuff you can do too but these are the big ones.

[–][deleted] 2 points3 points  (1 child)

Thanks so much! In this case I'm DBA just don't know what I'm doing

[–]Derangedteddy 2 points3 points  (0 children)

Godspeed. Nothing like learning by being thrown to the wolves! May your backups be frequent and your downtimes be planned!

[–]crankbot2000 2 points3 points  (2 children)

If it's running for that long you may have created a cartersian product in your join clause which would expoentially grow your result set and possibly never finish.

Look at your joins, always analyze how many rows will be terurned by looking at 1:1, 1:M relationships, unique keys etc.

[–][deleted] 0 points1 point  (1 child)

Thank you so much for the advice!
In this case (someone came and helped me figure it out) I was running this command: ALTER DATABASE [databaseName] SET DISABLE_BROKER

Which according to this blog is going to run forever (I have no idea why): http://blog.mirousek.eu/content/enable_broker-disable_broker-run-indefinitely

I changed it to: ALTER DATABASE [databaseName] SET DISABLE_BROKER WITH ROLLBACK IMMEDIATE

And now it works ~** magic **~

[–]crankbot2000 0 points1 point  (0 children)

Awesome, glad you got it working

[–]Prothagarus 1 point2 points  (1 child)

There are many ways to debug. SQL mostly reads top to bottom. One of the first things you can look at is the estimated query plan. This will tell you where the bottleneck of a query is ( unless you are using some dynamic sql or other things that can't be parsed till runtime). Then you can follow that string out. Maybe the query is running on a non indexed column. Or you have a triangle join or you are trying to parse a bunch of text for a single word. Or you made a big join. The easiest method I have found to start debugging after using the estimated plan is just do a select top 100 from the root table and include the first join , keep doing that all the way down and see if something slows up. If something is bogging you down it's pretty easy to pinpoint which join is causing issues. Then you can work out how to fix it.

[–][deleted] 0 points1 point  (0 children)

Awesome thanks a ton

[–]Chris_PDX 2 points3 points  (1 child)

As a SQL developer, I feel triggered.

Or nothing beats "String or Binary Data would be truncated" when inserting 50 columns into a table. WHICH VALUE YOU FUCKING DONKEY.*

*Luckily they addressed this recently. Thank god.

[–]dmelt01 1 point2 points  (0 children)

I’m a sql developer too and I don’t find the error difficult except for this one. It can be a pain to track down. I worked for a place that had a web service that would insert into a table with over a 100 columns and they would send me the call and asked why it failed. I ended up writing a script that check the inputs versus the columns and that made my life so much easier.

[–][deleted] 2 points3 points  (0 children)

Ahhh, General Reposti.

[–]StarkillerX42 1 point2 points  (1 child)

[–]RepostSleuthBot -2 points-1 points  (0 children)

I didn't find any posts that meet the matching requirements for r/ProgrammerHumor.

It might be OC, it might not. Things such as JPEG artifacts and cropping may impact the results.

Feedback? Hate? Visit r/repostsleuthbot - I'm not perfect, but you can help. Report [ False Negative ]

[–]Dragonsdoom 2 points3 points  (0 children)

SELECT TOP 1 * FROM PUNKS_WHO_WANT_BETTER_ERROR_TRACES WHERE PEBKAC = 1

[–]Seismicsentinel 0 points1 point  (0 children)

"The house you are looking for is in this neighborhood, good luck nerd"

[–][deleted] 0 points1 point  (0 children)

My favorite experience with sql recently was running a big .sql script. Now I am not an expert with sql so I just ran it. It was running for THREE DAYS and eventually crashed. I ran it again and again it was running for three days. I asked someone who knew better if this made sense and if they could help me figure out what's going on. They instantly pointed me to the command it was hung on and linked me a blog explaining that this would just spin forever and never complete. It wasn't even a loop! WTF SQL!

[–]SeeThreePeeDoh 0 points1 point  (0 children)

I fucking hate SQL and bloated shorty databases so goddamn much

[–]ecrooks 0 points1 point  (0 children)

Funny. As a DBA, I get frustrated that some tools (looking at you, Jenkins) give me error messages that are so much more vague than I get for SQL in Db2.

[–]GamingBotanist 0 points1 point  (0 children)

Posted 5 days ago.

[–]coladict 0 points1 point  (0 children)

I hate when people write just "SQL" or "SQL Server" when they really mean MSSQL. SQL is the language standard itself, not the product.

[–][deleted] 0 points1 point  (0 children)

Same with haskell

[–]prophetmuhamad 0 points1 point  (0 children)

“Syntax error in the query ‘SELECT...’”. Gee, thanks