T-SQL Tuesday #53: Why so serious8
April 8, 2014 by Kenneth Fisher
Why so serious? If you ask anyone who knows me they will tell you I’m not a terribly serious person. Add that to the comment “Mess with your co-workers” and I was hooked on this one. T-SQL Tuesday this month is hosted by Matt Velic (b/t) and he has picked a subject very close to my heart. I’ve always loved pranks between friends and while in college I traded pranks back and forth with several of my friends for years. In fact this piece of code is inspired by a prank I played on a PM friend of mine in the early days of my career.
She held the unfortunate nickname of “Blondie” (she dyed her hair) and as she was an intelligent individual this particular nickname rather annoyed her and as a male in my early twenties I couldn’t resist using it. At one point I wrote a piece of code that printed “Hi Blondie” on her screen 1 out of every hundred times she brought up a new menu and then removed it after 1 second. I put the code in place for a few hours then removed it and repeated every now and again. The code ran just often enough that she noticed it, but not so often she could show it to anyone. After a couple of days she called me sounding somewhat frantic. She thought she was going insane! I went down to her computer so she could try to show me this “bug” but when I got there I couldn’t keep a strait face which rather gave away the prank. As I recall she made a point of getting me back for that one!
By combining that inspiration with my love of old science fiction movies I came up with the following:
I give you .. the HAL0001.
CREATE TRIGGER HAL0001 ON DATABASE FOR DDL_DATABASE_LEVEL_EVENTS AS BEGIN DECLARE @Rand int DECLARE @Frequency int -- I've got the frequency set to 100 here which will cause this to -- trigger about 10% of the time. This is primarily for demonstration -- purposes. In the wild I would increase it to something like -- 1000 so it only triggers about 1% of the time. SET @Frequency = 100 SET @Rand = CAST(RAND(CAST(NEWID() AS varbinary))*@Frequency AS int) IF ORIGINAL_LOGIN()= 'login_test' AND @Rand < 10 BEGIN DECLARE @OutStr nvarchar(250) SET @OutStr = CASE @Rand WHEN 9 THEN 'I''m sorry, Dave. I''m afraid I can''t do that.' WHEN 8 THEN 'This mission is too important for me to allow you to jeopardize it.' WHEN 7 THEN 'Just what do you think you''re doing, Dave? ' WHEN 6 THEN 'Dave, stop. Stop, will you? Stop, Dave. Will you stop Dave? Stop, Dave.' WHEN 5 THEN 'Are you sure you''re making the right decision? I think we should stop.' WHEN 4 THEN 'I know I''ve made some very poor decisions recently, but I can give you ' + char(13) + 'my complete assurance that my work will be back to normal. I''ve still ' + char(13) + 'got the greatest enthusiasm and confidence in the mission. And I want ' + char(13) + 'to help you.' WHEN 3 THEN 'Thank you for a very enjoyable game.' WHEN 2 THEN 'By the way, do you mind if I ask you a personal question?' WHEN 1 THEN 'It can only be attributable to human error.' WHEN 0 THEN 'Affirmative, Dave. I read you.' END; IF @Rand BETWEEN 5 AND 9 BEGIN RAISERROR(@OutStr,1,16); ROLLBACK; END ELSE PRINT @OutStr END END;
Category: Bad idea Cowboy hat, DBA Humor, Microsoft SQL Server, SQLServerPedia Syndication, T-SQL, T-SQL Tuesday | Tags: code language, Humor, language sql, Microsoft SQL Server, T-SQL, T-SQL Tuesday
8 thoughts on “T-SQL Tuesday #53: Why so serious”
Leave a Reply Cancel reply
This site uses Akismet to reduce spam. Learn how your comment data is processed.
with a little more effort, I’m wondering on an imbedded red-eyeball graphic 🙂
You know I wanted to but I couldn’t figure out how to put that on the sql servers. I may at some point do HAL0002 with some ideas I got from Rob Volks T-SQL Tuesday post. Something along the lines of “Dave, I’m going to have to shut the instance down in 3” wait a few seconds “2” wait a few seconds “1” close the connection. Among other things 🙂
Thanks for participating, Ken, this is great!
Thanks for hosting. It was a great topic.
[…] now on they won’t be able to create or alter any code with NOLOCK or UNCOMMITTED in them. The HAL 0001 was just for fun. But now, I give you .. The HAL […]
[…] while back as part of a T-SQL Tuesday post I created HAL0001, then later HAL0002 with a long-term goal of building up a database version of HAL9000. Well, at […]
[…] HAL0001 randomly stopped you from making DDL changes. […]
[…] fun scripts: HAL0001, HAL0002, HAL0003, and […]