Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Comparison script

Author  Topic 

elwoos
Master Smack Fu Yak Hacker

2052 Posts

Posted - 2003-12-03 : 04:47:55
Does anyone have a script that will check the same fields exist in two views (with the same name) in two seperate servers.

I have a testing server and a live server and I want to make sure that there are no 'unexpected' changes on one of them and so I am trying to check a number of things including that all of the fields still exist in both. I know about SQL compare but that gives so much information that we were swamped. I only need something relatively simple

thanks

steve


Steve no function beer well without

TimChenAllen
Starting Member

45 Posts

Posted - 2003-12-03 : 05:19:35
Would this work for you?
declare @view_name sysname;
set @view_name='vwTest';
select name [in local, not remote] from syscolumns
where id = (select id from sysobjects where name = @view_name)
and name not in (
select name from REMOTESERVER.REMOTE_DB.dbo.syscolumns
where id = (select id from sysobjects where name = @view_name)
)

select name [in remote, not local] from REMOTESERVER.REMOTE_DB.dbo.syscolumns
where id = (select id from sysobjects where name = @view_name)
and name not in (select name from syscolumns
where id = (select id from sysobjects where name = @view_name)
)

Keep in mind that the two servers have to be linked for this to work. You can do this from Enterprise Manager->Security->Linked Servers or with the SP sp_addlinkedserver.
Go to Top of Page

mohdowais
Sheikh of Yak Knowledge

1456 Posts

Posted - 2003-12-03 : 07:37:28
Straight out of my toolbox:

--This script will compare the columns of all tables and views
--in the two databases. Returns all columns found in only one database
--or columns with a different datatype or datatype max length
select table_name, column_name, data_type,
character_maximum_length, min(table_catalog) AS DB
from
(
select table_catalog, table_name, column_name, data_type, character_maximum_length
from db1.information_schema.columns

union all

select table_catalog, table_name, column_name, data_type, character_maximum_length
from db2.information_schema.columns
)b

group by table_name, column_name, data_type, character_maximum_length having count(*) = 1

Note: this is designed to compare two databases on the same server, but using linked servers and four-part naming syntax, you could use it to compare databases across servers as well.

Owais


Please excuse my driving, I am reloading.
Go to Top of Page

TimChenAllen
Starting Member

45 Posts

Posted - 2003-12-03 : 10:41:39
quote:
Originally posted by mohdowais

Straight out of my toolbox:


That is very cool. I originally wanted to use the INFORMATION_SCHEMA tables but did not know the syntax to refer to them on another server. Thanks.

--
TimothyAllen
[url]http://www.timallen.org[/url]
Go to Top of Page

elwoos
Master Smack Fu Yak Hacker

2052 Posts

Posted - 2003-12-04 : 03:43:25
Thanks to both of you for the replies, I'll give them a try

steve

Steve no function beer well without
Go to Top of Page
   

- Advertisement -