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
 SQL Server Development (2000)
 Compare SP

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-08-01 : 08:39:39
Nilesh writes "Dear Sir,
I am analyst Programmer.I am not SQL expert but have sufficient knowledge to make work done.I have come across one problem while transferring projects from development into Testing phase.My problem is :

When I put my project on testing ,I started getting errors like DB objects not found etc ect.Most of the errors are pertaining to SP missing.Could it be possible for you to send me hints (script) which will take server name as input parameter and give me list of missing objects (like SP,views etc).In my case, DB name is remain constant for all the SQL Server (version 7 and 2000) which are located at remote places.
(I have already started writing script using sp_addlinkedserver,sysservers,sysobjects and cursors but till not reaching at final destinaton)

I would be glad if you could help me.

Thanks

Regds.

Nilesh Joshi"

AndrewMurphy
Master Smack Fu Yak Hacker

2916 Posts

Posted - 2002-08-01 : 08:46:13
save yourself the trouble and invest in a copy of s/w from red-gate.com.


It is cheap, available on limited free-trial and works to identify differences in SQL objects....SP, tables, data ,etc and also allows you to synchronise/fix them up.


It has been mentioned several times on this site.

Go to Top of Page

Page47
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2002-08-01 : 09:23:55
Assuming you have the linked servers set up....

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[usp_WhatsTheDiff]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[usp_WhatsTheDiff]
GO

CREATE procedure usp_WhatsTheDiff
@server1 varchar(255),
@server2 varchar(255),
@database varchar(255)
as

declare @sql nvarchar(4000)
declare @server1dotdb varchar(510)
declare @server2dotdb varchar(510)

set @server1dotdb = @server1 + '.' + @database
set @server2dotdb = @server2 + '.' + @database

create table #s1nots2
( objname varchar(255), objtype varchar(255))
create table #s2nots1
( objname varchar(255), objtype varchar(255))
create table #diff
( objname varchar(255), objtype varchar(255))


SELECT @sql =
N'INSERT INTO #s1nots2 (objname, objtype )
select s1.name, s1.xtype
from ' + @server1dotdb + '.dbo.sysobjects s1 left join ' + @server2dotdb + '.dbo.sysobjects s2
on s1.name = s2.name
where s1.xtype in (''P'',''TF'',''FN'',''TR'',''U'',''V'') and s2.id is null and s1.name not like ''dt_%'''
EXEC sp_executesql @sql

SELECT @sql =
N'INSERT INTO #s2nots1 (objname, objtype )
select s1.name, s1.xtype
from ' + @server2dotdb + '.dbo.sysobjects s1 left join ' + @server1dotdb + '.dbo.sysobjects s2
on s1.name = s2.name
where s1.xtype in (''P'',''TF'',''FN'',''TR'',''U'',''V'') and s2.id is null and s1.name not like ''dt_%'''
EXEC sp_executesql @sql


SELECT @sql =
N'INSERT INTO #diff (objname, objtype )
select distinct so1.name, so1.xtype
from ' + @server1dotdb + '.dbo.sysobjects so1 inner join ' + @server1dotdb + '.dbo.syscomments sc1 on so1.id = sc1.id
where so1.xtype in (''P'',''TF'',''FN'',''TR'',''U'',''V'') and exists (
select 1
from ' + @server2dotdb + '.dbo.sysobjects so2 inner join ' + @server2dotdb + '.dbo.syscomments sc2 on so2.id = sc2.id
where so1.name = so2.name and sc1.colid = sc2.colid and sc1.text <> sc2.text)
and so1.name not like ''dt_%''
option (ROBUST PLAN) '
EXEC sp_executesql @sql

SELECT objname 'Object Name',
case objtype when 'P' then 'Procedure'
when 'TF' then 'Function'
when 'FN' then 'Function'
when 'TR' then 'Trigger'
when 'U' then 'Table'
when 'V' then 'View'
else '?Error?'
end as 'Object Type',
'Missing in ' + @server2 as 'Status'
from #s1nots2
union
SELECT objname 'Object Name',
case objtype when 'P' then 'Procedure'
when 'TF' then 'Function'
when 'FN' then 'Function'
when 'TR' then 'Trigger'
when 'U' then 'Table'
when 'V' then 'View'
else '?Error?'
end as 'Object Type',
'Missing in ' + @server1 as 'Status'
from #s2nots1
union
SELECT objname 'Object Name',
case objtype when 'P' then 'Procedure'
when 'TF' then 'Function'
when 'FN' then 'Function'
when 'TR' then 'Trigger'
when 'U' then 'Table'
when 'V' then 'View'
else '?Error?'
end as 'Object Type',
'Dirty' as 'Status'
from #diff
order by 'Status', 'Object Type', 'Object Name'


drop table #s1nots2
drop table #s2nots1
drop table #diff

GO

 


Jay White
{0}
Go to Top of Page
   

- Advertisement -