Sqlserver
 sql >> Datenbank >  >> RDS >> Sqlserver

Identitätsspalte zu einer Ansicht in SQL Server 2008 hinzufügen

Verwenden Sie die ROW_NUMBER() Funktion 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