Sqlserver
 sql >> Base de Dados >  >> RDS >> Sqlserver

Adicionar coluna de identidade a uma exibição no SQL Server 2008


Use o ROW_NUMBER() função no 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