34,873
社区成员
发帖
与我相关
我的任务
分享CREATE TABLE t (Q VARCHAR(10), M VARCHAR(10), [名字] VARCHAR(10))
INSERT dbo.t
SELECT 'QW', 'WW', 'W' UNION ALL SELECT 'Q', 'EE', 'EE'
ALTER TABLE dbo.t ADD [自动顺序] INT IDENTITY(1,1)
create table yourname (Q varchar(2),W varchar(2),名字 varchar(2))
insert into yourname
select 'QW','WW','W' union all
select 'Q','EE','EE' union all
select 'a',null,null union all
select 'd',null,null union all
select 'u',null,null
alter table yourname add id int
declare @i int
set @i=0
update yourname set @i=id=@i+1
select id,Q,W,名字 from yourname
/*
id Q W 名字
----------- ---- ---- ----
1 QW WW W
2 Q EE EE
3 a NULL NULL
4 d NULL NULL
5 u NULL NULL
*/
select row_number() over (order by getdate()) as [自动顺序],Q,W,名字 from #c as c
select identity(int,1,1) as [自动顺序],Q,W,[名字] into #t from tb
select * from #tselect identity(int,1,1) as [自动顺序],Q,W,[名字] into #temp from tb
select * from #temp
select id=identity(int,1,1),* from tb
select id=row_number() over (order by getdate()),* from tb
select id=row)number()over(order by getdate()),* from tbselect id=identity(int,1,1),* into #temp from tb
select * from #temp