Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Filtered Index

Author  Topic 

ms65g
Constraint Violating Yak Guru

497 Posts

Posted - 2009-12-18 : 01:59:45
Hi,
I can create a Filtered Unique Index by DDL. but at wizard (design) I do not see any properties to set for Filter (Where), how can I do that?

create unique nonclustered index IX_test
on your_table (column_name)
where (column_name is not null) and (column_name <> 0)

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2009-12-18 : 02:25:25
Right click the column name-> Check Constrains

Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/
Go to Top of Page

ms65g
Constraint Violating Yak Guru

497 Posts

Posted - 2009-12-18 : 03:35:32
@senthil nagore --> Please re-read my question!
I want design a Filtered Index by using Wizard.
I need it (Filtered Unique Index) just for enforcing data integrity and I implement it by two other method.
Check Constraint Based on a UDF and TRIGGER.
take a look:

create function dbo.CustomUQ (@value int) returns bit as
begin
declare @b bit
if @value = 0
set @b = 1
else if not exists
(select *
from your_table
where column_name = @value)
set @b = 1
else
set @b = 0

return @b
end
go

alter table your_table
add constraint UQ_01
check ( dbo.CustomUQ ( Column_name ) = 1 )
go


create trigger trg_UQ
on your_table
instead of insert, update
as
begin
declare @v int
select @v = column_name from inserted

if @v = 0 or not exists
(select *
from your_table
where column_name = @v)
insert into your_table
select * from inserted

else
raiserror ('Duplicate Value',16,1)

end

Go to Top of Page
   

- Advertisement -