Home Microsoft SQL Server DigiMailing iRN Contact
    Keyword



sys.sp_MSdropdynsnapshotvws

  No additional text.


Syntax
create procedure sys.sp_MSdropdynsnapshotvws (
    @dynamic_snapshot_views_table sysname
    )
as
begin
    set nocount on
    declare @retcode int
    declare @final_retcode int
    declare @select_command nvarchar(4000)
    declare @old_dynamic_snapshot_view_name sysname
    declare @dynamic_snapshot_view_name sysname
    declare @drop_view_command nvarchar(4000)
    declare @select_param_list nvarchar(4000)

    select @final_retcode = 0
    select @retcode = 0
    -- Security check
    exec @retcode = sys.sp_MSreplcheck_publish
    if @@error<>0 or @retcode<>0
    begin
        return 1
    end

    -- For the first fecth, don't do comparison with the old view name...
    select @dynamic_snapshot_view_name  = null
    select @select_command = N'
        select @dynamic_snapshot_view_name = min(dynamic_snapshot_view_name)
          from ' + quotename(@dynamic_snapshot_views_table)

    select @select_param_list =
        N'@dynamic_snapshot_view_name sysname output'

    exec @retcode = sys.sp_executesql @select_command,
        @select_param_list,
        @dynamic_snapshot_view_name = @dynamic_snapshot_view_name output
    if @@error<>0 or @retcode<>0
    begin
        select @final_retcode = 1
    end

    -- Change query to do comparison with the old name
    select @select_command = N'
        select @dynamic_snapshot_view_name = min(dynamic_snapshot_view_name)
          from ' + quotename(@dynamic_snapshot_views_table) + N'
         where dynamic_snapshot_view_name > @old_dynamic_snapshot_view_name'

    select @select_param_list =
        N'@dynamic_snapshot_view_name sysname output,
          @old_dynamic_snapshot_view_name sysname'

    -- Keep selecting view with the smallest name that
    -- is greater than the last one until we are done
    while @dynamic_snapshot_view_name is not null
    begin

        select @drop_view_command = N'drop view ' +
            quotename(@dynamic_snapshot_view_name)
        exec(@drop_view_command)
        if @@error<>0
        begin
            select @final_retcode = 1
        end

        -- Drop the temporary function created for the dynamic snapshot view
        select @drop_view_command = 'drop function dbo.' +
                quotename(@dynamic_snapshot_view_name + '_FN')
        exec(@drop_view_command)
        if @@error<>0
        begin
            select @retcode = 1
        end

        delete MSdynamicsnapshotviews
         where dynamic_snapshot_view_name = @dynamic_snapshot_view_name
        if @@error<>0
        begin
            select @final_retcode = 1
        end

        select @old_dynamic_snapshot_view_name = @dynamic_snapshot_view_name
        select @dynamic_snapshot_view_name = null
        exec @retcode = sys.sp_executesql @select_command,
            @select_param_list,
            @dynamic_snapshot_view_name = @dynamic_snapshot_view_name output,
            @old_dynamic_snapshot_view_name = @old_dynamic_snapshot_view_name

        if @@error<>0 or @retcode<>0
        begin
            select @final_retcode = 1
        end
    end
    -- At the end, we need to drop the temp table
    declare @drop_table_command nvarchar(4000)
    select @drop_table_command = N'drop table ' + quotename(@dynamic_snapshot_views_table)
    exec(@drop_table_command)
    if @@error<>0
    begin
        select @final_retcode = 1
    end
    return @final_retcode
end

 
Last revision 2008RTM
See also

  sp_MSdrop_rlrecon (Procedure)
       



News

  Query a named instance
Sybase+ASE+silent+install
SQL 2008 R2
Deprecated procedures in SQL2008
Reporting Services item-level role definitions
Create all your missing indexes
Converting datetime field
Start MSSQL Server Profiler at time
Replicating MSSQL Server views
Exploring Microsoft Sharepoint
The OLE DB provider "SQLNCLI10" for linked server indicates.
Mobile solar charger
Oracle to SQL Server replication
Cannot insert the value NULL into column
Undocumented Microsoft SQL Server 2008
VMware
Zoekmachine optimalisatie
SQL Servers hidden objects
FckEditor
Flash in Ajax
De hype die AJAX heet
Barcode scannen
MySQL; Gratis, makkelijk en snel!
PHP
sIFR; de combinatie tussen HTML en Flash