sql >> Base de Datos >  >> RDS >> Sqlserver

Agregue la columna Identidad a una vista en SQL Server 2008

Usa el ROW_NUMBER() función en 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