Sqlserver
 sql >> Database >  >> RDS >> Sqlserver

Aggiungere la colonna Identity a una vista in SQL Server 2008

Usa il ROW_NUMBER() funzione 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