代码之家  ›  专栏  ›  技术社区  ›  eugeneK

如何在sql中创建索引列?

  •  1
  • eugeneK  · 技术社区  · 16 年前

    我正在使用SQLServer2005。

    我有许多列的表,我选择的行有where子句,这使得不可能使用identity作为索引器。我要选择所有这些行+索引行(像标识一样)。

    例子

    2 jack
    
    4 thomas
    
    8 james
    

    1 2 jack
    
    2 4 thomas
    
    3 8 james
    

    1 回复  |  直到 16 年前
        1
  •  2
  •   Michael Pakhantsov    16 年前

    http://www.databasejournal.com/features/mssql/article.php/3661461/New-Ranking-Functions-within-SQL-Server-2005.htm )

    select rank() OVER (ORDER BY list of your columns) as Id, 
    your_column_1, your_column_2 ...
    from your table