Кто-нибудь знает о хорошем скрипте для получения всех некластеризованных индексов для SQL Server 2005?Получить все некластеризованные индексы
4
A
ответ
13
Для всех некластеризованных индексов в конкретной базе данных:
select object_name(object_id) as tablename, *
from sys.indexes where type_desc = 'NONCLUSTERED'
Это вернет систему и несистемные таблицы. Альтернативно:
select t.name as tablename, i.*
from sys.indexes i, sys.tables t
where i.object_id = t.object_id
and i.type_desc = 'NONCLUSTERED'
только для некластеризованных индексов.
1
Вы можете получить все индексы для таблицы с помощью
exec sp_helpindex 'tablename'
Вы можете вставить это в таблицу, и удалить все строки, где INDEX_DESCRIPTION начинается с «CLUSTERED»
Вот скрипт для всех индексов в базе данных
declare @EmptyString varchar(1)
select @EmptyString = ''
-- 35 is the lenght of the name field of the master.dbo.spt_values table
declare @IgnoreDuplicateKeys varchar(35),
@Unique varchar(35),
@IgnoreDuplicateRows varchar(35),
@Clustered varchar(35),
@Hypotethical varchar(35),
@Statistics varchar(35),
@PrimaryKey varchar(35),
@UniqueKey varchar(35),
@AutoCreate varchar(35),
@StatsNoRecompute varchar(35)
select @IgnoreDuplicateKeys = name from master.dbo.spt_values
where type = 'I' and number = 1 --ignore duplicate keys
select @Unique = name from master.dbo.spt_values
where type = 'I' and number = 2 --unique
select @IgnoreDuplicateRows = name from master.dbo.spt_values
where type = 'I' and number = 4 --ignore duplicate rows
select @Clustered = name from master.dbo.spt_values
where type = 'I' and number = 16 --clustered
select @Hypotethical = name from master.dbo.spt_values
where type = 'I' and number = 32 --hypotethical
select @Statistics = name from master.dbo.spt_values
where type = 'I' and number = 64 --statistics
select @PrimaryKey = name from master.dbo.spt_values
where type = 'I' and number = 2048 --primary key
select @UniqueKey = name from master.dbo.spt_values
where type = 'I' and number = 4096 --unique key
select @AutoCreate = name from master.dbo.spt_values
where type = 'I' and number = 8388608 --auto create
select @StatsNoRecompute = name from master.dbo.spt_values
where type = 'I' and number = 16777216 --stats no recompute
select o.name,
i.name,
'index description' = convert(varchar(210), --bits 16 off, 1, 2, 16777216 on
case when (i.status & 16)<>0 then @Clustered else 'non'[email protected] end
+ case when (i.status & 1)<>0 then ', '[email protected] else @EmptyString end
+ case when (i.status & 2)<>0 then ', '[email protected] else @EmptyString end
+ case when (i.status & 4)<>0 then ', '[email protected] else @EmptyString end
+ case when (i.status & 64)<>0 then ', '[email protected] else
case when (i.status & 32)<>0 then ', '[email protected] else @EmptyString end end
+ case when (i.status & 2048)<>0 then ', '[email protected] else @EmptyString end
+ case when (i.status & 4096)<>0 then ', '[email protected] else @EmptyString end
+ case when (i.status & 8388608)<>0 then ', '[email protected] else @EmptyString end
+ case when (i.status & 16777216)<>0 then ', '[email protected] else @EmptyString end),
'index column 1' = index_col(o.name,indid, 1),
'index column 2' = index_col(o.name,indid, 2),
'index column 3' = index_col(o.name,indid, 3)
from sysindexes i, sysobjects o
where i.id = o.id and
indid > 0 and indid < 255 --all the clustered (=1), non clusterd (>1 and <251), and text or image (=255)
and o.type = 'U' --user table
--ignore the indexes for the autostat
and (i.status & 64) = 0 --index with duplicates
and (i.status & 8388608) = 0 --auto created index
and (i.status & 16777216)= 0 --stats no recompute
order by o.name
сценарий Джузеппе DiMauro на http://www.devx.com/vb2themax/Tip/18617
Смежные вопросы
- 1. Отключить все некластеризованные индексы
- 2. Некластеризованные индексы/CXPACKET Wait
- 3. Получить все индексы уникальных элементов
- 4. Как получить все индексы строки поиска
- 5. Получить все индексы каждой уникальной строки
- 6. Как получить все индексы шаблона в строке?
- 7. Получить все индексы для списка питона
- 8. Как получить все индексы из pandas DataFrame
- 9. Получить все индексы массива в CodeIgniter
- 10. Получить все Индексы заданных битов в BitSet
- 11. Elasticsearch подсчитывает все индексы
- 12. Производительность SQL Server: некластеризованные индексы + INCLUDE столбцы против кластеризованного индекса - эквивалент?
- 13. Кластеризованные/некластеризованные для некомпозитных ключей
- 14. Некластеризованные индексы в SQL Server - избирательность - и что находится на странице листового узла?
- 15. Все индексы списка
- 16. Как оптимизатор запросов SQL Server выбирает некластеризованные индексы из доступных индексов для конкретной таблицы?
- 17. Поддерживает ли индексы sqlite?
- 18. Pandas: Получить дублированные индексы
- 19. Удалить все индексы в строках
- 20. TitanDB Убрать все, включая индексы
- 21. Удалить все индексы в Lucene.net
- 22. PostgreSQL ищет все индексы массива
- 23. индексы, индексы, индексы
- 24. Java Bioinformatics - получить все индексы нескольких конкретных слов в строке
- 25. Elasticsearch: Как получить все индексы, которые когда-либо существовали
- 26. Как получить все индексы из базы данных в ravenDB?
- 27. Получить все индексы для данной таблицы с помощью JDBC
- 28. получить все индексы, объявленные в базе данных из java
- 29. Python3 поймать все индексы списка, чтобы получить доступ dicts
- 30. Pandas HDFStore MultiIndex DataFrames: как эффективно получить все индексы
Это не заслуживало понижения. –
оригинальный ответ сделал – super9