How should I index a table for optimization to find zero?

I have a table, and the only time I will choose or do anything against it, I need to find all the rows where the column of a certain date is zero. From there, I do things with it and update this column, and probably I will never visit this line again, except for audit purposes.

So, is there any best practice to quickly find rows where my SentDate column is zero?

+3
source share
3 answers

To optimize a table to find NULL, you use indexes, of course. NULLs are indexed and searchable like any other value:

create table foo (a int null, b varchar(100) null);
create clustered index cdxFoo on foo(a);
go

insert into foo (a,b) select Number, 'not null' from master..spt_values

insert into foo (a,b) values (null, 'null')

select * from foo where a is null

, "NULL" .

+2

Default Value or Binding -, , . .

+1

In SQL Server 2008, you can filter the index to theoretically create your index to include only NULL values, i.e. WHERE SentDate IS NULL.

0
source

Source: https://habr.com/ru/post/1736377/


All Articles