I have two databases, which are basically identical running on the same machine.
I would like to compare the records in a table on database A vs the same table in database B
I would like to know which records exist in the table on database A that do not exist in the same table on database B.
Database A = "RICSTOREV341"
Database B = "RICHOSTV341"
The table is "Price_Tab"
The columns I would like to pull are F01, F26, F27, F19, F38
Can this be accomplished?
Yes, this can be done.
You could use something like a three part identifier to identify the tables in different database. Kinda like this :
RICSTOREV341.dbo.Price_Tab
Then you can perform a join on the primary key and fetch the result.
Besides the solutions above - I can also suggest using some 3rd party tools for performing data comparison, and most of them have a fully functional free trial (like SQL data comparison tools from ApexSQL or Redgate).
These tools can help you save lots of time, as they can do data comparison and synchronization in just a couple of clicks.
Hope I helped.
Related
I have a new requirement with me in which I have to merge data of two identical DB2 databases(around 200 tables in each) keeping all the unique rows from the both. these two databases are identical as they are from two different environment of same application and now clients wants them to merge together.
These tables are business tables, so they always have single records on the basis of Primary keys and foreign keys. which makes that there will be good chances of having the 2 records with same primary key when we will try to merge the databases. We only need to keep only single record out of these two records.
I am not getting a way to start doing this or how to proceed any Idea or approach will help, thanks in advance.
I have to prepare some set of JCLs which can use DB2 utilities, SQL or COBOL program to achieve this, but I am not getting a way to start doing this or how to proceed .. any Idea or approach will help, thanks in advance.
Both Syncsort and DFSORT have match merging capabilities, look for the JOIN control statement in the documentation. Use your shop's DB2 unload utility to extract the data from each table into a flat file, then use your shop's SORT utility to match merge the two versions of each table, outputting matched records to one file, unmatched records from the first version to another file, and unmatched records from the second version to a third file.
This isn't difficult, just tedious.
I have two databases for two different stores. They have the same tables and structure.
When I created the second one, I made a copy of the first one and I'm pretty sure that I forgot to delete some data from the first one before I activated the second one.
Now I need to find this data and delete it from db two because I have for example articles from store 1 in store 2's database.
Is there some easy way to identify the data that is in both databases?
So i find one way but this would cost me a lot of time.
In heidisql that i use i made a copy of the article table in db 1 and put it in db 2 with the Name article_db1
Then i made a SELECT * FROM article a INNER JOIN article_db1 ON a.artnr = b.artnr and like this i got the matches that is in both databases.
My Problem is that im afraid i have to do this on all 40 tables in the databases and becuase of that i was thinking that it's maybe some faster way to solve this.
In SQL server 2008 I have some huge tables (200-300+ cols). Every day we run a batch job generating a new table with timestamp appended to the name of the table.
The the tables have no PK.
I would like a generic way to compare 2 rows from two tables. Showing which cols having different values is sufficient, but showing the values would be perfect.
Thanks a lot
Thanks for the answers. I ended up writing my own C# tool to do the job - as I'm not allowed to install 3rd party software in my company.
There are several tools that do this for you.
My favorite is Red Gate SQL Compare.
If you don't have the money use the open source solutions. There are several
DB Compare
OpenDBDiff
You could create RPT files from SELECT queries then use Beyond Compare to see the differences.
Also, red-gate has some tools to compare database tables, but I think they're expensive.
When you need to compare two tables to see what the differences are, are there any tools or shortcuts you use, or do you handcode the SQL to compare the two tables?
Basically the core features of a product like Red Gate SQL Data Compare (schemas for my tables typically always match).
Background: In my SQL Server environment, I created a stored procedure which inspects the metadata of the two tables/views, creates a query (as dynamic sql) which joins the two tables on the specified key columns, and compares data in the compare columns, reporting key differences and data differences. The query can either be printed and modified/copied or just excecuted as is. We are not allowed to create stored procedures in our Teradata environment, unfortunately.
Sounds like a data profiling tool such as Talend's Open Profiler would make the most sense at that point.
You could write a BTEQ statement that builds the query similar to your SQL Server stored procedure and then export the dynamically built SQL. You can then in turn run that inside of your BTEQ. It might get cumbersome, but with enough determination you could probably mock something up.
I dont know if this is the right answer you are searching for.
sel * from database_name1.table_name1
minus
sel * from database_name2.table_name2;
you can do the same by selecting specific columns. This will basically give the non existent rows from table2 which are in table1.
If you were not looking for this type of answer, please ignore this and continue.
Also you can select like below.
select
table1.keycol1,
table2.keycol2,
(table1.factcol1 - table2.factcol2) as diff
from table1
inner join
table2
on table1.keycol1 = table2.keycol1
and table1.keycol2 = table2.keycol2
where diff <> 0
This was just an analysis which can give an idea. Please ignore any syntactical and programmatical errors.
Hope this helps.
I am using Toad. Frequently i need to compare tables in two different test environments.
the tables present in them are same but the data differs.
i just need to know what are the differences in the same tables which are in two different data bases.Are there any tools which can be installed on windows and use it to compare.
Take a look at SQL Compare and SQL Data Compare
There's a compare tool built into TOAD. Tools | Compare Data.
Open Source DiffKit will do this:
www.diffkit.org
I would definitely go with AdeptSQL if you're using MSSQL. It's the least good looking but the most talented db compare tool amongst the ones I've tried. It can compare both the structure and the data. It tells you which tables exist on one db but does not exist on the other, compares the structure and data of the common ones and it can produce the script to synchronize the two. It's not free but has a 30 day trial (as far as I can remember)
Try dbForge Data Compare for SQL Server. It can compare and sync any databases, even very large ones. Quick, easy, always delivers a correct result.
Try it on your database and comment upon the product.
If you want to do it online, there is a free tool DB Matcher where you upload 2 .SQL files and it gives you the differences
https://dbmatcher.com