很好的。我正在研究一个过度规范化的数据库,该程序运行我们没有在内部构建的程序。我们需要从不同的表中提取数据以使其工作。当我运行以下查询时,它会导致:
消息4104,级别16,状态1,行14多部分标识符 " dbo.db_record.db_record_id"无法受约束。
我已经调查了这个,我找不到错误的原因,并试图弄清楚我可以做些什么来解决这个问题。
USE [Acuity_Train]
select p.provider_identity,
p.provider_type,
p.provider_name,
p.NPI,
t.taxonomy_code,
udf.user_field_data_09 AS [Medicaid #]
from provider p
--This join links provider data to taxonomy table for taxonomy code select above
LEFT OUTER JOIN dbo.provider_taxonomy prvt
ON prvt.provider_identity = p.provider_identity
INNER JOIN dbo.taxonomy t
ON t.taxonomy_identity = prvt.taxonomy_identity
-- This allows for access to medicaid ID #
LEFT OUTER JOIN v_provider_network_affiliation vpna
ON vpna.key2 = p.provider_identity
AND vpna.key1 in ('55', '56')
LEFT OUTER JOIN user_field_data AS udf
ON udf.table_code='PRNW'
AND udf.key1=vpna.provider_affiliation_identity
-- Next 3 Joins needed to access company.company_code
LEFT OUTER JOIN dbo.provider_affiliation praf
ON praf.db_record_id_child = dbo.db_record.db_record_id
LEFT OUTER JOIN dbo.db_record AS dbr_parent
ON praf.db_record_id_parent = dbr_parent.db_record_id
LEFT OUTER JOIN company
ON dbr_parent.key1 = company.company_identity
Where company.company_code in ('Prestige', '114', '115', '148', '181')
答案 0 :(得分:3)
你有... ...
LEFT OUTER JOIN dbo.provider_affiliation praf
ON praf.db_record_id_child = dbo.db_record.db_record_id
此时您尚未介绍dbo.db_record
,因此它不知道您想加入的内容。
答案 1 :(得分:0)
错过了一个加入步骤,需要在这里找到另一张桌子。
LEFT OUTER JOIN dbo.db_record
ON p.provider_identity = dbo.db_record.key1
AND dbo.db_record.table_code = 'PROV'
LEFT OUTER JOIN dbo.provider_affiliation praf
ON praf.db_record_id_child = dbo.db_record.db_record_id
LEFT OUTER JOIN dbo.db_record AS dbr_parent
ON praf.db_record_id_parent = dbr_parent.db_record_id
LEFT OUTER JOIN company
ON dbr_parent.key1 = company.company_identity