| We have two databases in the same SQL server instance. Both of the databases are copy of the production database, so both contains same tables. We added some records in Test Database’s some tables to update some features. We have added data in many tables of test database. Now we need to also update Production DB with the updated data. To update Production Database, we need to make sure in which tables we have updated data and then we will check and update production database accordingly. We have many numbers of tables, and we have updated many tables, so its not possible for us to check it manually. So, we need to make query to compare rows of each table with the another database tables, to find out which tables has different rows then the original database. Solution: As I need to solve this problem, I write a query which will give me Rows of each table in one Database. As I need to compare it with another database I write the following query to come out with the solution. Example: I have two databases. Database A and Database B. I need to make a report, which will give me details of each table and rows. I made this Stored Procedure in Database A. CREATE PROC CompareRowsBetweenDatabas This will give me results as I need. Let me know if it helps you. |
Learn SQL and database management at SQLYoga for articles, tutorials, and tips to improve your skills and streamline data operations. Join our community!
Showing posts with label Iterate Each Table. Show all posts
Showing posts with label Iterate Each Table. Show all posts
April 26, 2009
SQL SERVER - Query to compare number of Rows between different Databases
Labels:
Compare Database,
DBA,
Iterate Each Table,
Row Count,
sp_MSforeachtable
18+ years of Hands-on Experience
MICROSOFT CERTIFIED PROFESSIONAL (Microsoft SQL Server)
Proficient in .NET C#
Hands on working experience on MS SQL, DBA, Performance Tuning, Power BI, SSIS, and SSRS
March 26, 2009
SQL SERVER: How much space occupied by Each Table with sp_MSforeachtable procedure
Today, I came across requirement where I need to perform an action on all of the tables within a database.
For example, How much space occupied by each table.
I found undocumented Procedure: sp_MSforEachTable in the master database.
The following script reports the space used and allocated for every table in the database.
USE AdventureWorks;
EXECUTE sp_MSforeachtable 'sp_spaceused [?]'
So, We can use sp_MSforeachtable procedure when we need to loop through each table.
Let me know if it helps you in any way.
For example, How much space occupied by each table.
I found undocumented Procedure: sp_MSforEachTable in the master database.
The following script reports the space used and allocated for every table in the database.
USE AdventureWorks;
EXECUTE sp_MSforeachtable 'sp_spaceused [?]'
So, We can use sp_MSforeachtable procedure when we need to loop through each table.
Let me know if it helps you in any way.
Labels:
Iterate Each Table,
sp_MSforeachtable,
SQL,
SQL Server 2005,
SQL Tips,
T-SQL,
Tejas Shah
18+ years of Hands-on Experience
MICROSOFT CERTIFIED PROFESSIONAL (Microsoft SQL Server)
Proficient in .NET C#
Hands on working experience on MS SQL, DBA, Performance Tuning, Power BI, SSIS, and SSRS
Subscribe to:
Posts (Atom)