一个存储过程(事务),请大家看看是否有误。(20分)

V

vinge

Unregistered / Unconfirmed
GUEST, unregistred user!
向两个表中插入数据,返回第一个表的自动编号。<br> begin transaction<br> &nbsp; &nbsp; &nbsp;insert into Codes_Codes(CategoryID,Title,AuthorID,Codes,Notes)<br> &nbsp; &nbsp; &nbsp;values(@CategoryID,@Title,@AuthorID,@Codes,@Notes)<br> &nbsp; &nbsp; &nbsp;set @CodeID = @@Identity &nbsp; //放在这?如果放在最后是不是就不知道是那个表的编号了?<br> &nbsp; &nbsp; &nbsp;insert into Codes_History(MenderID,[Action],Content,[Date])<br> &nbsp; &nbsp; &nbsp;values(@AuthorID,'Insert',@Codes,getdate())<br> &nbsp; commit transaction<br> &nbsp; return @CodeID <br><br>请大家指教。
 
@@Identity是返回上一个插入的标识值,如果你后面的表也有标识列,自然@@Identity就会变成后面表的最新标识值了
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
827
DelphiTeacher的专栏
D
顶部