SQL code for comparing different database tables (including fields)

Source: Internet
Author: User

Use accdb1 -- the old ZY database and accdb are the standard LCD library. It is known that the accdb database has more tables and fields than the accdb1 database, and the more tables and fields are obtained.

Select accdb. table_name as accdb_table_name,
Accdb. columns_name as accdb_columns_name,
Accdb1.table _ name as accdb1_table_name,
Accdb1.columns _ name as accdb1_columns_name
From (select accdb. DBO. sysobjects. Name as table_name,
Accdb. DBO. syscolumns. Name as columns_name
From accdb. DBO. syscolumns inner join
Accdb. DBO. sysobjects on
Accdb. DBO. syscolumns. ID = accdb. DBO. sysobjects. ID
Where (not (accdb. DBO. syscolumns. name like '@ %') and
(Accdb. DBO. sysobjects. xtype = 'U') accdb left Outer Join
(Select sysobjects. Name as table_name,
Syscolumns. Name as columns_name
From syscolumns inner join
Sysobjects on syscolumns. ID = sysobjects. ID
Where (not (syscolumns. name like '@ %') and (sysobjects. xtype = 'U '))
Accdb1 on accdb. columns_name = accdb1.columns _ name and
Accdb. table_name = accdb1.table _ name
Where (accdb1.table _ name is null) or
(Accdb1.columns _ name is null) order by accdb. table_name, accdb. columns_name

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.