create table Dingdan
(
Did int identity(1,1) primary key,
D_cid int not null ,
Dcount int not null,
Dtime datetime not null,
foreign key(D_cid) references customer(Cid)
)insert into Dingdan (D_cid,Dcount,Dtime) values (34,340,getdate())表:
Did D_cid Dcount Dtime
...........
5 34 340 2010-11-01 18:18:18.181
如何得到这个最新增加的一行的Did,也就是自增ID?
(
Did int identity(1,1) primary key,
D_cid int not null ,
Dcount int not null,
Dtime datetime not null,
foreign key(D_cid) references customer(Cid)
)insert into Dingdan (D_cid,Dcount,Dtime) values (34,340,getdate())表:
Did D_cid Dcount Dtime
...........
5 34 340 2010-11-01 18:18:18.181
如何得到这个最新增加的一行的Did,也就是自增ID?
select max(did) from table
select * from table where did=(select max(did) from table)--如果都是按照getdate()插入的话还可以
select * from table where Dtime=(select max(Dtime) from table)
select SCOPE_IDENTITY() as NewID