Fun with SQL part 2

Fun with SQL part 2

This BlogPost was written by Andre Speek. Click here for other BlogPosts.

Last time we looked at some easy tricks to tease your co-worker when you have only a few seconds. Like when he or she is away from his computer and Management Studio is open. In this post we will explore some more.

Again, this is for fun. Never do this on Production!

Ready? Set? Go?

You might not be aware of this, but GO isn't actual an SQL command. It is merely a seperator in Management Studio to indicate that Queries seperated by GO should be executed one by one.

There is even a Setting for this under Tools, Options, Query Execution:

Since it is a Setting, it can be changed. Can you imagine when you change it to FROM? No, you should really try it and run any Select Statement after that!

p.s. It would only affect queries in windows opened after the change.

Where did that Column go? It is still there?

A bit evil, but you can rename an often used Column but only make a subtle change. Like adding a Tab in the name:

EXEC sp_rename 'dbo.Absences.HID', 'HID ', 'COLUMN';

Make sure you add a Tab and not a Space since that one will be trimmed. From now on, this Query will fail because the Column does not exist:

select HID
from Absences

Additional bous is that the Column still shows up in the Onject Explorer. And you will see it when you do a "select * from Absences". But that is because the Tab is not visible there.

Is your co-worker getting desperate? Simply rename it back to its original name.

EXEC sp_rename 'dbo.Absences.HID ', 'HID', 'COLUMN';

It works on my machine

This one is fun when you are working together and it doesn't require you to have access to your co-worker's machine.

First you need to find your login name with this:

select original_login()

Now go and copy what value and use it add a Constrain to a View you are working on, like this:

original_login() = '[the_value_you_copied]'

Since this one is only True when you run it, it will produce no results at all for anyone else.

That's it for today

Yes, we're done for today. Now go back to work and be kind for your co-workers.



Do you want to comment on this post? Leave a response here and I will get in touch with you!

You can leave a comment or send a question to andre@andrespeek.com. Let me know if you got inspired and stay safe and healthy always!




An error has occurred. This application may no longer respond until reloaded. Reload 🗙