sql - 有没有一种简单的方法来比较 SQL Server 中两个表之间的列名?
问题描述
我正在使用 SQL Server 中的两个非常广泛、非常相似的表。一个表中存在 5-10 列,但另一个表中不存在。有没有一种简单的方法可以找出一个表中存在哪些列但另一个表中不存在哪些列?
解决方案
使用information_schema.columns
. 这是一种带有 a 的方法full outer join
:
select c1.column_name, c2.column_name
from (select c.*
from information_schema.columns
where table_name = @table1 and table_schema = @schema1
) c1 full outer join
(select c.*
from information_schema.columns
where table_name = @table2 and table_schema = @schema2
) c2
on c1.column_name = c2.column_name
where c1.column_name is null or c2.column_name is null
推荐阅读
- awk - 防止 awk 添加非整数?
- python - 安装 anaconda 时,boto3 不会安装在 anaconda-2020.07 /apps/anaconda3-2020.07/
- elasticsearch - elasticsearch-certutil 创建的证书在生产中不可用?
- docker - 如何在 Alpine docker 容器中接收 UDP 消息?
- html - 为什么我使用 % 时背景图像会消失?
- python - 如何在 HTML 中呈现和显示来自 Django 的变量和值
- shell - 如何从一个新添加的列中的第一行更改值
- python - 在 Python 中规范化深度嵌套的 JSON 错误地产生数百列
- iphone - NotificationCenter addObserver forreachabilityChanged 不起作用
- python - 在python中生成一个随机句子