- /*建立traddeinfo表各相关索引,注意Trade_id字段必段是identity型*/
- create table Tradeinfo(Trade_id int identity(1,1),Tdtime datetime Tdname varchar(20))
- create index idx_trade_id on tradeinfo(trade_id)
- /*使用scope_identity()中断函数,取得当前脚本范围内最后insert进去的identity值*/
- declare @mytradeid int
- set @mytradeid=0
- begin transaction
- insert into tradeinfo values(getdata(),'test')
- select @mytradeid = Scope_identite()
- commit transaction
- /*把@mytradeid 变量中存放的流水号显示出来*/
- select @mytradeid
复制代码 |