Hier sind diverse Möglichkeiten um zu überprüfen, für welche Tabellen kein Clustered Index definiert wurde:
CREATE TABLE dbo.t(c1 int) -- heap
CREATE TABLE dbo.t1(c1 int PRIMARY KEY) -- cix
CREATE TABLE dbo.t2(c1 int)
GO
CREATE NONCLUSTERED INDEX ix_t2 ON dbo.t2(c1) -- ncix
GO
SELECT
t1.*
FROM
sys.tables t1
WHERE NOT EXISTS(SELECT 1
FROM
sys.indexes
WHERE
[object_id] = t1.[object_id] AND
TYPE > 0) AND
OBJECTPROPERTY(t1.[object_id], 'IsMSShipped') = 0 AND
t1.[name] NOT LIKE 'sys%'
--oder
SELECT
o.*
FROM
sys.objects o
WHERE
OBJECTPROPERTY(o.object_id, 'IsTable') = 1 AND
OBJECTPROPERTY(o.object_id, 'IsMSShipped') = 0 AND
OBJECTPROPERTY(o.object_id, 'TableHasIndex') = 0
DROP TABLE dbo.t
DROP TABLE dbo.t1
DROP TABLE dbo.t2
Ab SQL Server 2005 sähe die Abfrage folgendermassen aus:
SELECT
*
FROM
sys.objects O
WHERE
O.type = 'U' AND
OBJECTPROPERTY(O.object_id, 'TableHasClustIndex') = 0