script needed - to lists all the tables without a clustered index - sql2k5/2k

  • The script must exist somewhere, I believe. Anyone would like to share?

    Thank you in advance.

  • Vivien Xing (9/22/2008)


    The script must exist somewhere, I believe. Anyone would like to share?

    Thank you in advance.

    1 EXEC sp_tables

    2 select * from sys.tables

    3 select * from sysobjects where xtype='u'

    4 select * from sys.objects where type='u'

    5 select * from INFORMATION_SCHEMA.TABLES where table_type='base table'


    Madhivanan

    Failing to plan is Planning to fail

  • select o.name from sys.indexes i

    inner join sys.objects o

    on o.object_id = i.object_id

    where i.index_id = 0

  • Suresh B. (9/23/2008)


    select o.name from sys.indexes i

    inner join sys.objects o

    on o.object_id = i.object_id

    where i.index_id = 0

    Why do you think it is neccessary to join sys.indexes?


    Madhivanan

    Failing to plan is Planning to fail

  • Becuase the subject says

    script needed - to lists all the tables without a clustered index - sql2k5/2k

  • When you create a table without cluster index, a row is inserted in the sysindexes table marking this table is a HEAP. This is show by the indid field.

    In SQL Server 2000 the query is:

    select o.name from sysindexes i

    inner join sysobjects o

    on o.id = i.id

    where i.indid = 0

  • Thank you all for help. I limited to the user tables only.

    Here is the code with minor change:

    -- SQL2005:

    select o.name from sys.indexes i

    inner join sys.objects o

    on o.object_id = i.object_id

    where o.type = 'U' and i.index_id = 0

    -- SQL2000:

    select o.name, i.indid from sysindexes i

    inner join sysobjects o

    on o.id = i.id

    where o.xtype = 'u' and i.indid = 0

  • Suresh B. (9/23/2008)


    Becuase the subject says

    script needed - to lists all the tables without a clustered index - sql2k5/2k

    Well. I did nto see the title fully 🙂


    Madhivanan

    Failing to plan is Planning to fail

Viewing 8 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic. Login to reply