Adding a clustered index to each table, then removing

  • Is there a script anywhere to do this?

  • Search books online (BOL) for creating indexing and dropping indexes

    Gethyn Elliswww.gethynellis.com

  • ok here goes, check if this is useful and change it to suite your needs or let me know:

    declare @tabname_var varchar(25)

    declare @sqlstm varchar(4000)

    declare @dbname_var sysname

    Declare dbnamecur cursor for

    select name from master.dbo.sysdatabases where dbid>4

    Open dbnamecur

    fetch next from dbnamecur into @dbname_var

    while @@fetch_status=0

    BEGIN

    declare tabcur cursor for

    select TABLE_NAME from information_Schema.tables where table_type='BASE TABLE'

    open tabcur

    fetch next from tabcur into @tabname_var

    while @@fetch_status=0

    BEGIN

    SET @sqlstm = ' ALTER TABLE ['+@dbname_var+'].[dbo].['+@tabname_var+']

    ADD CONSTRAINT ['+@tabname_var+'_PK] PRIMARY KEY CLUSTERED

    (

    [column1],

    [column2],

    [column3],

    [column4]

    ) WITH FILLFACTOR = 90'

    PRINT (@sqlstm)

    fetch next from tabcur into @tabname_var

    END

    close tabcur

    deallocate tabcur

    fetch next from dbnamecur into @dbname_var

    END

    close dbnamecur

    deallocate dbnamecur

Viewing 3 posts - 1 through 2 (of 2 total)

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