SQL:从多个以“ _reports”结尾的表中选择*

时间:2018-07-10 15:35:53

标签: mysql

因此,我在一个人们可以在某个频道中放置文本和图像并防止不必要的帖子的网站上工作,我创建了一个报告按钮。按下后,*random_code*_reports表中将插入新行,该频道的管理员可以对此做出反应。

但是,网站所有者也应该能够对它们做出反应,但是我很高兴地做出了一个有效的查询,该查询选择了所有 random_code _reports表中的所有报告

因此,很明显,在创建通道时,将创建一些表:

$code."_posts"

$code."_files"

$code."_comments"

$code."_likes"

$code."_reports"

其中代码是6个字符的随机值。

是否存在用于选择某些名称为'_reports'的表的类似功能?

1 个答案:

答案 0 :(得分:1)

没有用于选择foreach (Section section in document.Sections) { //Get the header range and add the header details. var headerRange = section.Headers[WdHeaderFooterIndex.wdHeaderFooterPrimary].Range; headerRange.Fields.Add(headerRange, WdFieldType.wdFieldPage); headerRange.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphLeft; headerRange.Font.ColorIndex = WdColorIndex.wdBlack; headerRange.Font.Size = 12; headerRange.Font.Name = "Arial"; headerRange.Font.Bold = 1; headerRange.Text = ClientNameBox.Text; headerRange.InsertParagraphAfter(); object oCollapseEnd = WdCollapseDirection.wdCollapseEnd; headerRange.Collapse(ref oCollapseEnd); headerRange.Text = ClientsAddressBox.Text; headerRange.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphLeft; }

的SQL标准

请参阅:possible to create sql query with table wildcards?

您必须首先通过查询某种元信息来简单地选择所有表。

FROM %_table

(请注意,这是特定于mysql的,其他数据库服务器还有其他查询可用表的方式)

您可以将数据重组为多个数据库,而不是表前缀,然后使用

进行查询

SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME LIKE '%_reports';

通过这种方式,您可以将具有大量数据的整个数据库移到它们自己的服务器上,并调整连接字符串以查找哪些通道与哪些服务器相关联(称为单租户数据库)

或者,您可以将随机代码添加为一列,有时也称为说明符列或多租户数据库。

SELECT * FROM $random_code.reports

SELECT * FROM reports where channel_code = '$random_code'