写一条存储过程,实现往User中插入一条记录并返回当前UserId(自增长id) --推荐写法 if(Exists(select * from sys.objects where name=N'Usp_InsertedID')) drop proc Usp_InsertedID go create proc Usp_InsertedID as insert into [User] output inserted.UserID values(N'张三蛋',3) --另一种写法(SCOPE_IDEN…
原文:读取数据表中第m条到第n条的数据,SQL语句怎么写? 对于MySQL或者Oracle来说,如果实现从Table 表中取出第 m 条到第 n 条的记录操作,我们需要TOP函数(不是所有的数据库都支持TOP函数):Select Top子句 但是,你能想到几种方法? (1)使用not in Select TOP n-m+1 * FROM Table Where (id NOT IN (Select TOP m-1 id FROM Table )) (2)使用exists Select TOP…
假设对表 TXxxxxxxx 表新插入一条记录,然后要 SELECT 出刚刚插入的这条记录.可使用 SCOPE_IDENEITY(); 处理.具体代码参考如下: INSERT INTO TXxxxxxxx(...) VALUES(...) DECLARE @LastInsertId INT = 0; SET @LastInsertId = SCOPE_IDENTITY(); SELECT * FROM TGamePrizePoolWinRecord AS tppwr WHERE id = @La…