473,394 Members | 1,935 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Record count in all tables

There a stored procedure or query that will count all the records
in all my tables in a database.

One of these two -

exec sp_MSforeachtable N'SELECT "table" = ''?'', cnt = COUNT(*) FROM ?'

select object_name(id), rows from sysindexes where indid in (1, 0)

Is there a way to add columns to the second query? I would like to see
how many columns and their names as well.

Thanks.

Jan 11 '06 #1
1 6818
digispace (di***********@comcast.net) writes:
There a stored procedure or query that will count all the records
in all my tables in a database.

One of these two -

exec sp_MSforeachtable N'SELECT "table" = ''?'', cnt = COUNT(*) FROM ?'

select object_name(id), rows from sysindexes where indid in (1, 0)

Is there a way to add columns to the second query? I would like to see
how many columns and their names as well.


It's not exactly clear how the output would look like. This query:

The second query could be extended to:

SELECT object_name(i.id), i.rows, colunms = COUNT(*)
FROM sysindexes i
JOIN syscolunms c ON i.id = c.id
WHERE i.indid IN (0, 1)
GROUP BY i.id, i.rows
ORDER BY 1

Gives you an approxamite row count and an exact column count.

SELECT object_name(i.id), i.rows, c.name
FROM sysindexes i
JOIN syscolunms c ON i.id = c.id
WHERE i.indid IN (0, 1)
ORDER BY 1, c.name

Lists the column names.

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Jan 11 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: dkalsow | last post by:
Ok, I have the following code. Does any one know how I go about taking this record set and trying to find if a record exits in it? - Thanks Dale Imports System.Data.SqlClient Public Module...
1
by: Justin Koivisto | last post by:
I am trying to create a report that displays a name of an advertising source and count of the number of times it was hit between certain date ranges. The data is split between two different...
1
by: Scott269 | last post by:
So I've got an old MS Works database I imported into Access. I needed a primary key so I created a record number field that was just the record number I manually inserted when I entered it in the...
1
by: Roy Gourgi | last post by:
Hi, I am using VS.NET 2003 and I have made a connection to a MS Access database using the Server Explorer. Is this connection permanent, meaning that it will be there every time I reopen my...
2
by: DC Gringo | last post by:
I have a datagrid control that has paging set up and working. What I would like is a total record count (not just per page) in the header or near the header of the datagrid. Here's my code: ...
9
by: Greg | last post by:
Binding Manager & dataset - won't add record I've got an untyped dataset with controls bound through code. The user can select a question number from a bound combobox, and the question number and...
4
by: Peter W Johnson | last post by:
Hi guys, I have a problem with a datagrid record count. Here is the code:- <snip> Public Class frmMerchantDeposit Inherits System.Windows.Forms.Form Dim myconnection As New...
2
by: pltaylor3 | last post by:
This has got to be easier than I am making it out to be. I have a query that calls on two tables linked by unique ids. I would like to have the previous outing's # of laps brought into the...
5
by: Clownfish | last post by:
I have a report that joins 12 external tables, and works great. However, there is a time when I wish to skip printing a particular record. Background: The 12 tables all have the same fields,...
3
by: Phil Stanton | last post by:
I have a form based on a complex query (Lots of tables) If I delete a record, everything appears to be OK. Get the message "Youa are about to delete 1 record ....". I say yes. The record count...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.