Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
DJJUBES
Starting Member
4 Posts |
Posted - 2012-05-20 : 14:59:32
|
I need to show the total amount of rows in a specific table?The query is as follows:As part of the planning process to expand the database that supports Northwindoperations, the IT manager would like to know how many rows are currently in specifictables so that he can conduct capacity planning.The results needed include two columns, TableName( containing all the tables in the database and Rows, which contain the total amount of all the rows per table)Any advice would be much appreciated |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-05-20 : 15:46:13
|
easiest way is thisEXEC sp_Msforeachtable 'select ''?'',count(*) from ?'create a table to populate result and useINSERT tableEXEC.... (above EXEC code here) ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
prett
Posting Yak Master
212 Posts |
Posted - 2012-05-24 : 00:59:40
|
Query to find number Rows, Columns, ByteSize for each table in the current database:USE DatabaseNameGOCREATE TABLE #temp (table_name sysname ,row_count INT,reserved_size VARCHAR(50),data_size VARCHAR(50),index_size VARCHAR(50),unused_size VARCHAR(50))SET NOCOUNT ONINSERT #tempEXEC sp_msforeachtable 'sp_spaceused ''?'''SELECT a.table_name,a.row_count,COUNT(*) AS col_count,a.data_sizeFROM #temp aINNER JOIN information_schema.columns bON a.table_name collate database_default= b.table_name collate database_defaultGROUP BY a.table_name, a.row_count, a.data_sizeORDER BY CAST(REPLACE(a.data_size, ' KB', '') AS integer) DESCDROP TABLE #tempRef: http://blog.sqlauthority.com/2007/01/10/sql-server-query-to-find-number-rows-columns-bytesize-for-each-table-in-the-current-database-find-biggest-table-in-database/ |
|
|
mani_12345
Starting Member
35 Posts |
Posted - 2012-05-24 : 01:25:41
|
select object_name(sysindexes.id) "Database Name" ,rows from sysindexestry this u wll get a list of all database and number of rows and explore accrdngly which u want.i hope u got ur ans?? |
|
|
granuharmot
Starting Member
31 Posts |
Posted - 2014-09-23 : 05:14:22
|
unspammed |
|
|
|
|
|
|
|