How to rename a table or column using T-SQL in Microsoft SQL

So yeah, you could use the Microsoft SQL Server Management Studio UI to rename your table or column. But sometimes you need to do the rename in T-SQL. Here’s how.

How to rename a table:

EXEC sp_rename 'OldTableName', 'NewTableName'

How to rename a column:

EXEC sp_rename
    @objname = 'TableName.OldColumnName',
    @newname = 'NewColumnName',
    @objtype = 'COLUMN'

For a more detailed explanation of sp_rename check out this MSDN article: http://msdn2.microsoft.com/en-us/library/ms188351.aspx.

If Then Else Shorthand in C#

Sometimes you need to use “If Then Else” logic on something really simple, but all those brackets and parentheses are ugly and confusing. So instead use some fancy shorthand!

In this example I want to display the top 5 items in my array, but if my array is less than 5 items long I want to show all of the items up to the length of my array. (Otherwise I’d get an “index out of bounds” error for trying to access array items that don’t exist.)

int showTopEntries = 5;

showTopEntries = showTopEntries >= totalEntries ? totalEntries : showTopEntries;

This reads as: If 5 is greater than or equal to my array’s length, then use my array’s length, else use 5.

Your significant other is gonna’ be really impressed with this bit of code! Well, unless your significant other is also a programmer… then my sarcasm is lost. :/

I’m crushing over Drobo!

I’m in love with Data Robotics, Inc. no hassle data redundancy device, Drobo. I’ve been kicking around the idea of building my own RAID 5 network file server to store all of my music, videos, pics, and et cetera for a couple of years now. But that, of course, is no easy task, nor is it easy on the pocket book. And now here comes Drobo to my rescue!

So I’m dropping the “build my own RAID 5 network server” idea. Now I want to get a Drobo and new wireless Linksys router with USB storage support. Although, I’ve heard a rumor that Data Robotics, Inc. is planning on coming out with a new Drobo with built in network support later this fall or early next year. I’m not sure I can wait that long. This thing is just too cool.Oh, I heard about the Drobo and this YouTube video on TWiT. Great Podcast.