Use SQL to compare whether the two databases are consistent

Source: Internet
Author: User

To compare two databases, you can use tools, such as toad, or write a stored procedure yourself. I will introduce an SQL statement to check whether the table structure is consistent, and so on, you can write an SQL statement that compares the consistency of indexes and the consistency of constraints. The disadvantage of this SQL statement is that it can only identify the differences, but it is caused by the table:

Select case when a. cnt = B. cnt then 'two database structures are consistent'
When a. cnt <> B. cnt then 'inconsistent database structures 'end
From (select count (*) as cnt
From dba_tab_columns t1, dba_tab_colums @ lnk_db2 t2
Where t1.owner = 'taobao'
And t1.owner = t2.owner
And t1.table _ name = t2.table _ name
And t1.column _ name = t2.column _ name
And t1.data _ type = t2.data _ type
And t1.data _ length = t2.data _ length
And t1.nullable = t2.nullable
And nvl (t1.data _ precision, 0) = nvl (t2.data _ precision, 0)
And nvl (t1.data _ scale, 0) = nvl (t2.data _ scale, 0),
(Select count (*) as cnt
From dba_tab_columns
Where owner = 'taobao') B

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.