--------------------------------------添加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 )