sql语句如何在insert一条数据后直接返回刚刚插入的数据的ID

原文链接:http://blog.csdn.net/lllkey/article/details/7079277


在insert语句之后加上:

  1. SELECT @@IDENTITY  
           SELECT @@IDENTITY

就可以立即得到之前insert数据的ID

如:

  1. insert into news(newsTitle,newsContent)  
  2.       values('title','content')  
  3. select @@identity  

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章