Disable sp_refreshview
brigzy
Posts: 14
Hi
I am having trouble as sp_referesh view is included in the script generated by SQLCompare command line.
When running the script on the destination server\database, the script errors as the view refferes to a 'another' database that is not on the destination server.
The generated script is creating an sp_refresh for every view in the database? which is odd as there are only 4 ddl changes (one SP, three table structure changes).
Can I disable the sp_refreshview behaviour?
Attched is generated SQL script
I am having trouble as sp_referesh view is included in the script generated by SQLCompare command line.
When running the script on the destination server\database, the script errors as the view refferes to a 'another' database that is not on the destination server.
The generated script is creating an sp_refresh for every view in the database? which is odd as there are only 4 ddl changes (one SP, three table structure changes).
Can I disable the sp_refreshview behaviour?
Attched is generated SQL script
/* Run this script on: Partner-Dev.partner_chall - This database will be modified to synchronize it with: Partner-Dev.rdb_partner_chall You are recommended to back up your database before running this script Script created by SQL Compare version 8.1.0 from Red Gate Software Ltd at 24/09/2009 13:31:07 */ SET NUMERIC_ROUNDABORT OFF GO SET ANSI_PADDING, ANSI_WARNINGS, CONCAT_NULL_YIELDS_NULL, ARITHABORT, QUOTED_IDENTIFIER, ANSI_NULLS ON GO IF EXISTS (SELECT * FROM tempdb..sysobjects WHERE id=OBJECT_ID('tempdb..#tmpErrors')) DROP TABLE #tmpErrors GO CREATE TABLE #tmpErrors (Error int) GO SET XACT_ABORT ON GO SET TRANSACTION ISOLATION LEVEL SERIALIZABLE GO BEGIN TRANSACTION GO PRINT N'Refreshing [dbo].[Isokon_Tfb_Transactions]' GO EXEC sp_refreshview N'[dbo].[Isokon_Tfb_Transactions]' GO IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION GO IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END GO PRINT N'Altering [dbo].[up_Net2Matter_SetRecent_MatterContactAgenda]' GO SET QUOTED_IDENTIFIER OFF GO ALTER PROCEDURE [dbo].[up_Net2Matter_SetRecent_MatterContactAgenda] (@EntityRef varChar(15), @MatterNo int, @ContactRef VarChar(15), @AgendaID int, @UserID VarChar(20)) AS BEGIN -- Create results table DECLARE @Result TABLE(EntityRef varChar(15), MatterNo int, ContactRef varChar(15), AgendaID int, NewOrder int) -- Gather results INSERT INTO @Result SELECT TOP 30 EntityRef, MatterNo, Contact, AgendaID, ROW_NUMBER() OVER (order by orderinlist) -1 as RowNumber FROM recentmatters WHERE usercode = @UserID AND NOT (EntityRef = @EntityRef AND MatterNo =@MatterNo) -- Add our new most recent row, this entity, this matterno, this AgendaID UNION SELECT @EntityRef, @MatterNo, @ContactRef, @AgendaID, -1 ORDER BY RowNumber -- Set new orders UPDATE @Result SET NewOrder = NewOrder +1 DELETE recentmatters WHERE UserCode = @UserID INSERT INTO recentmatters (UserCode, EntityRef, MatterNo, Contact, AgendaID, OrderInList) SELECT @UserID, EntityRef, MatterNo, ContactRef, AgendaID, NewOrder FROM @Result END GO IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION GO IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END GO PRINT N'Altering [dbo].[Usr_CreditCheck]' GO ALTER TABLE [dbo].[Usr_CreditCheck] ADD [ResultsEntityRef] [varchar] (15) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, [ResultsStepID] [int] NULL GO IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION GO IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END GO PRINT N'Refreshing [dbo].[Chart_Of_Accounts_GroupView]' GO EXEC sp_refreshview N'[dbo].[Chart_Of_Accounts_GroupView]' GO IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION GO IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END GO PRINT N'Refreshing [dbo].[StepPostInDirect]' GO EXEC sp_refreshview N'[dbo].[StepPostInDirect]' GO IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION GO IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END GO PRINT N'Refreshing [dbo].[vw_ClientBills]' GO EXEC sp_refreshview N'[dbo].[vw_ClientBills]' GO IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION GO IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END GO PRINT N'Refreshing [dbo].[vw_ClientBills_ShortSummary]' GO EXEC sp_refreshview N'[dbo].[vw_ClientBills_ShortSummary]' GO IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION GO IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END GO PRINT N'Refreshing [dbo].[ViewTaskList]' GO EXEC sp_refreshview N'[dbo].[ViewTaskList]' GO IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION GO IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END GO PRINT N'Refreshing [dbo].[Dm_TimePostings]' GO EXEC sp_refreshview N'[dbo].[Dm_TimePostings]' GO IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION GO IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END GO PRINT N'Refreshing [dbo].[FM_fFiles]' GO EXEC sp_refreshview N'[dbo].[FM_fFiles]' GO IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION GO IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END GO PRINT N'Refreshing [dbo].[Chall_View_DisbsOUT]' GO EXEC sp_refreshview N'[dbo].[Chall_View_DisbsOUT]' GO IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION GO IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END GO PRINT N'Refreshing [dbo].[F_OrgTypeLnk]' GO EXEC sp_refreshview N'[dbo].[F_OrgTypeLnk]' GO IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION GO IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END GO PRINT N'Refreshing [dbo].[PBC_fWorkTypes]' GO EXEC sp_refreshview N'[dbo].[PBC_fWorkTypes]' GO IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION GO IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END GO PRINT N'Refreshing [dbo].[Chall_View_DisbsIN_Sept2008]' GO EXEC sp_refreshview N'[dbo].[Chall_View_DisbsIN_Sept2008]' GO IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION GO IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END GO PRINT N'Refreshing [dbo].[Chall_View_DisbsOUT_Sept08]' GO EXEC sp_refreshview N'[dbo].[Chall_View_DisbsOUT_Sept08]' GO IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION GO IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END GO PRINT N'Refreshing [dbo].[Chall_IncomeVsTargets]' GO EXEC sp_refreshview N'[dbo].[Chall_IncomeVsTargets]' GO IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION GO IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END GO PRINT N'Refreshing [dbo].[vw_LeverArchLabels]' GO EXEC sp_refreshview N'[dbo].[vw_LeverArchLabels]' GO IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION GO IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END GO PRINT N'Refreshing [dbo].[AllMatters]' GO EXEC sp_refreshview N'[dbo].[AllMatters]' GO IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION GO IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END GO PRINT N'Refreshing [dbo].[MARFEE]' GO EXEC sp_refreshview N'[dbo].[MARFEE]' GO IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION GO IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END GO PRINT N'Refreshing [dbo].[Corebridge_Directory]' GO EXEC sp_refreshview N'[dbo].[Corebridge_Directory]' GO IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION GO IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END GO PRINT N'Refreshing [dbo].[AcPLAgCrMatterAlloc]' GO EXEC sp_refreshview N'[dbo].[AcPLAgCrMatterAlloc]' GO IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION GO IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END GO PRINT N'Refreshing [dbo].[Ac_CashAccountTransactions]' GO EXEC sp_refreshview N'[dbo].[Ac_CashAccountTransactions]' GO IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION GO IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END GO PRINT N'Refreshing [dbo].[vw_CaseSteps]' GO EXEC sp_refreshview N'[dbo].[vw_CaseSteps]' GO IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION GO IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END GO PRINT N'Refreshing [dbo].[VIEW_LGFS_DATA]' GO EXEC sp_refreshview N'[dbo].[VIEW_LGFS_DATA]' GO IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION GO IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END GO PRINT N'Refreshing [dbo].[StepTime]' GO EXEC sp_refreshview N'[dbo].[StepTime]' GO IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION GO IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END GO PRINT N'Refreshing [dbo].[StepPostDirect]' GO EXEC sp_refreshview N'[dbo].[StepPostDirect]' GO IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION GO IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END GO PRINT N'Refreshing [dbo].[Chall_View_DisbsIN]' GO EXEC sp_refreshview N'[dbo].[Chall_View_DisbsIN]' GO IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION GO IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END GO PRINT N'Refreshing [dbo].[F_Organisations]' GO EXEC sp_refreshview N'[dbo].[F_Organisations]' GO IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION GO IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END GO PRINT N'Refreshing [dbo].[F_OrganisationsMatter]' GO EXEC sp_refreshview N'[dbo].[F_OrganisationsMatter]' GO IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION GO IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END GO PRINT N'Refreshing [dbo].[PBC_fClients]' GO EXEC sp_refreshview N'[dbo].[PBC_fClients]' GO IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION GO IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END GO PRINT N'Refreshing [dbo].[CDSDataView]' GO EXEC sp_refreshview N'[dbo].[CDSDataView]' GO IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION GO IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END GO PRINT N'Refreshing [dbo].[VIEW_CLAIMSTOAPPROVE]' GO EXEC sp_refreshview N'[dbo].[VIEW_CLAIMSTOAPPROVE]' GO IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION GO IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END GO PRINT N'Refreshing [dbo].[AcPLAgCrNominalAlloc]' GO EXEC sp_refreshview N'[dbo].[AcPLAgCrNominalAlloc]' GO IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION GO IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END GO PRINT N'Altering [dbo].[Usr_IDCheck]' GO ALTER TABLE [dbo].[Usr_IDCheck] ADD [ResultsEntityRef] [varchar] (15) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, [ResultsStepID] [int] NULL GO IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION GO IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END GO ALTER TABLE [dbo].[Usr_IDCheck] DROP COLUMN [PDFStepID] GO IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION GO IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END GO PRINT N'Altering [dbo].[Usr_Trace_Check]' GO ALTER TABLE [dbo].[Usr_Trace_Check] ADD [ResultsEntityRef] [varchar] (15) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, [ResultsStepID] [int] NULL GO IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION GO IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END GO SET QUOTED_IDENTIFIER ON GO IF EXISTS (SELECT * FROM #tmpErrors) ROLLBACK TRANSACTION GO IF @@TRANCOUNT>0 BEGIN PRINT 'The database update succeeded' COMMIT TRANSACTION END ELSE PRINT 'The database update failed' GO DROP TABLE #tmpErrors GO
Richard
Comments
The extra view refreshes are a known issue (SC-4542) which we'll hopefully get fixed soon.
Redgate Software
Ok thankyou, I am trying the /pr switch
The GUI project finds differences ok.
When using /pr switch however I receive message :
Error: The selected objects are identical or no objects have been selected in the comparison.
Here is the project contents:
and here is my command line
Hi Michelle
can I ask if the above /pr is a known issue?
Is there a previous (older vserion) of SQLCompare, perhaps without the issue I could use meanwhile?
Many thanks
So I am over that hurdle and now the script is created just fine.
Indeed the /pr aproach has removed all the unwanted sp_refreshview statements from the scripts.
Please could be logged as an enhancement request?
I think this behaviour is improved in our latest Frequent Updates release (11.1.7.47) - Compare should now refresh views less often; it will no longer refresh views unrelated to the deployment and will refresh no views if the 'Include Dependencies' option is disabled