如何在sql中创建索引列?

时间:2010-07-27 08:53:41

标签: sql sql-server tsql

我正在使用SQL-Server 2005。

我有许多列的表,我选择的行有where子句,这使得不可能将身份用作索引器。我想选择所有这些行+索引器行(表现为身份)。

例如

2 jack

4 thomas

8 james

1 2 jack

2 4 thomas

3 8 james

感谢

1 个答案:

答案 0 :(得分:2)

使用rank函数或row_number(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