在SQL Server中进行比较之前确定隐式转换

时间:2016-11-04 15:22:45

标签: sql-server type-conversion

我们都继承了糟糕的数据模型。我有一个数据模型,其中FK约束将转换为不可隐式转换的数据类型。例如,我有一个VARCHAR引用列(constraintColumn),它与INT父列(constrainedColumn)具有FK关系。

SELECT
  OBJECT_NAME(fk.constraint_object_id) KeyName
, t.name                               constrainedTable
, c.name                               constrainedColumn
, t2.name                              constraintTable
, c2.name                              constraintColumn
FROM
  sys.foreign_key_columns AS fk
    INNER JOIN
    sys.tables AS t ON
  fk.parent_object_id = t.object_id
    INNER JOIN
    sys.columns AS c ON
  fk.parent_object_id = c.object_id
  AND
  fk.parent_column_id = c.column_id
    INNER JOIN
    sys.tables AS t2 ON
  fk.referenced_object_id = t2.object_id
    INNER JOIN
    sys.columns AS c2 ON
  fk.referenced_object_id = c2.object_id
  AND
  fk.constraint_column_id = c2.column_id
ORDER BY
  t.name
, c.name;

如何使用sys.types或其他内容来确定哪些数据类型是可隐式转换的?

{{3}}

0 个答案:

没有答案