sqlserver 比較兩個表的列
一、問題
給了兩個各有四五十個列的表,找出他們相同的列和不同的列
二、查詢兩個表的列,存在臨時表
--#a ,#b都是臨時表,當前連接斷開后自動刪除
--RANK() OVER (ORDER BY syscolumns.name DESC) AS 是SQL2005支持的,在每行記錄前加上自增序號
--IDENTITY(INT,1,1) 函數(shù)必須要和into聯(lián)合使用
1、將表的列存入#a--'destTbl'比較的表名
select * into #a from (select RANK() OVER (ORDER BY syscolumns.name DESC) AS 序號,syscolumns.name
from syscolumns,sysobjects
where syscolumns.[id]=sysobjects.[id]
and sysobjects.[name]='destTbl') as t
select * from #a
1 姓名
2 課程
3 id
4 cno
2、將表的列存入#b--'student'比較的表名
select 序號= IDENTITY(INT,1,1),syscolumns.name
into #b from syscolumns,sysobjects
where syscolumns.[id]=sysobjects.[id]
and sysobjects.[name]='student'
select * from #b
1 id
2 name
3 cno
三、分析比較各個表列的異同
用下列語句,或者稍作改動比較
select * from #b where name in (select name from #a)
select * from #a where name not in (select name from #b)
select * from #a a, #b b where a.name=b.name
select * from #a a left join #b b on a.name=b.name
相關文章
如何得到數(shù)據(jù)庫中所有表名 表字段及字段中文描述
最近做一個項目,客戶希望可以自己選擇想要查看的列表,這樣就不好辦了,選擇列表的名字他們也想自定義,沒辦法這就需要查看數(shù)據(jù)表中字段,中文說明,默認標志了2011-12-12sql數(shù)據(jù)庫不能直接用instr函數(shù)
sql數(shù)據(jù)庫不能直接用instr函數(shù)...2007-01-01mybatis動態(tài)sql實現(xiàn)邏輯代碼詳解
mybatis通過將sql配置xml文件中,通過解析xml動態(tài)標簽來實現(xiàn)動態(tài)sql,本文以xml文件為例給大家介紹mybatis動態(tài)sql的實現(xiàn)代碼,感興趣的朋友一起看看吧2021-08-08關系型數(shù)據(jù)庫與非關系型數(shù)據(jù)庫簡介
數(shù)據(jù)庫有很多種類型,本文對常用的各大關系型數(shù)據(jù)庫(例如:Oracol、SQLSer、mysql等)和非關系型數(shù)據(jù)庫(例如:MongoDB、Cassandra、Hadoop HBase等)的優(yōu)勢和缺點做了詳細的分類分析介紹說明2021-08-08