Compare the rowcount from tables of two databases


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Compare the rowcount from tables of two databases
# 1  
Old 07-30-2010
Compare the rowcount from tables of two databases

All,

I have to create a shell script to comapre the rowcount of 120 tables from two oracle databases. In fact, using informatica the data is loading from 120 source tables to 120 staging tables. After that, they want to have a shell script to comapre the rowcount of all these tables.

1) I think we can spool the rowcount to two files. But what should be the best strategy to handle this 120 tables? If I hard code the 120 tables in my script to get the rwocount, the script may not run later if the tables got changed.

2)Also, how do we compare the two spool files with rowcount?

Can somebody help here pls?

Thanks
Maya
# 2  
Old 07-30-2010
MySQL Reply Spool

Hi,

Its quite interesting question..

I think u should read the file from some directory after spooling.
1. Within a 'for loop' u can access the file one by one.(table change may not effect)
2. then within the do statement u can use: either awk/WC -l to count the rows.

or u can compare two file using:wc -l <file1> file2 /// comp -l file1 file2


Please try this..
Smilie
# 3  
Old 07-30-2010
Thanks Jdash

1) what is the way of getting rowcount for 120 tables ?

Select count(*) from table1;

select count(*) from table 2;

like that if I list all 120 tables, the code won't be flexible.

2)Also, do we need to have one spool file for 120 tables ? or one spool file for one table? what would be the best method?

3)Can somebody pls paste some code here ? for spool and compare

Thanks
Maya
# 4  
Old 07-30-2010
Bug

Hai.. here is a sample snippet..
First write all your 120 tables names in a file, say, "tables.lst"..

Code:
for table in `cat tables.lst`
do
   sqlplus -s << EOF >>file_spool.txt 2>file_err.txt
   select ${table}||':'||count(*) from ${table};
EOF
done

First_tbl_cnt=`head -1 file_spool.txt | cut -d":" -f2`
awk -F":" -v cnt=${First_tbl_cnt} '$2!=cnt {print $0}' file_spool.txt

Now you will get the list of tables along with the actual record count which ever is not having the same record count as your first table. If nothing displayed, then it means that all your table record counts are same..

My worry is the 120 SQLPLUS login operations you need to do here..

Thanks,
Ramkrix
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Compare with 2 tables

I have 3 file inputs, file1 20160302|5485368299953|96|510101223440252|USA|5485368299953|6|800|2300|0 20160530|5481379883742|7|510101242850814|USA|5481379883742|5|540|2181|1500 20160513|5481279653404|24|510100412142433|INDIA|5481279653404|3|380|1900|0... (1 Reply)
Discussion started by: radius
1 Replies

2. Shell Programming and Scripting

Howto compare the columns of 2 diff tables of 2 different schemas in UNIX shell script

HI All, I am new to Unix shell scripts.. Could you please post the unix shell script for for the below request., There are two different tables(sample1, sample2) in different schemas(s_schema1, s_schema2). Unix shell script to compare the columns of two different tables of two... (2 Replies)
Discussion started by: Rajkumar Gopal
2 Replies

3. Shell Programming and Scripting

Two databases

Hello, I have two databases one is student_Name and another is student_Name1...Two tabled contain 200 records each..I found that near 30 names are entered in both databases..I would like to remove the duplicates..and i have to keep the name which is newly added..Please hepl how to remove... (7 Replies)
Discussion started by: Anjali_vee
7 Replies

4. Shell Programming and Scripting

Cut rowcount from one file to another

Hi guys! I need to cut first row from a file (using awk) without the record separator character (in my case its MS-DOS 0D0A) and field separator character (in my case ; 3B) and put it in another file. Can you help with that? Regards, PsmakR (18 Replies)
Discussion started by: PsmakR
18 Replies

5. Shell Programming and Scripting

compare two tables using shell script

Hi, I want to compare two tables fieldwise using shell script. Can anyone help me regarding the same. The approach which i tried is to first move the two tables in simple txt file where each field is now seperated by space. But i can't retrive each field with "space" as a seperator b'coz there... (1 Reply)
Discussion started by: dtidke
1 Replies

6. Shell Programming and Scripting

Converting tables of row data into columns of tables

I am trying to transpose tables listed in the format into format. Any help would be greatly appreciated. Input: test_data_1 1 2 90% 4 3 91% 5 4 90% 6 5 90% 9 6 90% test_data_2 3 5 92% 5 4 92% 7 3 93% 9 2 92% 1 1 92% ... Output:... (7 Replies)
Discussion started by: justthisguy
7 Replies

7. Shell Programming and Scripting

use shell scripts to update tables from databases

Hi I need to write a shell script that will access tables available on webpages and update a table on my webpage on a periodic basis. It will access, say for example a website that periodically update a table with certain quantities and update my table accordingly.it should have the flexibility... (0 Replies)
Discussion started by: wannabegeek
0 Replies

8. UNIX for Dummies Questions & Answers

Need to find a rowcount

Hi All, I have a sequential file, with that I want to know row count within. As know we can use, wc -l filename, to find out a row count. But, I found this command works well , if a file is small. It fails to give me rowcount, if File is pretty big. It keeps on processing after we give the... (3 Replies)
Discussion started by: videsh77
3 Replies

9. UNIX for Dummies Questions & Answers

Unix and databases

I had a person ask me if a Sql database can be run with Unix? I don't know can this be done? They only have Sql dba's and no oracle dba but want to use a Unix box???? (1 Reply)
Discussion started by: tyranunn
1 Replies

10. Post Here to Contact Site Administrators and Moderators

TODO: Sync User Tables Between Databases

Need to eventually sync the MY.UNIX userdata to the forums database (and others). Suggestions on the best approach welcome. (0 Replies)
Discussion started by: Neo
0 Replies
Login or Register to Ask a Question