I want some Moore

Blog about stuff and things and stuff. Mostly about SQL server and .Net
posts - 226, comments - 2295, trackbacks - 33

My Links



Hi! My name is 
Mladen Prajdić  I'm from Slovenia and I'm currently working as a .Net (C#) and SQL Server developer.

I also speak at local user group meetings and conferences like SQLBits and NT Conference
Welcome to my blog.
SQL Server MVP

My Books

SQL Server MVP Deep Dives 2
The Red Gate Guide to SQL Server Team based Development Free e-book

My Blog Feed via Email
Follow MladenPrajdic on Twitter

Users Online: who's online

Article Categories


Post Categories

Cool software

Other Blogs

Other stuff

SQL stuff

SQL Server 2005 evil DBA prank

Today I feel a bit evil minded so I thought I'd share this little prank-friendly function.

If you put this into a .Net Assembly you import to SQL Server as a function or a stored procedure

you can wreck some real havoc :)


private static void SQLPrank()
    Random r1 = new Random(DateTime.Now.Millisecond);
    int lowerBound = r1.Next(1000, 2000);
    int upperBound = r1.Next(3000, 4000);
    int randomNumber = r1.Next(1000, 4000);
    1000             2000             3000             4000
    random lower bound                  random upper bound
                        random number 
       Exit          Normal operation             Wait
    if (randomNumber >= 1000 && randomNumber < lowerBound)
    else if (randomNumber >= upperBound && randomNumber < 4000)


The gem here is the Environment.Exit(0) which shuts down SQL Server without anyone having a clue why.

This is perfect for a prank on your least favorite DBA or developer. :)


kick it on DotNetKicks.com

Print | posted on Thursday, November 15, 2007 10:05 PM | Filed Under [ .Net SQL Server ]



# re: SQL Server 2005 evil DBA prank

I always thought a cruel prank was to set up an "instead of" trigger that did nothing!
11/16/2007 8:29 AM | Matt G

# re: SQL Server 2005 evil DBA prank

uuuu... combined with this in an instead triiger... ufff!! :))
that would be something!
11/16/2007 10:24 AM | Mladen

# re: SQL Server 2005 evil DBA prank

Wow - dunno what to say to that one. That would stump anyone for hours and hours. I would not be your friend when I found out the true answer :) Also good is the "old standby":

ALTER PROC GetEmployeeInfo (@EmpId INT)
IF USER = 'Mike'
WAITFOR DELAY '00:00:07'

SELECT * FROM EmployeeId=@EmpId
11/16/2007 11:08 AM | Scott Whigham

# re: SQL Server 2005 evil DBA prank

So the moral of the story here is to not trust UNSAFE code. That's why it's called "unsafe". If you do need unsafe code in your environment, it should be carefully reviewed by more than one person before deployment to make sure that there are no issues. And only authorized people should have access to deploy that kind of code to any servers that are of any value (including dev servers - bringing one down can cost the company plenty in terms of productivity).
6/15/2009 8:28 PM | Adam Machanic

# re: SQL Server 2005 evil DBA prank

Try An on insert or update trigger that changes altered fields to random values
7/3/2010 2:49 AM | JeffOrwick
Comments have been closed on this topic.

Powered by:
Powered By Subtext Powered By ASP.NET