本文介紹了將標(biāo)識(shí)列添加到 SQL Server 2008 中的視圖的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
這是我的觀點(diǎn):
Create View [MyView] as
(
Select col1, col2, col3 From Table1
UnionAll
Select col1, col2, col3 From Table2
)
我需要添加一個(gè)名為 Id
的新列,我需要這個(gè)列是唯一的,所以我想添加新列作為身份.我必須提到這個(gè)視圖返回了大量數(shù)據(jù),所以我需要一種具有良好性能的方法,而且我使用了兩個(gè)帶有聯(lián)合的選擇查詢,我認(rèn)為這可能有些復(fù)雜,那么您的建議是什么?
I need to add a new column named Id
and I need to this column be unique so I think to add new column as identity. I must mention this view returned a large of data so I need a way with good performance, And also I use two select query with union all I think this might be some complicated so what is your suggestion?
推薦答案
在 SQL Server 2008 中使用 ROW_NUMBER()
函數(shù).
Use the ROW_NUMBER()
function in SQL Server 2008.
Create View [MyView] as
SELECT ROW_NUMBER() OVER( ORDER BY col1 ) AS id, col1, col2, col3
FROM(
Select col1, col2, col3 From Table1
Union All
Select col1, col2, col3 From Table2 ) AS MyResults
GO
這篇關(guān)于將標(biāo)識(shí)列添加到 SQL Server 2008 中的視圖的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!