SQL Server 2005 Index Filter Feature - sql-server

I was told that there is new a feature in SQL Server 2005 called index filters.
What I want to do is add an Index to a column and have the index ignore null values.
I can't find good information on this feature (maybe my source is wrong). Can anyone provide additional information on this feature?

CREATE INDEX ix_mytable_mycolumn ON mytable(mycolumn) WHERE mycolumn IS NOT NULL
This will work only in SQL Server 2008, though.
From the docs:
WHERE <filter_predicate>
Creates a filtered index by specifying which rows to include in the index. The filtered index must be a nonclustered index on a table. Creates filtered statistics for the data rows in the filtered index.

I think you are speaking about filtered indexes, which were introduced in SQL Server 2008, not 2005.
For information, have a look at this article: http://www.sql-server-performance.com/articles/dba/Filtered_Indexes_in_SQL_Server_2008_p1.aspx
Or just do a google search for "sql server filtered indexes".

Related

Indexing using UPPER function in SQL Server

I am trying to create the indexes using the liquibase using following query in SQL Server.
CREATE NONCLUSTERED INDEX LASTNAME_IDX ON EMPLOYEE(UPPER(LAST_NAME));
But I am getting the error while running the liquibase. It works fine in oracle. Let me know if there a way I can create the index in SQL Server
SQL Server does not support function indices, which Oracle does support. One workaround here would be to create a computed uppercase column, and then index that:
ALTER TABLE EMPLOYEE ADD LAST_NAME_UPPER AS UPPER(LAST_NAME);
CREATE NONCLUSTERED INDEX last_name_idx ON EMPLOYEE(LAST_NAME_UPPER);

SQL Server NOEXPAND with indexed view

I've been researching a bit on the use of indexed views and the noexpand hint in SQL Server and needed some clarification. Let's assume for this example you have two situations.
An indexed view is created against a table which already has an index created for the underlying table
An indexed view is created against a table which does not have an index created for the underlying table.
If we omit the noexpand hint, will SQL Server utilize the the view index in either situation? Or is noexpand only applicable when the table has an index and there is a choice to be made?
Secondly, does this behavior vary between editions of SQL Server? Has anything changed in 2012?
Depending what message board, blog, or MSDN documentation you read, it's a little unclear.

Does FluentMigrator support creating a filtered index?

Is it possible to create a filtered index with FluentMigrator? The scenario is that I want to create a unique index on a column that may contain NULLs, so the filter should exclude rows with NULL for the indexed column.
I've modified an index in SQL Server 2012 generated by FluentMigrator to use such a filter and can confirm that it works well, so the remaining piece of the puzzle is to generate this option.
As this is a very Sql Server specific feature you might as well fall back to sql.
One of the reasons for the fluent style is that it is not database specific so the same migration can be run for different database types. But if you are only ever going to use Sql Server and want to use database specific features then the great thing about FluentMigrator is that it allows you to execute sql statements. This is recommended for advanced stuff that we will never support in FluentMigrator and for changes in Stored Procedures.
It would simply be:
Execute.Sql(#"CREATE NONCLUSTERED INDEX FIBillOfMaterialsWithEndDate
ON Production.BillOfMaterials (ComponentID, StartDate)
WHERE EndDate IS NOT NULL;");
Postgres has partial indexes too so this could be something that we will add to FluentMigrator in the future.

How to ignore index in SQL Server

I found that one of the indexes is slowing my Query...but I can't drop it because it is used else where and it seems it is a good index for that query.
Is there a way in SQL Server 2005+, where I could ignore an index in a Query?

Is there a dynamic management view in SQL Server 2005 that pertains to column statistics?

The dynamic management views of SQL Server 2005 can give usage information about table indexes. Is there a similar method for getting usage information about column statistics? In specific, I'm curious if some of the older column statistics I've created are still being used. If not, I'd like to delete them.
no there isn't. there are however sys.stats_columns and sys.stats catalog views

Resources