powered by simpleCommunicator - 2.0.59     © 2026 Programmizd 02
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Форумы / Microsoft SQL Server [игнор отключен] [закрыт для гостей] / Обмен опытом
4 сообщений из 4, страница 1 из 1
Обмен опытом
    #32017486
Владимир
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Привет всем.
Эта статейка проскочила в рассылке и я думаю, может кому пригодиться...
От себя добавлю что это работает также в 2000.

Alexander Chigrik
chigrik@hotmail.com


To get the total row count in a table, we usually use the following select statement: SELECT count(*) FROM


This query will perform full table scan to get the row count. You can check it by setting SET SHOWPLAN ON for SQL Server 6.5 or SET SHOWPLAN_TEXT ON for SQL Server 7.0. So, if the table is very big, it can take a lot of time. This is the example of simple table creation and addition of new records into this table: CREATE TABLE tbTest (
id int identity primary key,
Name char(10)
)
GO
DECLARE @i int
SELECT @i = 1
WHILE @i <= 10000
BEGIN
INSERT INTO tbTest VALUES (LTRIM(str(@i)))
SELECT @i = @i + 1
END
GO


There is another way to determine the total row count in a table. You can use sysindexes system table for this purpose. There is field ROWS in the sysindexes table. This field contains the total row count for each table in your database. So, you can use the following select statement instead above one: SELECT rows FROM sysindexes
WHERE id = OBJECT_ID('table_name') AND indid < 2


There are physical read and logical read operations. A logical read occurs if the page is currently in the cache. If the page is not currently in the cache, a physical read is performed to read the page into the cache. To see how many logical or physical read operations were made, you can use SET STATISTICS IO ON command. This is the example: SET STATISTICS IO ON
GO
SELECT count(*) FROM tbTest
GO
SELECT rows FROM sysindexes WHERE id = OBJECT_ID('tbTest') AND indid < 2
GO
SET STATISTICS IO OFF
GO


This is the results: -----------
10000

(1 row(s) affected)

Table 'tbTest'. Scan count 1, logical reads 32, physical reads 0, read-ahead
reads 0.
rows
-----------
10000

(1 row(s) affected)

Table 'sysindexes'. Scan count 1, logical reads 2, physical reads 0,
read-ahead reads 0.


So, you can improve the speed of the first query in several times. This works for SQL Server 6.5 and SQL Server 7.0 as well.
...
Рейтинг: 0 / 0
Обмен опытом
    #32017489
olegusan
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Спасибо. Интересно.
А не подскажите адресок сервера рассылки?
...
Рейтинг: 0 / 0
Обмен опытом
    #32017516
Фотография Александр Гладченко
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
...
Рейтинг: 0 / 0
Обмен опытом
    #32017519
BiSas
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
На самом деле здесь существенное ограничение, как правило количество записей надо по какому-нибудь условию. А в этом случае обращение к sysindexes не поможет.
...
Рейтинг: 0 / 0
4 сообщений из 4, страница 1 из 1
Форумы / Microsoft SQL Server [игнор отключен] [закрыт для гостей] / Обмен опытом
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]