您现在的位置: 万盛学电脑网 >> 程序编程 >> 数据库 >> mssql数据库 >> 正文

SQL编程:存储过程+事务处理+回滚+数据迁移

作者:佚名    责任编辑:admin    更新时间:2022-06-22

   问题描述:

  最近给学校在做一个.NET网站,名字叫做文正学院过程化成绩录入系统,其中需要用到老用户登陆系统需要从旧系统里将以前存在的数据导入到新数据表中,

?

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 USE [new_wzjw] GO /****** Object:  StoredProcedure [dbo].[成绩管理_过程化成绩录入_数据迁移]    Script Date: 2014/3/16 22:55:38 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO   create proc [dbo].[成绩管理_过程化成绩录入_数据迁移]  @kcId jxrw_code/*自定义变量名*/ as begin       begin try         begin tran         INSERT INTO [web_inputCj_xsxkb]                 ([xh] ,[xm],[xxxzdm],[xxxzmc],[cjxzdm],[kcid],[lrsj],[manuAdd])             select xh, xm, xxxzdm,xxxzmc, cjxzdm, kcid, lrsj, manualAdd             from web_inputCj_cjb as a where a.kcId = @kcId             and not exists ( select * from web_inputCj_xsxkb as b                 where a.xh = b.xh and a.kcId = b.kcid )           commit tran         return 0       end try     begin catch         rollback tran         return 1     end catch   end