比较5

发布: (2025年12月3日 GMT+8 05:49)
1 min read
原文: Dev.to

Source: Dev.to

SQL 脚本

-- Declare variables for schema UIDs (run once)
DECLARE @uid1 int, @uid2 int
SELECT @uid1 = uid FROM sysusers WHERE name = 'GLOBAL_COMET_US_1'
SELECT @uid2 = uid FROM sysusers WHERE name = 'GLOBAL_COMET_US_2'

-- Query: Tables only in US_1
SELECT 'ONLY_IN_US_1' AS location, t1.name AS table_name
FROM   sysobjects t1
LEFT JOIN sysobjects t2 
       ON t1.name = t2.name
      AND t2.uid = @uid2
      AND t2.type = 'U'
WHERE  t1.uid = @uid1
  AND  t1.type = 'U'
  AND  t2.id IS NULL

UNION ALL

-- Query: Tables only in US_2
SELECT 'ONLY_IN_US_2' AS location, t2.name AS table_name
FROM   sysobjects t2
LEFT JOIN sysobjects t1 
       ON t2.name = t1.name
      AND t1.uid = @uid1
      AND t1.type = 'U'
WHERE  t2.uid = @uid2
  AND  t2.type = 'U'
  AND  t1.id IS NULL

ORDER BY 1, 2;
Back to Blog

相关文章

阅读更多 »

比较4

sql -- 首先获取用户ID(可选),以提高可读性 DECLARE @uid1 int, @uid2 int SELECT @uid1 = uid FROM sysusers WHERE name = 'GLOBAL_COMET_US_1' SELE...

比较3

sql SELECT 'ONLY_IN_US_1' AS location, t1.table_name FROM dba_tables t1 LEFT JOIN dba_tables t2 ON t1.table_name = t2.table_name AND t2.owner = 'GL...

创建12

用于DBVisualizer的T-SQL脚本,统计过去45天内添加的行数

创建11

SQL 声明 @sql 为 varchar8000;将 @sql 设为空字符串;将 @sql 追加为 `SELECT ''+name+'' , count FROM '+name+ ' WHERE INTERNTIMESTAMP >= DATEADD(dd,-45,GETDATE) UNION …`