
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE [dbo].[p_doc_collections_delete_by_table_id]
	@table_id type_table_id READONLY
AS

	/*
	DGE

	Suppression d'une collection de documents, par table_id.

	*/

	-- suppression des documents
	DELETE  v 
	from	dbo.vw__obj_objects_insert v
			INNER JOIN dbo.doc_collections_docs dcd ON v.obj_object_id = dcd.dcd_object_id
			inner join @table_id t ON t.id = dcd.dcd_collection_id

	delete	a
	from	doc_collections_docs_accounts a
			inner join doc_collections_docs d on d.dcd_document_id = a.dcda_document_id
			inner join @table_id t ON t.id = d.dcd_collection_id

	-- suppression des détails
	DELETE	d
	from	dbo.doc_collections_docs d
			inner join @table_id t ON t.id = d.dcd_collection_id

	-- suppression de la collection
	DELETE	d
	FROM	dbo.doc_collections d
			INNER JOIN @table_id t ON t.id = d.dc_collection_id


GO
