第一列要自动递增select *
-------------------------
1 aaa
2 bbb
3 ccc
4 ddd
...不能在数据库增加字段,数据库也没有identity字段,就只用SQL语句达到以上效果,该怎么写?
-------------------------
1 aaa
2 bbb
3 ccc
4 ddd
...不能在数据库增加字段,数据库也没有identity字段,就只用SQL语句达到以上效果,该怎么写?
调试欢乐多
select id=identity(int,1,1),* into #t from tb
select * from #t
Id=(select COUNT(*) from tb where name<=kble.Name) ,
name
from tb kble
--======= 每天都在进步,却依然追不上地球的自传=========
--======= By: zc_0101 At:2009-08-25 22:01:49=========
--========++++++++++++++++++++++++++++++++++++=========
--> 测试数据: #t
if object_id('tempdb.dbo.#t') is not null drop table #t
create table #t (COL varchar(3))
insert into #t
select 'AAA' union all
select 'BBB' union all
select 'CCC'
----------------查询------------
SELECT ID=IDENTITY(INT,1,1),COL INTO #TEMP FROM #t
SELECT * FROM #TEMP
----------------结果--------------
/*
ID COL
1 AAA
2 BBB
3 CCC
*/
select
Id=ROW_NUMBER() over (order by name),
name
from tb
--SQL2005可以用select Id=ROW_NUMBER() over (order by name),name
from tb