说我有这个MYBATIS声明:
<insert id="insertValue" resultType="car" >
BEGIN TRANSACTION
INSERT INTO table1 ( somefield,... ) VALUES ( #{value},... );
<selectKey keyProperty="carId" resultClass="int">
SELECT @@IDENTITY as carId
</selectKey>
UPDATE table2
set fieldx = #{carId}
where table2Id = 500;
COMMIT
</insert>
我为carId获取值0,应该是刚刚添加到table1中的记录的关键
如何获取最近生成的keyValue以供立即使用?
答案 0 :(得分:0)
我认为你想要做的是:
insert table1 ......
declare @var int
set @var= scope_identity()
update table2 set ... where id = @var