There is a fast and easy way to determine the number of rows in a table. Instead of using queries like:
Select COUNT(*) from tablename
where it is necessary to use the datatable, you can use the systemtable:
SELECT rows
FROM sys.sysindexes
WHERE (id = OBJECT_ID('tablename'))
AND (name = 'PrimaryKey name').
This is very fast, because you select only one row.
Showing posts with label SQL. Show all posts
Showing posts with label SQL. Show all posts
Monday, December 04, 2006
Friday, September 29, 2006
Query Select random row
I was looking for a way to select a random row from a table, preferably in a stored procedure.
This is the query:
SELECT TOP (1) *
FROM table
ORDER BY NEWID()
Simple and effective!
This is the query:
SELECT TOP (1) *
FROM table
ORDER BY NEWID()
Simple and effective!
Subscribe to:
Posts (Atom)