Tuesday, 24 June 2008

Creating a simple Computed Column in SQL2005

CREATE TABLE [dbo].[CustomerType](
[iCustomerTypeID] [int] IDENTITY(1,1) NOT NULL,
[vcDescription] [varchar](50) NOT NULL,
[vcMore] [varchar](50) NULL,
[LookUpDescription] AS
) Persisted NOT NULL

In this example the LookUpDescription column mimics the contents of the vcDescription field. Could have been concatenated fields or written a case statement or pretty much anything else. These columns do not take up storeage and CAN BE INDEXED!

So they will have a cost as far as indexing, and returning the results are concerned.