因为要用到回收站功能,删除一条记录,要先放到一个delete表中,以便以后恢复
要求:
1、delete表要比被删除表中多三项(用于表明删除用户,删除的是哪种用户表,删除该条数据在该用户表中的id)
2、用户表有多张(一个部门一张,但是一个部门又有多个用户,所有设计数据库时,回收站表只设置了一张,因为如果每一部门设置一张delete表,那么有很多跨部门操作,数据库最后终于一个用户的回收站里面记录整理起来很麻烦)
3、表中的记录项很多,有40多个属性,所有如果有程序来实现,数据量太大,会出现不可预期的错误,不得不用存储过程
因为自己对存储过程也不熟悉,一边写,一边学习,用了将近一天的时间,终于搞定了,其中主要难题:
1、数据存放到临时变量中,
2、对其中一个变量——表的调用
现在把存储过程放起来,也是对我自己一天工作的肯定,高手不要见笑
ALTER PROCEDURE [dbo].[copy_data]
@tablename varchar(30),
@t_id int ,
@u_id int
as
set nocount on
declare @tm varchar(500)
declare @jh int
declare @ajh int
declare @gjz varchar(100)
declare @sjms varchar(5000)
declare @fsdd varchar(100)
declare @fsrq nchar(10)
declare @zyrw varchar(1000)
declare @psz varchar(20)
declare @psrq nchar(10)
declare @tgz varchar(50)
declare @zrz varchar(50)
declare @sc nchar(4)
declare @ly varchar(8)
declare @cjh varchar(20)
declare @srz nchar(10)
declare @flh int
declare @dph nchar(10)
declare @bz varchar(500)
declare @xpdx bigint
declare @xpgs nchar(10)
declare @xpxs nchar(11)
declare @scrid int
declare @scr nchar(10)
declare @scsj datetime
declare @scbm int
declare @shr nchar(10)
declare @shsj datetime
declare @ecbz varchar(500)
declare @gdr nchar(10)
declare @gdsj datetime
declare @xgsj datetime
declare @flag nchar(1)
declare @ysurl varchar(100)
declare @ysfile varchar(250)
declare @xgurl varchar(100)
declare @xgfile varchar(250)
declare @xwurl varchar(500)
declare @xwnr varchar(4000)
declare @textall varchar(4000)
declare @fei nvarchar(4000)
set @fei=N'select @tm=[tm]
,@jh=[jh]
,@ajh=[ajh]
,@gjz=[gjz]
,@sjms=[sjms]
,@fsdd=[fsdd]
,@fsrq=[fsrq]
,@zyrw=[zyrw]
,@psz=[psz]
,@psrq=[psrq]
,@tgz=[tgz]
,@zrz=[zrz]
,@sc=[sc]
,@ly=[ly]
,@cjh=[cjh]
,@srz=[srz]
,@flh=[flh]
,@dph=[dph]
,@bz=[bz]
,@xpdx=[xpdx]
,@xpgs=[xpgs]
,@xpxs=[xpxs]
,@scrid=[scrid]
,@scr=[scr]
,@scsj=[scsj]
,@scbm=[scbm]
,@shr=[shr]
,@shsj=[shsj]
,@ecbz=[ecbz]
,@gdr=[gdr]
,@gdsj=[gdsj]
,@xgsj=[xgsj]
,@flag=[flag]
,@ysurl=[ysurl]
,@ysfile=[ysfile]
,@xgurl=[xgurl]
,@xgfile=[xgfile]
,@xwurl=[xwurl]
,@xwnr=[xwnr]
,@textall=[textall]
from ['+@tablename+N'] where id='+CAST(@t_id AS varchar(10))
exec sp_executesql @fei,
<a href="mailto:N%27@tm" target="_blank">N'@tm</a> varchar(500) OUT,
@jh int OUT,
@ajh int OUT,
@gjz varchar(100) OUT,
@sjms varchar(5000) OUT,
@fsdd varchar(100) OUT,
@fsrq nchar(10) OUT,
@zyrw varchar(1000) OUT,
@psz varchar(20) OUT,
@psrq nchar(10) OUT,
@tgz varchar(50) OUT,
@zrz varchar(50) OUT,
@sc nchar(4) OUT,
@ly varchar(8) OUT,
@cjh varchar(20) OUT,
@srz nchar(10) OUT,
@flh int OUT,
@dph nchar(10) OUT,
@bz varchar(500) OUT,
@xpdx bigint OUT,
@xpgs nchar(10) OUT,
@xpxs nchar(11) OUT,
@scrid int OUT,
@scr nchar(10) OUT,
@scsj datetime OUT,
@scbm int OUT,
@shr nchar(10) OUT,
@shsj datetime OUT,
@ecbz varchar(500) OUT,
@gdr nchar(10) OUT,
@gdsj datetime OUT,
@xgsj datetime OUT,
@flag nchar(1) OUT,
@ysurl varchar(100) OUT,
@ysfile varchar(250) OUT,
@xgurl varchar(100) OUT,
@xgfile varchar(250) OUT,
@xwurl varchar(500) OUT,
@xwnr varchar(5000) OUT,
@textall varchar(5000) OUT',
@tm OUT,
@jh OUT,
@ajh OUT,
@gjz OUT,
@sjms OUT,
@fsdd OUT,
@fsrq OUT,
@zyrw OUT,
@psz OUT,
@psrq OUT,
@tgz OUT,
@zrz OUT,
@sc OUT,
@ly OUT,
@cjh OUT,
@srz OUT,
@flh OUT,
@dph OUT,
@bz OUT,
@xpdx OUT,
@xpgs OUT,
@xpxs OUT,
@scrid OUT,
@scr OUT,
@scsj OUT,
@scbm OUT,
@shr OUT,
@shsj OUT,
@ecbz OUT,
@gdr OUT,
@gdsj OUT,
@xgsj OUT,
@flag OUT,
@ysurl OUT,
@ysfile OUT,
@xgurl OUT,
@xgfile OUT,
@xwurl OUT,
@xwnr OUT,
@textall OUT;
INSERT INTO [yx].[dbo].[S_del]
([t_id]
,[u_id]
,[u_t]
,[tm]
,[jh]
,[ajh]
,[gjz]
,[sjms]
,[fsdd]
,[fsrq]
,[zyrw]
,[psz]
,[psrq]
,[tgz]
,[zrz]
,[sc]
,[ly]
,[cjh]
,[srz]
,[flh]
,[dph]
,[bz]
,[xpdx]
,[xpgs]
,[xpxs]
,[scrid]
,[scr]
,[scsj]
,[scbm]
,[shr]
,[shsj]
,[ecbz]
,[gdr]
,[gdsj]
,[xgsj]
,[flag]
,[ysurl]
,[ysfile]
,[xgurl]
,[xgfile]
,[xwurl]
,[xwnr]
,[textall])
VALUES
(
@t_id,
@u_id,
@tablename,
@tm ,
@jh ,
@ajh ,
@gjz ,
@sjms ,
@fsdd ,
@fsrq ,
@zyrw ,
@psz ,
@psrq ,
@tgz ,
@zrz ,
@sc ,
@ly ,
@cjh ,
@srz ,
@flh ,
@dph ,
@bz ,
@xpdx ,
@xpgs ,
@xpxs ,
@scrid ,
@scr ,
@scsj ,
@scbm ,
@shr ,
@shsj ,
@ecbz ,
@gdr ,
@gdsj ,
@xgsj ,
@flag ,
@ysurl ,
@ysfile ,
@xgurl ,
@xgfile ,
@xwurl ,
@xwnr ,
@textall
)
set nocount off
从企业管理器中直接导出来的,现在看看也没有什么难的哦,只是因为自己不熟悉,而使得自己在项目时间本来就是很紧张的情况下还因为这个而浪费了不少的时间。