下面的查询比较两个数据库之间的主键。它标识一个数据库中的所有主键约束,但不标识另一个数据库中的所有主键约束。当我运行查询时,一些约束名称似乎是系统生成的(即PK__afm_scmpref__2D27B809
或PK__projfund__E34271EE251CF998
),因为这些是系统生成的,所以我无法跨数据库比较它们。有没有办法解决这个问题?
非常感谢,
这是我的代码:
SELECT src.table_name AS src_table,
src.constraint_name AS scr_constraint_name,
src.column_name AS src_column_name,
src.ordinal_position AS src_ordinal_position,
tgt.table_name AS tgt_table_name ,
tgt.constraint_name AS tgt_constraint_name,
tgt.column_name AS tgt_column_name,
tgt.ordinal_position AS tgt_ordinal_position
from db_comp_src_primary_keys src
FULL OUTER JOIN
db_comp_tgt_primary_keys tgt ON
src.table_name = tgt.table_name
AND src.constraint_name = tgt.constraint_name
WHERE ( (src.constraint_name IS NULL AND tgt.constraint_name IS NOT NULL)
OR (src.constraint_name IS NOT NULL AND tgt.constraint_name IS NULL))
AND ( ( tgt.table_name IS NULL
AND src.table_name IS NOT NULL
AND src.constraint_name IS NOT NULL
AND src.table_name IN
(SELECT table_name
FROM [HQ-193-STOCK-DBO].INFORMATION_SCHEMA.tables))
OR ( src.table_name IS NULL
AND tgt.table_name IS NOT NULL
AND tgt.constraint_name IS NOT NULL
AND tgt.table_name IN
(SELECT table_name
FROM [HQ-211-STOCK-DBO].INFORMATION_SCHEMA.tables)))