Home > Database > Mysql Tutorial > SqlServer 序号列的实现方法

SqlServer 序号列的实现方法

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-07 17:58:18
Original
1333 people have browsed it

对于 SQL SERVER 2000 及更早的版本,需要使用一个自增列,结合临时表来实现。

对于 SQL SERVER 2000 及更早的版本,需要使用一个自增列,结合临时表来实现。
代码如下:
SELECT [AUTOID] = IDENTITY(int,1,1), * INTO #temp_table FROM 表名;


代码如下:
SELECT * FROM #temp_table;

从 SQL SERVER 2005 开始, SQL SERVER 提供了一个 ROW_NUMBER() 函数,大大简化了工作。

代码如下:
SELECT *,ROW_NUMBER() OVER (ORDER BY 排序字段) AS [AUTOID] FROM 表名;

序号字段的别名,可以在后续的条件中使用。
Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
Problem with tp6 connecting to sqlserver database
From 1970-01-01 08:00:00
0
0
0
Unable to connect to SQL Server in Laravel
From 1970-01-01 08:00:00
0
0
0
Methods of parsing MYD, MYI, and FRM files
From 1970-01-01 08:00:00
0
0
0
SQLSTATE: User login failed
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template