create table tmp(id varchar(10),name varchar(10),sex varchar(2))
insert tmp values('001','张三','男')
insert tmp values('002','李四' ,'男')
insert tmp values('003','刘芳' ,'女')
select identity(int) no,* into #tmp from tmp
如果你在执行select identity(int) no,* into #tmp from tmp这条语句的时候报错,
那是因为你的DB中间的select into/bulkcopy属性没有打开要先执行:
exec sp_dboption 你的DB名字,'select into/bulkcopy',true
select * from #tmp where identitycol=2 --当表中含有identity列的时候可以使用关键字identity来引用该列。
select * from #tmp where no=2
http://www.itpub.net/showthread.php?threadid=173159
|