• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
机灵小不懂
博客园    首页    新随笔    联系   管理    订阅  订阅

Form数据迁移

--------------------------------------添加linkserver---------------------------------------
--EXEC master.dbo.sp_addlinkedserver @server = server', @srvproduct=N'SQL Server' 
--EXEC master.dbo.sp_addlinkedsrvlogin @rmtsrvname=N'server',@useself=N'False',
--@locallogin=NULL,@rmtuser=N'sa',@rmtpassword='XXXX'

--------------------------------------动态表单迁移------------------------------------------
DECLARE @form_Label NVARCHAR(30)
DECLARE @form_Table NVARCHAR(30)
DECLARE @strsql_InsertFormTable_Org NVARCHAR(200)
DECLARE @strsql_InsertFormTable_Tag NVARCHAR(200)

SET @form_Label='细胞学检查%'
SET @form_Table=(select table_name from [server].[bio-d].dbo.forms where label like @form_Label)
SET @strsql_InsertFormTable_Org='select * into '+@form_Table+' from [server].[bio-d].dbo.'+@form_Label
SET @strsql_InsertFormTable_Tag='select * from '+@form_Table

-- forms子表单结构表结构及数据
exec(@strsql_InsertFormTable_Org)
exec(@strsql_InsertFormTable_Tag)

--检查添加是否成功
select * from [server].[bio-d].dbo.forms where label like @form_Label
select * from forms where label like @form_Label

-- Forms表中记录的插入
SET IDENTITY_INSERT forms ON
insert into forms(id,label,name,table_name,type,collect_type,deleted,crt_time,crt_user,crt_user_name,upd_time,upd_user,upd_user_name,display_fields_in,bio_type) 
select id,label,name,table_name,type,collect_type,deleted,crt_time,crt_user,crt_user_name,upd_time,upd_user,upd_user_name,display_fields_in,bio_type from  [server].[bio-d].dbo.forms where label like @form_Label
SET IDENTITY_INSERT forms OFF

-- 检查Form表中记录插入是否正确
select * from [172.18.1.25].[bio-d].dbo.forms where label like @form_Label
select * from forms where label like @form_Label

-- fields字段中值的插入
--select * from [server].[bio-d].dbo.fields where form_id in (select id from [server].[bio-d].dbo.forms where label like @form_Label )
--select * from fields where form_id=67

SET IDENTITY_INSERT fields ON
insert into fields(id,label,name,form_id,data_type,required,deleted,child_form_id,field_name,crt_time,crt_user,crt_user_name,upd_time,upd_user,upd_user_name,validation,options,validation_msg,standalone_id,link_field_id,sort,default_value) 
select id,label,name,form_id,data_type,required,deleted,child_form_id,field_name,crt_time,crt_user,crt_user_name,upd_time,upd_user,upd_user_name,validation,options,validation_msg,standalone_id,link_field_id,sort,default_value from [server].[bio-d].dbo.fields  where form_id in (select id from [server].[bio-d].dbo.forms where label like @form_Label )
SET IDENTITY_INSERT fields OFF

-- 验证插入是否正确
select * from [server].[bio-d].dbo.fields where form_id in (select id from [server].[bio-d].dbo.forms where label like @form_Label )
select * from fields where form_id in (select id from forms where label like @form_Label )

 

posted @ 2019-02-20 13:40  机灵小不懂  阅读(425)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3