UPDATE TBDD_BASECONFIG SET DB_VERSION = '1.8.0.1'
GO
ALTER PROCEDURE [dbo].[PRDD_DELETE_USER](@pUSER_ID INT)
AS
BEGIN TRY
	-- COMMON
	IF OBJECT_ID(N'dbo.TBDD_USER_MODULES', N'U') IS NOT NULL 
		DELETE FROM TBDD_USER_MODULES WHERE USER_ID = @pUSER_ID
	IF OBJECT_ID(N'dbo.TBDD_CLIENT_USER', N'U') IS NOT NULL 
		DELETE FROM TBDD_CLIENT_USER WHERE USER_ID = @pUSER_ID
	IF OBJECT_ID(N'dbo.TBDD_GROUPS_USER', N'U') IS NOT NULL 
		DELETE FROM TBDD_GROUPS_USER WHERE USER_ID = @pUSER_ID
	IF OBJECT_ID(N'dbo.TBDD_VERSION_USER_UPDATE', N'U') IS NOT NULL 
		DELETE FROM TBDD_VERSION_USER_UPDATE WHERE USER_ID = @pUSER_ID
	IF OBJECT_ID(N'dbo.TBDD_VERSION_USER_UPDATE_PATH', N'U') IS NOT NULL 
		DELETE FROM TBDD_VERSION_USER_UPDATE_PATH WHERE USER_ID = @pUSER_ID
	IF OBJECT_ID(N'dbo.TBDD_USER_LOGIN_OUT', N'U') IS NOT NULL 
		DELETE FROM TBDD_USER_LOGIN_OUT WHERE USER_ID = @pUSER_ID
	IF OBJECT_ID(N'dbo.TBDD_USER_MODULE_LOG_IN', N'U') IS NOT NULL 
		DELETE FROM TBDD_USER_MODULE_LOG_IN WHERE USER_ID = @pUSER_ID	

	-- PROCESS MANAGER
	IF OBJECT_ID(N'dbo.TBPM_PROFILE_USER', N'U') IS NOT NULL 
		DELETE FROM TBPM_PROFILE_USER WHERE USER_ID = @pUSER_ID
	IF OBJECT_ID(N'dbo.TBPMO_FOLDERWATCH_USER', N'U') IS NOT NULL 
		DELETE FROM TBPMO_FOLDERWATCH_USER WHERE USER_ID = @pUSER_ID

	-- GLOBAL INDEXER
	IF OBJECT_ID(N'dbo.TBGI_FOLDERWATCH_USER', N'U') IS NOT NULL 
		DELETE FROM TBGI_FOLDERWATCH_USER WHERE USER_ID = @pUSER_ID
	IF OBJECT_ID(N'dbo.TBHOTKEY_USER_PROFILE', N'U') IS NOT NULL 
		DELETE FROM TBHOTKEY_USER_PROFILE WHERE USER_ID = @pUSER_ID
	-- CLIPBOARD WATCHER
	IF OBJECT_ID(N'dbo.TBCW_USER_PROFILE', N'U') IS NOT NULL 
		DELETE FROM TBCW_USER_PROFILE WHERE USER_ID = @pUSER_ID

	--_ADDI
	IF OBJECT_ID(N'dbo.TBPMO_CONSTRUCTOR_USER', N'U') IS NOT NULL 
		DELETE FROM TBPMO_CONSTRUCTOR_USER WHERE USER_ID = @pUSER_ID
	IF OBJECT_ID(N'dbo.TBPMO_USER_CONSTR_VIEW_TYPE', N'U') IS NOT NULL 
		DELETE FROM TBPMO_USER_CONSTR_VIEW_TYPE WHERE USER_ID = @pUSER_ID
			
	-- FINALLY
	DELETE FROM TBDD_USER WHERE GUID = @pUSER_ID

	RETURN 0
END TRY
BEGIN CATCH   
	PRINT 'FEHLER IN PROCEDURE: ' + CONVERT(VARCHAR(30),ERROR_PROCEDURE()) + ' - ZEILE: ' + CONVERT(VARCHAR(10),ERROR_LINE())
	+ ' - FEHLER-MESSAGE: ' 
    + CONVERT(VARCHAR(500),ERROR_MESSAGE())
	RETURN -1
END CATCH
GO