begin transaction
insert dbo.dtproperties (property) VALUES ('DtgSchemaOBJECT')
update dbo.dtproperties set objectid=@@identity 
where id=@@identity and property='DtgSchemaOBJECT'
commit
return @@identity

解决方案 »

  1.   


    其实这个就是一个插入,然后是更新操作。首先,把这个值'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'
      

  2.   

    dbo.dtproperties是什么意思?表名,你看看你的库是否有这个表
    'DtgSchemaOBJECT'是什么意思?这个表上的property列上,你将要插入的值
    objectid,id,以及property又是什么呢?这是dbo.dtproperties表上的三个列。用来查找复合条件的数据。整个逻辑是先插入一个值为'DtgSchemaOBJECT' 的数据到dbo.dtproperties表上property的列,然后获取这个表的自增ID,用@@identity函数获取,然后把这个数据的objectid也用@@identity函数填充
      

  3.   

    哈哈,多谢了!不好意思对SQL SERVER的存储过程一窍不通。多谢你的解答了,结贴了.
      

  4.   

    最后发现这个是MSSQL的官方案例,在用户自定义的存储过程竟然把官方案例原封不动地粘上去了。怪不得我没找到那几个字段的含义!