April 30, 2012

sp_ivindexhasnullcols (Transact-SQL MetaData) Definition

Please note: that the following source code is provided and copyrighted by Microsoft and is for educational purpose only.
The meta data is from an SQL 2012 Server.

I have posted alot more, find the whole list here.

Goto Definition or MetaData

Definition:

sys.sp_ivindexhasnullcols(nvarchar @viewname)

MetaData:

 create procedure sys.sp_ivindexhasnullcols (  
@viewname sysname
,@fhasnullcols bit OUTPUT
)
as
begin
declare @f_ind_unique bit
,@f_ind_clustered bit
,@ivobject_id int
,@indkey int
,@key sysname
,@retcode int

exec @retcode = sys.sp_MSreplcheck_publish
if @@ERROR <> 0 or @retcode <> 0
return(1)
--
-- validate view object
--
select @ivobject_id = object_id(@viewname)
,@fhasnullcols = 0

if (@ivobject_id IS NULL or @ivobject_id = 0)
begin
raiserror(15390, 16, 1, @viewname)
return 1
end

--
-- get the clustered index and validate
--
select @f_ind_unique = case (status & 2) when 0 then 0 else 1 end
,@f_ind_clustered = case (status & 16) when 0 then 0 else 1 end
from dbo.sysindexes
where id = @ivobject_id and indid = 1

if (@f_ind_unique != 1) or (@f_ind_clustered != 1)
begin
raiserror(21751, 16, 1, @viewname)
return 1
end

--
-- create an enumeration of all the columns that are part of the view index
--
create table #indcoltab(vindexcol int identity, keyname sysname collate database_default not null)
select @indkey = 1
while (@indkey <= 16)
begin
select @key = index_col( @viewname, 1, @indkey )
if (@key is null)
break
else
insert into #indcoltab(keyname) values(@key)

select @indkey = @indkey + 1
end

--
-- We should not have any column participating in this index
-- that allows NULL if we do
-- mark the output flag to TRUE
--
if exists (select *
from sys.columns
where object_id = @ivobject_id
and is_nullable = 1
and name in (select keyname from #indcoltab))
begin
select @fhasnullcols = 1
end

--
-- all done, cleanup and return
--
drop table #indcoltab
return 0
end

No comments:

Post a Comment

Total Pageviews