Category Archives: MS Sql Server

How to rename a column in MS Sql Server using query?


In SQL Server, we can use sp_rename. The format is: sp_RENAME ‘TableName.[OldColumnName]‘ , ‘[NewColumnName]‘, ‘COLUMN’ For example table employee has column ‘Name’, we need to rename it to ‘FirstName’: sp_RENAME ‘employee .Name’, ‘FirstName’ , ‘COLUMN’ The above statement will rename the column Name table to FirstName. Tweet

Know which version of MS SQL Server you are running using query


To know the version of your running sql server, you need to execute below statement: SELECT @@VERSION To determine what instances of sql server/sql express you have installed try the following command: SELECT SERVERPROPERTY(‘productversion’), SERVERPROPERTY (‘productlevel’), SERVERPROPERTY (‘edition’) Tweet

How to get nth row from a table in MS Sql Server?


You might have occasion where you want to find who finished second, the 10th most popular rock track, or the 5th highest paid employee. This is trival using nested TOP statements, but that can be quite tough if you trying to get row 5,199,245. Here are some other options that you can test. This example assumes a unique FName, and tries the 10th name (in alphabetical order). SELECT * FROM ( SELECT ROW_NUMBER() OVER (ORDER BY key ASC) AS rownumber, [...]