注册表中

时间:2018-01-04 18:16:32

标签: sql sql-server database performance

我需要知道他们在做select时使用什么数据库,uni使用UNION,他们是5个不同的数据库,具有相同的字段

SELECT *, DB_NAME()[DATABASE] FROM SMKNEW.dbo.COLABORA WHERE CB_CODIGO LIKE '%11%'
UNION ALL SELECT *, DB_NAME()[DATABASE] FROM DH.dbo.COLABORA WHERE CB_CODIGO LIKE '%11%'
UNION ALL SELECT *, DB_NAME()[DATABASE] FROM FE.dbo.COLABORA WHERE CB_CODIGO LIKE '%11%'
UNION ALL SELECT *, DB_NAME()[DATABASE] FROM PSQ.dbo.COLABORA WHERE CB_CODIGO LIKE '%11%'
UNION ALL SELECT *, DB_NAME()[DATABASE] FROM RH.dbo.COLABORA WHERE CB_CODIGO LIKE '%11%'

Query Dabatase Name Master

我需要知道他们在做select时使用什么数据库,uni使用UNION,他们是5个不同的数据库,具有相同的字段

试试这个.. enter image description here

我怎么知道注册表来自哪个数据库?

1 个答案:

答案 0 :(得分:1)

您已经知道查询中的数据库名称,为什么不像以下那样做

SELECT *, 'SMKNEW' as [DATABASE] FROM SMKNEW.dbo.COLABORA WHERE CB_CODIGO LIKE '%11%'
UNION ALL SELECT *, 'DH' as [DATABASE] FROM DH.dbo.COLABORA WHERE CB_CODIGO LIKE '%11%'
UNION ALL SELECT *, 'FE' as [DATABASE] FROM FE.dbo.COLABORA WHERE CB_CODIGO LIKE '%11%'
UNION ALL SELECT *, 'PSQ' as [DATABASE] FROM PSQ.dbo.COLABORA WHERE CB_CODIGO LIKE '%11%'
UNION ALL SELECT *, 'RH' as [DATABASE] FROM RH.dbo.COLABORA WHERE CB_CODIGO LIKE '%11%'