Home Microsoft SQL Server DigiMailing iRN Contact
    Keyword



sys.sp_cdc_drop_objects

  No additional text.


Syntax
create procedure sys.sp_cdc_drop_objects
as
begin
	declare @object_name sysname
		,@object_type char(2)
		,@stmt nvarchar(max)
		,@role sysname
		,@member sysname
	
	declare #hobjects cursor local fast_forward for
		select o.name, o.type
		from  sys.objects o
		where schema_name(o.schema_id) = 'cdc'
		order by o.type
	
	declare #members cursor local fast_forward for	
		select p.name, r.name from sys.database_principals  p
			inner join sys.database_role_members m
				on p.principal_id = m.member_principal_id
			inner join sys.database_principals r
				on r.principal_id = m.role_principal_id
			inner join sys.database_principals c
				on r.owning_principal_id = c.principal_id
		where r.type = 'R'
		and c.name = 'cdc'
		and c.type = 'S'
	
	declare #roles cursor local fast_forward for	
		select r.name from sys.database_principals r
			inner join sys.database_principals c
				on r.owning_principal_id = c.principal_id
		where r.type = 'R'
		and c.name = 'cdc'
		and c.type = 'S' 	
		set nocount on
	
    -- Drop the functions and stored procedures in the cdc schema
	open #hobjects
	fetch #hobjects into @object_name, @object_type
	
	while (@@fetch_status <> -1)
	begin
		if (@object_type = 'U')
		begin
			set @stmt = N'drop table [cdc].' + quotename(@object_name)
			exec (@stmt)
		end
		
		else if (@object_type = 'FN') or (@object_type = 'FS') or (@object_type = 'IF')
		begin
			set @stmt = N'drop function [cdc].' + quotename(@object_name)
			exec (@stmt)
		end
		
		else if (@object_type = 'P')
		begin
			set @stmt = N'drop procedure [cdc].' + quotename(@object_name)
			exec (@stmt)
		end
		
		else if (@object_type = 'AF')
		begin
			set @stmt = N'drop aggregate [cdc].' + quotename(@object_name)
			exec (@stmt)
		end

		fetch #hobjects into @object_name, @object_type
	end
	
	close #hobjects
	deallocate #hobjects
	
	-- Drop all members of roles owned by the cdc user
	open #members
	fetch #members into @member, @role
	
	while (@@fetch_status <> -1)
	begin
		exec sp_droprolemember @role , @member
		fetch #members into @member, @role
	end
	
	close #members
	deallocate #members
	
	-- Drop all roles owned by the cdc user
	open #roles
	fetch #roles into @role
	
	while (@@fetch_status <> -1)
	begin
		set @stmt = N'drop role ' + quotename(@role)
		exec (@stmt)
		fetch #roles into @role
	end
	
	close #roles
	deallocate #roles
	
	-- Drop the database schema and user if they exist
	if schema_id ('cdc') is not null
	begin	
		drop schema cdc
	end
	
    return 0
end

 
Last revision 2008RTM
See also

  sp_cdc_disable_db_internal (Procedure)
sp_MSdrop_cdc (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