他的意思好像是说在插入时不是建表时 [code=SQL create table #tb(id int identity(1,1) PRIMARY KEY,col int) insert into #tb select 10insert into #tb select (select top 1 col+1 from #tb order by id desc)][/code] 不知道是不是这个意思还有想问下 select col from x where id= (select max(id) from x) select col from x order by id desc 哪个快啊?
他的意思好像是说在插入时不是建表时 create table #tb(id int identity(1,1) PRIMARY KEY,col int) insert into #tb select 10insert into #tb select (select top 1 col+1 from #tb order by id desc) 不知道是不是这个意思还有想问下 select col from x where id= (select max(id) from x) select col from x order by id desc 哪个快啊?
1> create table table1( 2> id int identity(1,1) primary key, 3> col varchar(10) 4> ); 5> insert into table1 (col) values ('A01'); 6> insert into table1 (col) values ('A02'); 7> insert into table1 (col) values ('A03'); 8> go(1 rows affected) 1> select * from table1; 2> go id |col -----------|---------- 1|A01 2|A02 3|A03(3 rows affected) 1> insert into table1 (col) values ('D04'); 2> go(1 rows affected) 1> select * from table1; 2> go id |col -----------|---------- 1|A01 2|A02 3|A03 4|D04(4 rows affected) 1>
create table tb(id int identity(1,1),name varchar(10))
insert into tb(name) values('a')
insert into tb(name) values('b')
goselect * From tb
select id=identity(int,0,1) into # from syscolumns a,syscolumns bselect * from #---------------
0
1
2
3
4
..
create table A ([id] int identity(1,1),[name] varchar(10))
IDENTITY [ ( seed , increment ) ]参数
seed装载到表中的第一个行所使用的值。increment增量值,该值被添加到前一个已装载的行的标识值上。必须同时指定种子和增量,或者二者都不指定。如果二者都未指定,则取默认值 (1,1)。
[code=SQL
create table #tb(id int identity(1,1) PRIMARY KEY,col int)
insert into #tb select 10insert into #tb select (select top 1 col+1 from #tb order by id desc)][/code]
不知道是不是这个意思还有想问下 select col from x where id= (select max(id) from x)
select col from x order by id desc
哪个快啊?
insert into #tb select 10insert into #tb select (select top 1 col+1 from #tb order by id desc)
不知道是不是这个意思还有想问下 select col from x where id= (select max(id) from x)
select col from x order by id desc
哪个快啊?
2> id int identity(1,1) primary key,
3> col varchar(10)
4> );
5> insert into table1 (col) values ('A01');
6> insert into table1 (col) values ('A02');
7> insert into table1 (col) values ('A03');
8> go(1 rows affected)
1> select * from table1;
2> go
id |col
-----------|----------
1|A01
2|A02
3|A03(3 rows affected)
1> insert into table1 (col) values ('D04');
2> go(1 rows affected)
1> select * from table1;
2> go
id |col
-----------|----------
1|A01
2|A02
3|A03
4|D04(4 rows affected)
1>