J'ai cette procédure stockée qui provoque régulièrement des locks dans SQL Server au…
- User
J'ai cette procédure stockée qui provoque régulièrement des locks dans SQL Server au niveau du truncate table v_refvalues. Quel peut être le problème? USE [Semarchy_MDM_PROD] GO
/****** Object: StoredProcedure [dbo].[USR_MOD_UpdateWhenRequiredV_RefValues] Script Date: 28.04.2023 08:45:15 ******/ SET ANSI_NULLS ON GO
SET QUOTED_IDENTIFIER ON GO
CREATE procedure [dbo].[USR_MOD_UpdateWhenRequiredV_RefValues] as begin if not exists(select 1 from GD_META_UPDATED_ENTITY) begin return end -- ############################################################################ ------------------------------------------------------------------------ -- Cette table contiendra les listes dynamiques par default par category -- --------------------------------------------------------------------- drop table if exists ##DefaultRefInheritance create table ##DefaultRefInheritance ( id int identity (1,1), category_id int, property_id int, process_id int )
-- ---------------------------------------------------------------------------- -- build local tmp tables from GD tables : build ##Coating table -- ---------------------------------------------------------------------------- drop table if exists ##Coating select cast(coating.F_MATER_AP as int) as material_id, cast(process.CODE as int) as process_id, coating.F_COLOR_AP as color_code, hardness.DEFAULT_LABEL as hardness, thickness.DEFAULT_LABEL as thickness, cast(family.CODE as int) as material_family_id into ##Coating from GD_COATING coating left join GD_LOV_VALUE process on process.PK = coating.F_PROCESS left join GD_LOV_VALUE family on family.PK = coating.F_MATER_FAMILY left join GD_LOV_VALUE hardness on hardness.PK = coating.F_HARDNESS left join GD_LOV_VALUE thickness on thickness.PK = coating.F_COATING_THICKNESS -- select from ##Coating -- ---------------------------------------------------------------------------- -- build local tmp tables from GD tables : build ##RefCoatingLink table () 445 en prod Vs 875 -> KO -- ---------------------------------------------------------------------------- drop table if exists ##RefCoatingLink select cast(coatingprocess.CODE as int) as process_id, cast(process_lk.F_MOD_CATEGORY as int) as category_id, cast(process_lk.F_MOD_PROCESS_INHERITANCE as int) as inheritance_group_id, cast(process_lk.F_MOD_CATEGORY_TYPE as int) as category_type_id, CASE when process_lk.METSTATUS = 'CONS' then N'En Travail' when process_lk.METSTATUS = 'PROD' then N'Valide' when process_lk.METSTATUS = 'ARCH' then N'Archive' when process_lk.METSTATUS = 'OBSO' then N'Obsolète' else N'Valide' end as status into ##RefCoatingLink from GD_MOD_PROCESS_LK process_lk left join GD_LOV_VALUE coatingprocess on coatingprocess.PK = process_lk.F_MOD_COATING_PROCESS -- select * from ##RefCoatingLink order by category_id, process_id -- ---------------------------------------------------------------------------- -- build local tmp tables from GD tables : build ##Category table 139 en prod Vs 160 -> OK -- ---------------------------------------------------------------------------- drop table if exists ##Category select cast(CODE as int) as id, cast(F_MOD_CATEGORY_TYPE as int) as type_id, LABEL as name into ##Category from GD_MOD_CATEGORY --select * from ##Category -- ---------------------------------------------------------------------------- -- build local tmp tables from GD tables : build ##GenericMaterial table en prod 86 Vs 166 -> KO -- ---------------------------------------------------------------------------- drop table if exists ##GenericMaterial select cast(generic.CODE as int) as id, generic.DEFAULT_LABEL as name, cast(Family.CODE as int) as material_family_id into ##GenericMaterial from GD_LOV_VALUE generic left join GD_LOV_VALUE family on family.PK = generic.F_PARENT where generic.F_LOV_LIST = 'MaterGeneric' --select * from ##GenericMaterial -- ---------------------------------------------------------------------------- -- build local tmp tables from GD tables : build ##Material table en prod 321 Vs 495 -> KO -- ---------------------------------------------------------------------------- drop table if exists ##Material select cast(mater.CODE as int) as id, cast(generic.CODE as int) as generic_material_id, mater.LABEL as name, composition.DEFAULT_LABEL as composition, case when mater.METSTATUS = 'CONS' then N'En Travail' when mater.METSTATUS = 'PROD' then N'Valide' when mater.METSTATUS = 'ARCH' then N'Archive' when mater.METSTATUS = 'OBSO' then N'Obsolète' else N'Valide' end as status into ##Material from GD_MATER_AP mater left join GD_LOV_VALUE composition on composition.PK = mater.F_MATER_COMPOSITION left join GD_LOV_VALUE generic on generic.PK = mater.F_MATER_GENERIC --select * from ##Material -- ---------------------------------------------------------------------------- -- build local tmp tables from GD tables : build ##RefMaterialLink table en prod 2124 Vs 2986 -> OK -- ---------------------------------------------------------------------------- drop table if exists ##RefMaterialLink select distinct cast(mater_lk.F_MATER_AP as int) as material_id, cast(mater_lk.F_CATEGORY as int) as category_id, cast(mater_lk.F_MATER_INHERITANCE as int) as inheritance_group_id into ##RefMaterialLink from GD_MOD_MATER_LK mater_lk --select * from ##RefMaterialLink -- ---------------------------------------------------------------------------- -- build local tmp tables from GD tables : build ##MaterialFamily table en prod 17 Vs 25 -> OK -- ---------------------------------------------------------------------------- drop table if exists ##MaterialFamily select cast(family.CODE as int) as id, family.DEFAULT_LABEL as name into ##MaterialFamily from GD_LOV_VALUE family where family.F_LOV_LIST = 'MaterFamily' --select * from ##MaterialFamily -- ---------------------------------------------------------------------------- -- build local tmp tables from GD tables : build ##Property table en prod 644 Vs 715 -> OK -- ---------------------------------------------------------------------------- drop table if exists ##Property select cast(Property.CODE as int) as id, Property.LABEL as name into ##Property from GD_MOD_PROPERTY Property --select * from ##Property -- ---------------------------------------------------------------------------- -- build local tmp tables from GD tables : build ##CategoryPropertyLink table en prod 6226 Vs 6307 -> OK -- ---------------------------------------------------------------------------- drop table if exists ##CategoryPropertyLink select cast(categoryproperty_lk.CODE as int) as id, cast(categoryproperty_lk.F_MOD_PROPERTY as int) as property_id, cast(categoryproperty_lk.F_MOD_CATEGORY as int) as category_id into ##CategoryPropertyLink from GD_MOD_CATEGORY_PROPERTY_LK categoryproperty_lk --select * from ##CategoryPropertyLink -- ---------------------------------------------------------------------------- -- build local tmp tables from GD tables : build ##Color table en prod 1485 Vs 1825 -> OK -- ---------------------------------------------------------------------------- drop table if exists ##Color select distinct color.CODE as code, family.DEFAULT_LABEL as name into ##Color from GD_COLOR_AP color left join GD_LOV_VALUE family on PK = color.F_COLOR_FAMILY --select * from ##Color -- ---------------------------------------------------------------------------- -- build local tmp tables from GD tables : build ##CoatingProcess table en prod 91 Vs 129 -> OK -- ---------------------------------------------------------------------------- drop table if exists ##CoatingProcess select distinct cast(coatingprocess.CODE as int) as id, coatingprocess.CODE as code, coatingprocess.DEFAULT_LABEL as name into ##CoatingProcess from GD_LOV_VALUE coatingprocess where coatingprocess.F_LOV_LIST = 'CoatingProcess' --select * from ##CoatingProcess -- ---------------------------------------------------------------------------- -- build local tmp tables from GD tables : build ##RefCoatingInheritance table en prod 57 Vs 60 -> OK -- ---------------------------------------------------------------------------- drop table if exists ##RefCoatingInheritance select cast(id as int) as id, cast(description as nvarchar(50)) collate SQL_Latin1_General_CP1_CS_AS as description, cast(material_family as int) as material_family, cast(material as int) as material, cast(process as int) as process, cast(color_name as int) as color_name, cast(color_code as int) as color_code, cast(coating_thickness as int) as coating_thickness, cast(coating_hardness as int) as coating_hardness into ##RefCoatingInheritance from DBV_REF_COATING_INHERITANCE --select * from ##RefCoatingInheritance -- ---------------------------------------------------------------------------- -- build local tmp tables from GD tables : build ##RefMaterialInheritance table en prod 17 Vs 23 -> OK -- ---------------------------------------------------------------------------- drop table if exists ##RefMaterialInheritance select cast(id as int) as id, cast(description as nvarchar(50)) collate SQL_Latin1_General_CP1_CS_AS as description, cast(material_family as int) as material_family, cast(material as int) as material, cast(hardness as int) as hardness, cast(color_name as int) as color_name, cast(color_code as int) as color_code, cast(composition as int) as composition into ##RefMaterialInheritance from DBV_REF_MATERIAL_INHERITANCE --select * from ##RefMaterialInheritance -- ---------------------------------------------------------------------------- -- build local tmp tables from GD tables : build ##MaterialCaracteristic table en prod 439 Vs 249 -> KO -- ---------------------------------------------------------------------------- drop table if exists ##MaterialCaracteristic select distinct cast(materheattreathardness.F_MATER_AP as int) as material_id, hardness.DEFAULT_LABEL as hardness into ##MaterialCaracteristic from GD_MATER_HEATTREAT_HARD_LK materheattreathardness left join GD_LOV_VALUE hardness on hardness.PK = materheattreathardness.F_HARDENESS --select * from ##MaterialCaracteristic -- ---------------------------------------------------------------------------- -- build local tmp tables from GD tables : build ##ColorMaterialLink table en prod 1182 Vs 1273 -> OK -- ---------------------------------------------------------------------------- drop table if exists ##ColorMaterialLink select distinct cast(matercolor_lk.F_MATER_AP as int) as material_id, matercolor_lk.F_COLOR_AP as color_code into ##ColorMaterialLink from GD_MATER_COLOR_LK matercolor_lk --select * from ##ColorMaterialLink -- ---------------------------------------------------------------------------- -- build local tmp tables from GD tables : build ####AffectedRefCoating table -- ---------------------------------------------------------------------------- drop table if exists ##AffectedRefCoating select cast(processlnk.F_MOD_CATEGORY as int) as category_id, cast(processinh.F_MOD_PROP_PROCESS as Int) as property_id, cast(process.code as int) as process_id, cast(processlnk.F_MOD_PROCESS_INHERITANCE as int) as inheritance_id, cast(processlnk.F_MOD_CATEGORY_TYPE as int) as category_type_id into ##AffectedRefCoating from GD_MOD_PROCESS_LK processlnk inner join GD_MOD_PROCESS_INH processinh on processinh.CODE = processlnk.F_MOD_PROCESS_INHERITANCE inner join GD_LOV_VALUE process on process.PK = processlnk.F_MOD_COATING_PROCESS --select * from ##AffectedRefCoating ------------------------------------------------------------------------------------- -- CoatingLink by material ------------------------------------------------------------------------------------- drop table if exists ##Coating_RefValues create table ##Coating_RefValues ( id int identity (1,1), category_name nvarchar(128) collate SQL_Latin1_General_CP1_CS_AS, property_name nvarchar(128) collate SQL_Latin1_General_CP1_CS_AS, material nvarchar(128) collate SQL_Latin1_General_CP1_CS_AS, material_family nvarchar(128) collate SQL_Latin1_General_CP1_CS_AS, process nvarchar(128) collate SQL_Latin1_General_CP1_CS_AS, color_name nvarchar(128) collate SQL_Latin1_General_CP1_CS_AS, color_code nvarchar(128) collate SQL_Latin1_General_CP1_CS_AS, thickness nvarchar(128) collate SQL_Latin1_General_CP1_CS_AS, hardness nvarchar(128) collate SQL_Latin1_General_CP1_CS_AS, composition nvarchar(128) collate SQL_Latin1_General_CP1_CS_AS, status nvarchar(128) collate SQL_Latin1_General_CP1_CS_AS, category_id int, property_id int, process_id int, inheritance_id int, category_type_id int ) insert into ##Coating_RefValues ( category_name, property_name, material, material_family, process, color_name, color_code, thickness, hardness, composition, status, category_id, property_id, process_id, inheritance_id, category_type_id ) select category.NAME as category_name, Property.NAME as property_name, Material.NAME as material, MaterialFamily.NAME as material_family, CoatingProcess.NAME as process, Color.NAME as color_name, Color.CODE as color_code, NewCoatingLink3.COATING_THICKNESS as thickness, NewCoatingLink3.COATING_HARDNESS as hardness, null as composition, COALESCE (NewCoatingLink3.COATING_STATUS, 'Valide') as status, NewCoatingLink3.CATEGORY_ID, RefCoatingInheritance.PROPERTY_ID, NewCoatingLink3.PROCESS_ID, NewCoatingLink3.COATING_INHERITANCE_GROUP_ID as inheritance_id, Category.TYPE_ID from ( select NewCoatingLink.PROCESS_ID, NewCoatingLink.CATEGORY_ID, NewCoatingLink.COATING_INHERITANCE_GROUP_ID, NewCoatingLink.COATING_STATUS, NewCoatingLink.MATERIAL_ID, NewCoatingLink.COATING_COLOR_CODE, NewCoatingLink.COATING_HARDNESS, NewCoatingLink.COATING_THICKNESS from ( -- CoatingLink by material by category ------------------------------------------------------------------------------------- select coating.PROCESS_ID as process_id, refcoatinglink.CATEGORY_ID as category_id, refcoatinglink.INHERITANCE_GROUP_ID as coating_inheritance_group_id, refcoatinglink.STATUS as coating_status, coating.MATERIAL_ID as material_id, coating.COLOR_CODE as coating_color_code, coating.HARDNESS as coating_hardness, coating.THICKNESS as coating_thickness from ##RefCoatingLink refcoatinglink join ##Coating coating on coating.PROCESS_ID = refcoatinglink.PROCESS_ID where coating.MATERIAL_ID is not null and refcoatinglink.CATEGORY_ID is not null ------------------------------------------------------------------------------------- union all -- CoatingLink by material by category type ------------------------------------------------------------------------------------- select coating.PROCESS_ID as process_id, category.ID as category_id, refcoatinglink.INHERITANCE_GROUP_ID as coating_inheritance_group_id, refcoatinglink.STATUS as coating_status, coating.MATERIAL_ID as material_id, coating.COLOR_CODE as coating_color_code, coating.HARDNESS as coating_hardness, coating.THICKNESS as coating_thickness from ##RefCoatingLink refcoatinglink join ##Coating coating on coating.PROCESS_ID = refcoatinglink.PROCESS_ID join ##Category category on Category.TYPE_ID = refcoatinglink.CATEGORY_TYPE_ID where coating.MATERIAL_ID is not null and refcoatinglink.CATEGORY_TYPE_ID is not null ------------------------------------------------------------------------------------- union all -- CoatingLink by material family by category type ------------------------------------------------------------------------------------- select coating.PROCESS_ID as process_id, category.ID as category_id, refcoatinglink.INHERITANCE_GROUP_ID as coating_inheritance_group_id, refcoatinglink.STATUS as coating_status, material.ID as material_id, coating.COLOR_CODE as coating_color_code, coating.HARDNESS as coating_hardness, coating.THICKNESS as coating_thickness from ##RefCoatingLink refcoatinglink join ##Coating coating on coating.PROCESS_ID = refcoatinglink.PROCESS_ID join ##GenericMaterial genericmaterial on genericmaterial.MATERIAL_FAMILY_ID = coating.MATERIAL_FAMILY_ID join ##Material material on material.GENERIC_MATERIAL_ID = genericmaterial.ID join ##Category category on category.TYPE_ID = refcoatinglink.CATEGORY_TYPE_ID where coating.MATERIAL_FAMILY_ID is not null and refcoatinglink.CATEGORY_TYPE_ID is not null ------------------------------------------------------------------------------------- union all -- CoatingLink by material family by category ------------------------------------------------------------------------------------- select coating.PROCESS_ID as process_id, refcoatinglink.CATEGORY_ID as category_id, refcoatinglink.INHERITANCE_GROUP_ID as coating_inheritance_group_id, refcoatinglink.STATUS as coating_status, material.ID as material_id, coating.COLOR_CODE as coating_color_code, coating.HARDNESS as coating_hardness, coating.THICKNESS as coating_thickness from ##RefCoatingLink RefCoatingLink join ##Coating coating on Coating.PROCESS_ID = refcoatinglink.PROCESS_ID join ##GenericMaterial genericmaterial on GenericMaterial.MATERIAL_FAMILY_ID = coating.MATERIAL_FAMILY_ID join ##Material material on material.GENERIC_MATERIAL_ID = genericmaterial.ID -- filtre des matières par catégories where coating.MATERIAL_FAMILY_ID is not null and refcoatinglink.CATEGORY_ID is not null ) as NewCoatingLink -- Filtre des résultats dont la matière est autorisée pour la catégorie join ( select distinct MATERIAL_ID, CATEGORY_ID from ##RefMaterialLink ) as refmateriallink on refmateriallink.CATEGORY_ID = newcoatinglink.CATEGORY_ID and refmateriallink.MATERIAL_ID = newcoatinglink.MATERIAL_ID -- Ajout des résultats qui n ont pas de matières propre union all select * from ( -- CoatingLink by material by category en prod 25231 Vs 47081 -> KO ------------------------------------------------------------------------------------- select distinct coating.PROCESS_ID as process_id, refcoatinglink.CATEGORY_ID as category_id, refcoatinglink.INHERITANCE_GROUP_ID as coating_inheritance_group_id, refcoatinglink.STATUS as coating_status, null as material_id, coating.COLOR_CODE as coating_color_code, coating.HARDNESS as coating_hardness, coating.THICKNESS as coating_thickness from ##RefCoatingLink refcoatinglink join ##Coating coating on coating.PROCESS_ID = refcoatinglink.PROCESS_ID where refcoatinglink.CATEGORY_ID is not null ------------------------------------------------------------------------------------- union all -- CoatingLink by material by category type en prod 94311 Vs 835238 -> OK ------------------------------------------------------------------------------------- select distinct coating.PROCESS_ID as process_id, category.ID as category_id, refcoatinglink.INHERITANCE_GROUP_ID as coating_inheritance_group_id, refcoatinglink.STATUS as coating_status, null as material_id, coating.COLOR_CODE as coating_color_code, coating.HARDNESS as coating_hardness, coating.THICKNESS as coating_thickness from ##RefCoatingLink refcoatinglink join ##Coating coating on coating.PROCESS_ID = refcoatinglink.PROCESS_ID join ##Category Category on category.TYPE_ID = refcoatinglink.CATEGORY_TYPE_ID where refcoatinglink.CATEGORY_TYPE_ID is not null ------------------------------------------------------------------------------------- ) as NewCoatingLink2 where newcoatinglink2.CATEGORY_ID not in (select CATEGORY_ID from ##RefMaterialLink where INHERITANCE_GROUP_ID = 1) ) as NewCoatingLink3 -- Ajout des informations de famille matière left join ##Material material on material.ID = newcoatinglink3.MATERIAL_ID left join ##GenericMaterial genericmaterial on genericmaterial.ID = material.GENERIC_MATERIAL_ID left join ##MaterialFamily materialfamily on materialfamily.ID = genericmaterial.MATERIAL_FAMILY_ID -- Ajout des informations des process de revêtements inner join ##CoatingProcess coatingprocess on coatingprocess.ID = newcoatinglink3.PROCESS_ID -- Ajout des informations des couleurs inner join ##Color color on color.CODE = newcoatinglink3.COATING_COLOR_CODE -- Ajout des informations des catégories inner join ##Category category on newcoatinglink3.CATEGORY_ID = Category.ID -- Ajout des propriétés inner join ( select distinct ID, PROCESS as Property_id from ##RefCoatingInheritance where PROCESS is not null union all select distinct ID, COLOR_NAME as Property_id from ##RefCoatingInheritance where COLOR_NAME is not null union all select distinct ID, COLOR_CODE as Property_id from ##RefCoatingInheritance where COLOR_CODE is not null union all select distinct ID, COATING_HARDNESS as Property_id from ##RefCoatingInheritance where COATING_HARDNESS is not null union all select distinct ID, COATING_THICKNESS as Property_id from ##RefCoatingInheritance where COATING_THICKNESS is not null ) as refcoatinginheritance on refcoatinginheritance.ID = newcoatinglink3.COATING_INHERITANCE_GROUP_ID inner join ##Property property on RefCoatingInheritance.PROPERTY_ID = property.ID inner join ##CategoryPropertyLink categorypropertylink on categorypropertylink.PROPERTY_ID = Property.ID and categorypropertylink.CATEGORY_ID = Category.ID ------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------------ drop table if exists ##V_RefValues create table ##V_RefValues ( category_name nvarchar(128) collate SQL_Latin1_General_CP1_CS_AS, property_name nvarchar(128) collate SQL_Latin1_General_CP1_CS_AS, material nvarchar(128) collate SQL_Latin1_General_CP1_CS_AS, material_family nvarchar(128) collate SQL_Latin1_General_CP1_CS_AS, process nvarchar(128) collate SQL_Latin1_General_CP1_CS_AS, color_name nvarchar(128) collate SQL_Latin1_General_CP1_CS_AS, color_code nvarchar(128) collate SQL_Latin1_General_CP1_CS_AS, thickness nvarchar(128) collate SQL_Latin1_General_CP1_CS_AS, hardness nvarchar(128) collate SQL_Latin1_General_CP1_CS_AS, composition nvarchar(128) collate SQL_Latin1_General_CP1_CS_AS, status nvarchar(128) collate SQL_Latin1_General_CP1_CS_AS ) ------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------------ drop table if exists ##AffectedRefCoatingCategoriesId select distinct coat.ID into ##AffectedRefCoatingCategoriesId from ##Coating_RefValues coat inner join ##AffectedRefCoating affectedrefcoating on affectedrefcoating.CATEGORY_ID = coat.CATEGORY_ID and affectedrefcoating.INHERITANCE_ID = coat.INHERITANCE_ID where AffectedRefCoating.CATEGORY_ID is not null insert into ##AffectedRefCoatingCategoriesId (ID) select distinct coat.ID from ##Coating_RefValues coat inner join ##AffectedRefCoating AffectedRefCoating on AffectedRefCoating.category_type_id = coat.category_type_id and AffectedRefCoating.INHERITANCE_ID = coat.INHERITANCE_ID where AffectedRefCoating.CATEGORY_ID is null insert into ##V_RefValues ( category_name, property_name, material, material_family, process, color_name, color_code, thickness, hardness, composition, [status] ) select distinct category_name, property_name, material, material_family, process, color_name, color_code, thickness, hardness, composition, status from ##Coating_RefValues coat inner join ##AffectedRefCoating affectedrefcoating on affectedrefcoating.CATEGORY_ID = COAT.CATEGORY_ID --and affectedrefcoating.PROPERTY_ID = coat.PROPERTY_ID and affectedrefcoating.PROCESS_ID = coat.PROCESS_ID and affectedrefcoating.INHERITANCE_ID = coat.INHERITANCE_ID where affectedrefcoating.CATEGORY_ID is not null insert into ##V_RefValues ( category_name, property_name, material, material_family, process, color_name, color_code, thickness, hardness, composition, status ) select distinct category_name, property_name, material, material_family, process, color_name, color_code, thickness, hardness, composition, status from ##Coating_RefValues coat --inner join ##Category category on category.ID = coat.CATEGORY_ID inner join ##AffectedRefCoating affectedrefcoating on affectedrefcoating.CATEGORY_TYPE_ID = coat.CATEGORY_TYPE_ID --and affectedrefcoating.PROPERTY_ID = coat.PROPERTY_ID and affectedrefcoating.PROCESS_ID = coat.PROCESS_ID and affectedrefcoating.INHERITANCE_ID = coat.INHERITANCE_ID where affectedrefcoating.CATEGORY_ID is null ------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------------ insert into ##V_RefValues ( category_name, property_name, material, material_family, process, color_name, color_code, thickness, hardness, composition, status ) select distinct category_name, property_name, material, material_family, process, color_name, color_code, thickness, hardness, composition, status from ##Coating_RefValues where ID not in (Select ID from ##AffectedRefCoatingCategoriesId) ------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------------ insert into ##V_RefValues ( category_name, property_name, material, material_family, process, color_name, color_code, thickness, hardness, composition, status ) select distinct category.NAME as category_name, Property.NAME as property_name, Material.NAME as material, MaterialFamily.NAME as material_family, null as process, Color.NAME as color_name, Color.CODE as color_code, null as thickness, MaterialCaracteristic.HARDNESS as hardness, material.COMPOSITION as composition, Material.STATUS as status from ##RefMaterialLink refmateriallink join ( select distinct ID, MATERIAL as Property_id from ##RefMaterialInheritance where MATERIAL is not null union all select distinct ID, MATERIAL_FAMILY as Property_id from ##RefMaterialInheritance where MATERIAL_FAMILY is not null union all select distinct ID, HARDNESS as Property_id from ##RefMaterialInheritance where HARDNESS is not null union all select distinct ID, COLOR_CODE as Property_id from ##RefMaterialInheritance where COLOR_CODE is not null union all select distinct ID, COLOR_NAME as Property_id from ##RefMaterialInheritance where COLOR_NAME is not null union all select distinct ID, COMPOSITION as Property_id from ##RefMaterialInheritance where COMPOSITION is not null ) as refcoatinginheritance on refcoatinginheritance.ID = refmateriallink.INHERITANCE_GROUP_ID join ##Property property on property.ID = refcoatinginheritance.PROPERTY_ID join ##Category category on category.ID = refmateriallink.CATEGORY_ID join ##Material material on material.ID = refmateriallink.MATERIAL_ID left join ##MaterialCaracteristic materialcaracteristic on Material.ID = materialcaracteristic.MATERIAL_ID join ##GenericMaterial genericmaterial on Material.GENERIC_MATERIAL_ID = genericmaterial.ID join ##MaterialFamily materialfamily on MaterialFamily.ID = genericmaterial.MATERIAL_FAMILY_ID left join ##ColorMaterialLink colormateriallink on colormateriallink.MATERIAL_ID = material.ID left join ##Color color on color.CODE = colormateriallink.COLOR_CODE truncate table V_RefValues insert into V_RefValues ( category_name, property_name, material, material_family, process, color_name, color_code, thickness, hardness, composition, status ) select distinct category_name, property_name, material, material_family, process, color_name, color_code, thickness, hardness, composition, status from ( select *, rank() over (partition by CATEGORY_NAME, PROPERTY_NAME, MATERIAL, MATERIAL_FAMILY, PROCESS, COLOR_NAME, COLOR_CODE, THICKNESS, HARDNESS, COMPOSITION, STATUS order by status desc) as ranking FROM ##V_RefValues ) tmp where ranking = 1 - Assistant
Il y a plusieurs raisons possibles pour les verrous persistants sur la table "truncate table v_refvalues" dans la procédure stockée. Voici quelques pistes à explorer :
-
Des transactions concurrentes ou d'autres opérations peuvent bloquer l'accès à la table
v_refvalues. Essayez d'exécuter l'instructiontruncate tableen dehors des heures de pointe ou pendant des périodes de faible charge sur la base de données. Vous pouvez également envisager d'utiliser au lieu de pour éviter les verrous.
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.