Unix Technical Forum

How to use function based index in SQL Server2005?

This is a discussion on How to use function based index in SQL Server2005? within the SQL Server forums, part of the Microsoft SQL Server category; --> Don Burleson said in SQL Server2005, several new features are introduced include function based index.( Specialised index on a ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > SQL Server

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 03-01-2008, 03:25 PM
Steven
 
Posts: n/a
Default How to use function based index in SQL Server2005?

Don Burleson said in SQL Server2005, several new features are
introduced include function based index.( Specialised index on a
computed column (ala Function based Index))

But when I refered MSDN, I could't find this new function.

CREATE [ UNIQUE ] [ CLUSTERED | NONCLUSTERED ] INDEX index_name
ON <object> ( column [ ASC | DESC ] [ ,...n ] )
[ INCLUDE ( column_name [ ,...n ] ) ]
[ WITH ( <relational_index_option> [ ,...n ] ) ]
[ ON { partition_scheme_name ( column_name )
| filegroup_name
| default
}
]
[ ; ]

What should I if I want to create index like this:
CREATE INDEX IDX1 ON T1(COL1+COL2-COL3)

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 03-01-2008, 03:25 PM
Plamen Ratchev
 
Posts: n/a
Default Re: How to use function based index in SQL Server2005?

You have to create an index on the computed column, not on the expression
defining the computed column. If the computed column expression is imprecise
you can mark the computed column as PERSISTED (that will force storing the
computed value in the table).

See more details here:
http://msdn2.microsoft.com/en-us/library/ms189292.aspx

Here is one example:

CREATE TABLE Foo (
col1 INTEGER,
col2 INTEGER,
col3 INTEGER,
col4 AS col1 + col2 - col3);

CREATE INDEX ix_computed
ON Foo ( col4 );

INSERT INTO Foo (col1, col2, col3)
VALUES (2, 3, 4);

SELECT col1, col2, col3, col4
FROM Foo;

DROP TABLE Foo;

-- With imprecise computed column.
CREATE TABLE Foo (
col1 FLOAT,
col2 FLOAT,
col3 FLOAT,
col4 AS col1 + col2 - col3 PERSISTED);

CREATE INDEX ix_computed
ON Foo ( col4 );

INSERT INTO Foo (col1, col2, col3)
VALUES (2, 3, 4);

SELECT col1, col2, col3, col4
FROM Foo;

DROP TABLE Foo;


HTH,

Plamen Ratchev
http://www.SQLStudio.com



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 01:31 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com