Arcane Saturday SQL Tip

I was lucky enough to escape the grip of the dread meeting monster this week and actually got to do some T-SQL coding. I needed to know what sever my T-SQL code was running on. It made a difference as I would be taking one action if we were on a production instance, another if we were on a test box. SQL Server 2005 has some nice system information views built into the master database. All you have to do is use:

Select [name] as CurrentServerName from sys.servers where server_id = 0;

That’s all there is to it, according to books online the row with server id 0 is always the current server. You may find it useful to look through the other rows in the table, as any linked servers are recorded here as well.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: