SQL多表访问

SQL多表访问,sql,Sql,我这里有一段代码,它是查询选择的“TestLog”,显示: 名字 模式 行数 总空间 usedspace 问题是,我需要这个信息被查询多个表,让我们说一个5个具体的。。。有人能帮忙吗 USE myDB GO SELECT t.name AS TableName, s.name AS Sche

我这里有一段代码,它是查询选择的“TestLog”,显示:

  • 名字
  • 模式
  • 行数
  • 总空间
  • usedspace
问题是,我需要这个信息被查询多个表,让我们说一个5个具体的。。。有人能帮忙吗

USE myDB
GO 

SELECT
  t.name                                                 AS TableName,
  s.name                                                 AS SchemaName,
  p.rows                                                 AS RowCounts,
  SUM(a.total_pages) * 8 / 1024                          AS TotalSpaceMB,
  SUM(a.used_pages) * 8 / 1024                           AS UsedSpaceMB,
  (SUM(a.total_pages) - SUM(a.used_pages)) * 8 / 1024    AS UnusedSpaceMB
FROM
  sys.tables t
  INNER JOIN sys.indexes i ON t.object_id = i.object_id
  INNER JOIN sys.partitions p ON i.object_id = p.object_id AND i.index_id = p.index_id
  INNER JOIN sys.allocation_units a ON p.partition_id = a.container_id
  LEFT OUTER JOIN sys.schemas s ON t.schema_id = s.schema_id
WHERE
    t.name = ('TestLog') 
      AND t.is_ms_shipped = 0
  AND i.object_id > 255
GROUP BY
  t.name, s.name, p.rows
ORDER BY
  t.name;
GO
其工作原理如下:

-- specific tables 
 WHERE
    t.name in ('Test1' , 'Test2' , 'Test3') 
    AND t.is_ms_shipped = 0   
    AND i.object_id > 255

-- one specific table 
 WHERE
    t.name = 'TestLog' 
    AND t.is_ms_shipped = 0   
    AND i.object_id > 255

-- specific tables with test in front 
  WHERE
    t.name like 'Test%' 
    AND t.is_ms_shipped = 0   
    AND i.object_id > 255

其中t.name('TestLog','table2','table3',…)
是的,我完成了脚本,对它进行了测试,它就像一个charm@600vka,所以请接受答案。我知道它实际上得到了回答(在jarlh的评论中),但除此之外,你的问题仍然没有得到回答。。。