Thursday, August 9, 2012

How Many Rows are Present in a Table?

Have your manager or team leader asked to you about how many rows are present in a particular table? To answer this question, you have two option, first one is connect with the database developer who has created the database and second one is run a script yourself. Sometimes database developer may not present due to some reason to answer your question at this situation second solution is best for you. If you are a Sr. Developer then its your responsibility to answer your manager or team leader. You can write down bellow script to find out the total numbers rows in particular table.

USE Sample-Database-Name
SELECT OBJECT_NAME(OBJECT_ID) TableName, st.row_count
FROM sys.dm_db_partition_stats st
WHERE index_id < 2
ORDER BY st.row_count DESC

Result: This script shows a list with table name & row count. With the help of list you can able to answer your manager or team leader.

For example: Here is a list of all tables present in a particular database with their total number of rows.

Local Address
Permanent Address
Customer List & .....
202841 & ......

No comments:

Post a Comment