473,472 Members | 2,139 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 6821
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: 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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.