SQL 自增ID
alter table a add id int identity(1,1) not null
這里為 a 表增加一個 id 字段,其中identity(1,1)代表自增,第一個1代表從1開始計數,第二個1代表每次增長1。not null 不能為空。
SQL查詢序號
select row_number() over(order by a1) xh from a
Sql Server 中的 row_number() 得到一個查詢出的順序,但這個函數要求給出一個查的排序方案,因為SQL Server的存儲是無關順序的。解說:在這里,a是一個表,a1是表中的一個字段,這里用於在自增時排序。
