有没有办法检查另一个数据集中存在一个数据集中的哪些列? SQL

发布于 2025-01-28 15:05:06 字数 44 浏览 2 评论 0原文

例如,我有表1和表2,有没有一种方法可以检查表2中的表1中的哪些列?谢谢!

For example, I have table 1 and table 2, is there a way I can check the which columns from table 1 exist in table 2? Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

请爱~陌生人 2025-02-04 15:05:06

虽然最好的解决方案将是特定于RDBMS(您尚未指示),但大多数数据库支持的A enstry 方法是使用 inovery_schema 视图,例如列出表1中的表1中的列名:

select column_name 
from information_schema.columns t1
where t1.table_schema='schemaName' and t1.table_name='table1'
and exists (
  select * from information_schema.COLUMNS t2
    where t2.column_name = t1.column_name 
      and t2.table_schema = t1.table_schema 
      and t2.column_name ='table2'
);

While the best solutions will be RDBMS specific (which you have not indicated), a general way that's supported by most databases is to use the information_schema views, for example the following will list the column names in table1 that are also in table2:

select column_name 
from information_schema.columns t1
where t1.table_schema='schemaName' and t1.table_name='table1'
and exists (
  select * from information_schema.COLUMNS t2
    where t2.column_name = t1.column_name 
      and t2.table_schema = t1.table_schema 
      and t2.column_name ='table2'
);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文