Category: Bad Idea Jeans

Poor Man’s Resource Governor: Database-Scoped Configurations

Let's say you had report queries that were going wildly parallel, and you wanted to put a stop to it, but you couldn't afford SQL Server Enterprise Edition.

You could do is create databases with different MAXDOP settings:
[crayon-6a72da343680f913613208/]
Yes, MAXDOP has been a database-scoped configuration since SQL Server 2016.

Read more about Poor Man’s Resource Governor: Database-Scoped Configurations 4 comments — Join the discussion
T-SQL & Development

Stupid T-SQL Tricks

Presented without comment:
[crayon-6a72da34434f6199740131/]
Next up, can you break up a query with spaces? Yep:
[crayon-6a72da34434fe174451172/]
Well if you can do that - can you break up a query across lines? Sure you can:
[crayon-6a72da3443501231583620/]
And now, brace yourself: this one is so weird that I can't even embed it in the blog. I'm just going to show you a picture of it first:

Read more about Stupid T-SQL Tricks 33 comments — Join the discussion
T-SQL & Development

Creating Insert Triggers to Silently Ignore Data You Don’t Want

Say you've got an application that insists on inserting data into the database, and...you don't want the data.

You want the application to THINK it inserted the data - you don't want to roll it back or return an error to the end user. You just don't want the data, and you don't want the hassle of deleting it later.

Read more about Creating Insert Triggers to Silently Ignore Data You Don’t Want 19 comments — Join the discussion
Performance Tuning

How to Drop All Your Indexes – Fast

Sometimes I need to reset stuff during performance training classes. I know some of you teach classes, too, and some of you just like doing crazy stuff. So here you go, a stored procedure to lose weight fast: DropIndexes for SQL Server 2016 & Newer [crayon-6a72da3446583534089836/] DropIndexes for SQL Server 2008-2014 This one doesn't include…

Read more about How to Drop All Your Indexes – Fast 28 comments — Join the discussion
News & Opinion

Stupid Things I’ve Done With SQL

I Always Enjoy Reminiscing
And that header is a lie. I do enjoy thinking about stuff I used to have to do at work, because I don't have to do it anymore. While we mostly gripe about the on-call stuff, the late night maintenance windows, etc., we don't usually talk about the goofy stuff we've done. What follows is a non-comprehensive (and embarrassing code free) list of things I've done with SQL that I really should have used something else to do.

Read more about Stupid Things I’ve Done With SQL 20 comments — Join the discussion
News & Opinion

Bad Idea Jeans Week: Dynamically Generating Long Queries

As part of an experiment, I needed to build a really long query. (Don't ask.)

From another recent experiment, I know that SQL Server won't let a query return more than 65,535 columns. I set about writing a one-line query that would return 65,535. I'm a big fan of writing the simplest reproduction scripts possible - I don't want them to rely on tables if they don't have to - so we'll start a CTE like this:

Read more about Bad Idea Jeans Week: Dynamically Generating Long Queries 12 comments — Join the discussion
News & Opinion

Bad Idea Jeans Week: Building a Fork Bomb in SQL Server

Somewhat different than a sex bomb, a fork bomb is a denial-of-service attack that just starts a process that replicates itself, thereby starting more and more processes until the service goes down. Wikipedia's fork bomb page lists examples on most operating systems (including Windows).

I've always found fork bombs funny because of their elegant simplicity, so I figured, why not build one in SQL Server?

Read more about Bad Idea Jeans Week: Building a Fork Bomb in SQL Server 14 comments — Join the discussion
News & Opinion

Bad Idea Jeans Week: Prevent the Use of the Database Engine Tuning Advisor

Every now and then, we put on our bad idea jeans in the company chat room and come up with something really ill-advised. We should probably bury these in the back yard, but...what fun would that be? Bad ideas are the most fun when they're shared. One day, after seeing enough horrific but well-meaning indexes created…

Read more about Bad Idea Jeans Week: Prevent the Use of the Database Engine Tuning Advisor 12 comments — Join the discussion
News & Opinion

Bad Idea Jeans: Dynamically Generating Ugly Queries and Task Manager Graffiti

Say you're at Dell DBA Days, and you want to build a really ugly query, fast. You want to generate a StackOverflow database query that will take a long time to compile, and maybe demand a huge amount of memory to run, but not actually take any time to execute.

You might start by building a numbers table with Method #7 from this StackOverflow answer, and then:
[crayon-6a72da344a6f0876103151/]
Which gives you a 10,000 join query, but I'm only showing the first 10 lines here:

Read more about Bad Idea Jeans: Dynamically Generating Ugly Queries and Task Manager Graffiti 10 comments — Join the discussion
Performance Tuning

Creating Tables and Stored Procedures in TempDB – Permanently

No, not #tables - actual tables. Here's how: [crayon-6a72da344ab5f063228051/] The first one disappears when my session is over, but the latter two persist until the SQL Server is restarted. Why would you ever do the latter two? Say you need to share data between sessions, or between different applications, or staging tables for a data…

Read more about Creating Tables and Stored Procedures in TempDB – Permanently 47 comments — Join the discussion
Performance Tuning

Trace Flag 2330: Who needs missing index requests?

Hey, remember 2005?
What a great year for... not SQL Server. Mirroring was still a Service Pack away, and there was an issue with spinlock contention on OPT_IDX_STATS or SPL_OPT_IDX_STATS. The KB for it is over here, and it's pretty explicit that the issue was fixed in 2008, and didn't carry over to any later versions. For people still on 2005, you had a Trace Flag: 2330.

Read more about Trace Flag 2330: Who needs missing index requests? 7 comments — Join the discussion
News & Opinion

Brent’s Bad Idea Jeans: Stop People From Changing Tables with This One Trick

Developers hate his bad idea jeans:
[crayon-6a72da344baae416904809/]
Presto, the schemabinding option means no one can change the underlying tables. (At least, until they figure out about your view.)

Obligatory disclaimer: seriously, this is a really bad idea. But it's hilarious.

Read more about Brent’s Bad Idea Jeans: Stop People From Changing Tables with This One Trick 21 comments — Join the discussion