dev-resources.site
for different kinds of informations.
SQL-Quick tip #9 - Number of rows in all tables
Published at
4/19/2022
Categories
tsql
sqlserver
sql
mssql
Author
coderallan
Author
10 person written this
coderallan
open
Sql Server tips and tricks
This is part of a series of quick tips and tricks I have accumulated over the year, that I think can be useful for others.
If you have similar short tips and tricks please leave a comment.
Number of rows in all tables
When you start to work on a project for a new customer a good piece of information is how many tables does the database contain and how many rows are there in each table. Or maybe you don't have access to the production database and need to send a service request to the IT operations department to get information about the production database.
Then the query below will useful to you.
SELECT SCHEMA_NAME(sOBJ.schema_id) + '.' + sOBJ.name AS [Table name],
SUM(sPTN.Rows) AS [Row count]
FROM sys.objects AS sOBJ
JOIN sys.partitions AS sPTN ON sOBJ.object_id = sPTN.object_id
WHERE sOBJ.type = 'U'
AND sOBJ.is_ms_shipped = 0x0
AND index_id < 2 -- 0:Heap, 1:Clustered
GROUP BY sOBJ.schema_id, sOBJ.name
ORDER BY [Table name]
tsql Article's
30 articles in total
T-SQL avanzato: tecniche da ricordare
read article
SQL Server Management Studio (SSMS)
read article
T-SQL , Stored Procedures UNIT Testing - Part 2
read article
How to check if a temporary table exists and delete it if it does before creating a temporary table?
read article
How to search for text in a SQL Server stored procedure, function, or view?
read article
SQL Server 2022 - GENERATE_SERIES
read article
SQL Server 2022: Logical Functions - GREATEST & LEAST
read article
SQL-Quick tip #15 - Random dates
read article
SQL-Quick tip #13 - Index usage
read article
SQL-Quick tip #14 - Server information
read article
SQL-Quick tip #8 - Finding foreign key constraints
read article
SQL-Quick tip #12 - Available disk space
read article
SQL-Quick tip #10 - Select table definition
read article
SQL-Quick tip #11 - Most intensive queries
read article
SQL-Quick tip #9 - Number of rows in all tables
currently reading
How to find an account balance in SQL?
read article
SQL-Quick tip #7 - Find stored procedures
read article
SQL-Quick tip #6 - Find table or column
read article
SQL-Quick tip #5 - Create a sequence of date and time
read article
SQL-Quick tip #2 - Randomize rows
read article
SQL-Quick tip #4 - Random Int for each row
read article
SQL-Quick tip #1 - Range of Int
read article
SQL Server Primary Keys
read article
Calculating length of ntext data type with T-SQL
read article
What are the gotchas when converting a T-SQL statement into a JavaScript RegExp?
read article
How to prevent duplicate count value for inner join
read article
SQL Server: The Identifier Is Too Long; Max Length Is 128
read article
Geohash Open-Source library in TSQL for SQL Server
read article
How to monitor backup and restore progress in SQL Server
read article
SQL Query Inner Join for SUM Amount
read article
Featured ones: