UPDATE TBDD_MODULES SET PRODUCT_VERSION = '2.4.5.0' where NAME = 'Record-Organizer' 
GO

CREATE TABLE TBPMO_WD_NAMECONVENTION_FORMAT
(
	GUID			INTEGER			NOT NULL	IDENTITY(1,1),
	ID 				INTEGER			NOT NULL,
	PATTERN			VARCHAR(50)		NOT NULL,
	FORMAT_RULE		VARCHAR(100)    NOT NULL,
	ADDED_WHO		VARCHAR(50)		DEFAULT 'DEFAULT',
	ADDED_WHEN		DATETIME 		DEFAULT GETDATE(),
	CHANGED_WHO     VARCHAR(50),
	CHANGED_WHEN	DATETIME,
	CONSTRAINT		PK_TBPMO_WD_NAMECONVENTION_FORMAT				PRIMARY KEY (GUID)
)
GO
CREATE TRIGGER TBPMO_WD_NAMECONVENTION_FORMAT_UPD ON TBPMO_WD_NAMECONVENTION_FORMAT
FOR UPDATE
AS
	UPDATE TBPMO_WD_NAMECONVENTION_FORMAT SET CHANGED_WHEN = GETDATE() FROM INSERTED WHERE TBPMO_WD_NAMECONVENTION_FORMAT.GUID = INSERTED.GUID
GO
ALTER PROCEDURE [dbo].[PRPMO_DELETE_DOCTYPE](@pDOCID INT)
AS
BEGIN TRY
	DELETE FROM TBPMO_WD_NAMECONVENTION_FORMAT WHERE ID IN (SELECT GUID FROM TBPMO_WD_FORMVIEW_DOKTYPES WHERE DOCTYPE_ID = @pDOCID)
	DELETE FROM TBPMO_WD_FORMVIEW_DOKTYPES WHERE DOCTYPE_ID = @pDOCID
	DELETE FROM TBDD_INDEX_MAN WHERE DOK_ID = @pDOCID
	DELETE FROM TBDD_INDEX_AUTOM WHERE DOCTYPE_ID = @pDOCID
	DELETE FROM TBDD_USRGRP_DOKTYPE WHERE DOCTYPE_ID = @pDOCID
	DELETE FROM TBPMO_CLIENT_DOCTYPE WHERE DOCTYPE_ID = @pDOCID
	DELETE FROM TBPMO_TEMPLATE WHERE DOCTYPE_ID = @pDOCID
	DELETE FROM TBDD_DOKUMENTART WHERE GUID = @pDOCID
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())
END CATCH
GO