Tabele fara clustered index

Configurare noua (How To)

Situatie

Mai jos este o procedura care rulata pe o baza de date Microsoft Sql Server, returneaza toate tabelele ce nu au clustered index definit.

Solutie

create procedure FindTableWoClusteredIndexPrc

as

DECLARE @tbl TABLE
(
ID INT IDENTITY(1,1),
TableName NVARCHAR(100)
)

DECLARE @SQL NVARCHAR(MAX)
SELECT @SQL = ‘
SELECT distinct ts.Name
FROM sys.tables ts
LEFT JOIN sys.indexes si
ON ts.object_id = si.object_id
AND si.type = 1
INNER JOIN sys.databases d
ON d.name NOT IN ( ”tempdb”,”master”,”msdb”,”ReportServer”)
WHERE si.index_id IS NULL

INSERT INTO @tbl
EXECUTE (@SQL)

select * from @tbl

Tip solutie

Permanent

Voteaza

(13 din 31 persoane apreciaza acest articol)

Despre Autor

Leave A Comment?