SQL Server Interview Questions and Answers
<< Previous Question Next Question >>
 Question: 1695 Page Views: 

How can we find the number of rows in a table?



Posted By: Avi Date: 19 September 2009 04:51:20 AM
 Answer:

Following SQL statements can be used to get the number of rows in a table:

SQL Query - 1:
SELECT COUNT(*)FROM TableName

SQL Query - 2:
SELECT rows FROM sysindexes WITH (NOLOCK) WHERE id = OBJECT_ID('TableName') AND IndId < 2

*The second query will return data faster than first one.


Posted By: eTechPlanet


Date: 19 September 2009 04:51:20 AM
Post a better Answer if you have
 
(Will show your Gravatar icon)  
  Country flag

Loading
Enter the text as shown in the image 0vGtnM
Related Questions
SQL Server : Write the query to Select the name of the product whose total sales is 20 form the following table named sales:-
PID    Pname      Sale
1        Soap         5
2        Brush       10
3        Tea          8
1        Soap        12
2        Brush       5

Write the query to Select the name of the product whose total sales is 20 form the following table n....

select Pname from sales group by PID having sum(sale)=130
Category: SQL Server Date: 10/1/2010 11:42:07 AM
SQL Server : What will be returned with @@identity T-Sql?

What will be returned with @@identity T-Sql?

It will return the last inserted identity value. It will return a numeric value. So whenever a row ....
Category: SQL Server Date: 10/1/2010 11:41:07 AM
SQL Server : Why there is a need to use secondary database file when the same work can be done with primary databse files?

Why there is a need to use secondary database file when the same work can be done with primary datab....

Secondary files can be spread over multiple disks which will enhance the I/O operations.
Category: SQL Server Date: 10/1/2010 11:40:07 AM
SQL Server : What will be the result of the following query ? Explain your answer.
create table  tempo 
(sno INT, item_code nvarchar(2)) ;
 
insert into tempo
select 1, '0' UNION 
select 2, '11' UNION 
select 3, '12' UNION 
select 4,'0' UNION 
select 5,'0' 
 
update t

What will be the result of the following query ? Explain your answer. create table tempo (sno INT,....

The given query will result inot 3 rows. Sno item_code 1 4 5 ....
Category: SQL Server Date: 10/1/2010 11:38:07 AM
SQL Server : What is the purpose of sp_lock?

What is the purpose of sp_lock?

sp_lock is a stored procedure which returns the detailed information regarding the locks. The follow....
Category: SQL Server Date: 10/1/2010 11:37:07 AM