我需要知道他们在做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%'
我需要知道他们在做select时使用什么数据库,uni使用UNION,他们是5个不同的数据库,具有相同的字段
我怎么知道注册表来自哪个数据库?
答案 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%'