DECLARE @SourceTableNameVARCHAR(100)
DECLARE @DestTableName VARCHAR(100)
SET @SourceTableName = 'TableA'
SET @DestTableName = 'TableB'
SELECT A.TABLE_NAME AS SourceTable
,A.COLUMN_NAME AS SourceColumn
,A.DATA_TYPE AS SourceType
,B.TABLE_NAME AS DestTable
,B.COLUMN_NAME AS DestColumn
,B.DATA_TYPE AS DestType
FROM (SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = @SourceTableName) A
FULL OUTER JOIN (SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = @DestTableName) B
ON A.COLUMN_NAME = B.COLUMN_NAME AND A.DATA_TYPE = B.DATA_TYPE
WHERE A.TABLE_NAME IS NULL OR B.TABLE_NAME IS NULL
查数据字典select T.COLUMN_NAME
from ALL_TAB_COLUMNS T
where T.TABLE_NAME = 'A表'
minus
select T.COLUMN_NAME
from ALL_TAB_COLUMNS T
where T.TABLE_NAME = 'B表'
这样就找到了DBF_1比DBF_2多出来的列
要抽数据就直接写:
select 查到的几列 from DBF_1就行了
我给你的sql贴上去跑就行了啊,怎么还不清楚么?
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)