C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Forums » .NET » SQL Server »

Databases


Posted Date: 22 Nov 2008      Posted By: shaik mohiuddin      Member Level: Gold     Points: 1   Responses: 3



Dear Friends
iwanna the solution for this program
that will compare the table structure of two different databases and generate a report that will list the differences.


Thnx in Advance





Responses

Author: Rajesh Ranjan    25 Nov 2008Member Level: GoldRating: 2 out of 52 out of 5     Points: 2

Hi,

Can you tell me what type of difference you want to get.


Regds
Rajesh Ranjan



Author: Rajesh Ranjan    25 Nov 2008Member Level: GoldRating: 2 out of 52 out of 5     Points: 6

Hi Freind,

Try bellow query

-----------If both database is in same Server then try this query

select d1.name,d2.name from database1.dbo.syscolumns,database2.dbo.syscolumns where d1.name<>d2.name and d1.id=object_id('Table1') and d2.id=(select id from database2.dbo.sysobjects where name='Table1'
-------If databases are on different Server
sp_addlinkedserver [Server ip]
select d1.name,d2.name from database1.dbo.syscolumns,[server ip].database2.dbo.syscolumns where d1.name<>d2.name and d1.id=object_id('Table1') and d2.id=(select id from [server ip].database2.dbo.sysobjects where name='Table1')

It will return you difference between the name of columns in both tables

WIth the same query you can find out Difference between datatype and length

Regds
Rajesh Ranjan



Author: kiran    27 Nov 2008Member Level: SilverRating: 2 out of 52 out of 5     Points: 5

To return all rows in table1 that do not match exactly the rows in table2, we can just use EXCEPT like this:


select * from table1 except select * from table2


To return all rows in table2 that do not match exactly in table1, we reverse the EXCEPT:


select * from table2 except select * from table1


And to return all rows in table1 that match exactly what is in table2, we can use INTERSECT:


select * from table1 intersect select * from table2



Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.


Next : Find Last Modified Row In Sql TAble
Previous : SQL Select Querry
Return to Discussion Forum
Post New Message
Category: SQL Server

Related Messages



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use