Feeds:
Posts
Comments

Archive for August, 2014

Quick one today:

Sometimes, we need to rename some column names. Surprisingly, there is no intuitive way to rename a column name in Sql Server i.e. ALTER TABLE statement type method. We need to use a system stored procedure called sp_rename.

Example Below:

The sample code below, renames the column ‘PKID’ in ‘dbo.ProductAttribute’ table to ‘ProductAttributesID’.

--
-- Rename Column
--
EXEC sp_rename 'dbo.ProductAttributes.PKID', 'ProductAttributesID', 'COLUMN'
GO

 

Hope this helps,
_Sqltimes

Advertisements

Read Full Post »

Quick one today:

Sometimes, for some scripts, viewing execution statistics for IO and TIME help measure the improvement you make with code changes.

They could be enabled with the following T-SQL:

--
-- Enable IO and TIME execution statistics for a query
--
SET STATISTICS IO ON
SET STATISTICS TIME ON
GO

-- Run some query
SELECT * FROM sys.objects
GO

-- disable them
SET STATISTICS IO OFF
SET STATISTICS TIME OFF
GO

Result:

SET STATISTICS ON

SET STATISTICS ON

Hope this helps,
_Sqltimes

Read Full Post »