begin transaction
insert dbo.dtproperties (property) VALUES ('DtgSchemaOBJECT')
update dbo.dtproperties set objectid=@@identity
where id=@@identity and property='DtgSchemaOBJECT'
commit
return @@identity
insert dbo.dtproperties (property) VALUES ('DtgSchemaOBJECT')
update dbo.dtproperties set objectid=@@identity
where id=@@identity and property='DtgSchemaOBJECT'
commit
return @@identity
其实这个就是一个插入,然后是更新操作。首先,把这个值'DtgSchemaOBJECT' 插入到表dtproperties的 字段property 中。然后,是update表dtproperties的objectid字段,你的dtproperties表,应该是包含了一个identity,也就是自增列,当上面插入了记录后,@@identity中就保存了,插入到你的自增列中的值,于是,通过条件where id=@@identity and property='DtgSchemaOBJECT',来找到这条刚刚插入的记录,更新objectid为@@identity 的值,不过这个update语句完全可以写成:update dbo.dtproperties set objectid=id
where id=@@identity and property='DtgSchemaOBJECT'
'DtgSchemaOBJECT'是什么意思?这个表上的property列上,你将要插入的值
objectid,id,以及property又是什么呢?这是dbo.dtproperties表上的三个列。用来查找复合条件的数据。整个逻辑是先插入一个值为'DtgSchemaOBJECT' 的数据到dbo.dtproperties表上property的列,然后获取这个表的自增ID,用@@identity函数获取,然后把这个数据的objectid也用@@identity函数填充