将MySql合并到MSSQL模式中

时间:2019-05-02 18:47:33

标签: mysql sql-server migration sql-server-migration-assi

我有2个数据库,一个在Sql Server上,一个在MySQL上,两者的定义略有不同。我需要做的是将MySQL中的定义合并到Sql Server中,而无需重新创建表。我正在使用Sql Server迁移助手,但它所做的第一件事是检查架构是否存在,如果存在,则将其删除。那不是我想要的。这是SSMA输出的示例。

IF EXISTS (SELECT * FROM sys.objects so JOIN sys.schemas sc ON so.schema_id = sc.schema_id WHERE so.name = N'opencall'  AND sc.name = N'dbo'  AND type in (N'U'))
BEGIN

  DECLARE @drop_statement nvarchar(500)

  DECLARE drop_cursor CURSOR FOR
      SELECT 'alter table '+quotename(schema_name(ob.schema_id))+
      '.'+quotename(object_name(ob.object_id))+ ' drop constraint ' + quotename(fk.name) 
      FROM sys.objects ob INNER JOIN sys.foreign_keys fk ON fk.parent_object_id = ob.object_id
      WHERE fk.referenced_object_id = 
          (
             SELECT so.object_id 
             FROM sys.objects so JOIN sys.schemas sc
             ON so.schema_id = sc.schema_id
             WHERE so.name = N'opencall'  AND sc.name = N'dbo'  AND type in (N'U')
           )

  OPEN drop_cursor

  FETCH NEXT FROM drop_cursor
  INTO @drop_statement

  WHILE @@FETCH_STATUS = 0
  BEGIN
     EXEC (@drop_statement)

     FETCH NEXT FROM drop_cursor
     INTO @drop_statement
  END

  CLOSE drop_cursor
  DEALLOCATE drop_cursor

  DROP TABLE [dbo].[opencall]
END 
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE 
[dbo].[opencall]
(
   [custom_l] real  NULL,
   [custom_k] real  NULL,
   [loggedbygroup] varchar(160)  NULL,
   [fk_authoriser] varchar(64)  NULL,
   [itsm_impact_level] varchar(50)  NULL,
   [itsm_urgency_level] varchar(50)  NULL,
   [flg_firsttimefix] int  NULL,
   [itsm_title] varchar(254)  NULL,
   [flg_requiresauth] int  NULL,
   [flg_authorised] int  NULL,
   [authanalyst] varchar(64)  NULL,
   [authdatex] int  NULL,
   [rfc_callref] int  NULL,
   [prb_callref] int  NULL,
   [c_ratingtxt] varchar(124)  NULL,
   [itsm_swtoday_on] int  NULL,
   [itsm_schedendx] int  NULL,
   [itsm_schedstartx] int  NULL,
   [custom_g] int  NULL,
   [custom_h] int  NULL,
   [custom_i] int  NULL,
   [custom_j] real  NULL,
   [custom_i1] varchar(512)  NULL,
   [custom_i2] varchar(512)  NULL,
   [custom_i3] varchar(512)  NULL,
   [custom_i4] varchar(512)  NULL,
   [custom_d1] varchar(512)  NULL,
   [custom_d2] varchar(512)  NULL,
   [custom_d3] varchar(512)  NULL,
   [custom_d4] varchar(512)  NULL,
   [companyname] varchar(128)  NULL,
   [fk_contract_id] varchar(124)  NULL,
   [fk_company_id] varchar(64)  NULL,
   [prb_state] varchar(32)  NULL,
   [itsm_wssm_on] int  NULL,
   [flg_resolve_incs] int  NULL,
   [flg_resolve_prbs] int  NULL,
   [fk_dept_code] varchar(254)  NULL,
   [flg_ke] int  NULL,
   [custom_f] varchar(164)  NULL,
   [custom_e] varchar(164)  NULL,
   [custom_d] varchar(164)  NULL,
   [custom_c] varchar(164)  NULL,
   [custom_b] varchar(164)  NULL,
   [custom_a] varchar(164)  NULL,
   [contact_id] varchar(64)  NULL,
   [workitemprogress] varchar(10)  NULL,
   [nextactdate] varchar(20)  NULL,
   [nextaction] int  NULL,
   [nextactdatex] int  NULL,
   [lastactdatex] int  NULL,
   [lastactdate] varchar(20)  NULL,
   [lastactby] varchar(20)  NULL,
   [commitdate] varchar(20)  NULL,
   [lastaction] int  NULL,
   [commitdatex] int  NULL,
   [assigncount] int  NULL,
   [origin] varchar(64)  NULL,
   [stateflags] int  NULL,
   [a_rating] int  NULL,
   [last_text] varchar(255)  NULL,
   [c_rating] int  NULL,
   [prob_text] varchar(255)  NULL,
   [callclass] varchar(64)  NULL,
   [extdetails] varchar(64)  NULL,
   [issueref] varchar(20)  NULL,
   [component] varchar(64)  NULL,
   [component_id] varchar(64)  NULL,
   [contact] varchar(64)  NULL,
   [compltdatx] int  NULL,
   [postcode] varchar(20)  NULL,
   [site] varchar(124)  NULL,
   [compltdate] varchar(20)  NULL,
   [respondbyx] int  NULL,
   [fixbyx] int  NULL,
   [completeby] varchar(20)  NULL,
   [closedatex] int  NULL,
   [assigndatx] int  NULL,
   [logdatex] int  NOT NULL,
   [withinfix] int  NULL,
   [totaltime] int  NULL,
   [withinresp] int  NULL,
   [fix_time] int  NULL,
   [resp_time] int  NULL,
   [fixby] varchar(20)  NULL,
   [respondby] varchar(20)  NULL,
   [fixcode] varchar(32)  NULL,
   [probcode] varchar(32)  NULL,
   [costcenter] varchar(64)  NULL,
   [rate] int  NULL,
   [slafix] int  NULL,
   [slaresp] int  NULL,
   [equipment] varchar(64)  NULL,
   [closedate] varchar(20)  NULL,
   [closedby] varchar(64)  NULL,
   [assigndate] varchar(20)  NULL,
   [logdate] varchar(20)  NULL,
   [loggedby] varchar(64)  NULL,
   [cust_name] varchar(124)  NULL,
   [cust_id] varchar(64)  NULL,
   [owner] varchar(64)  NULL,
   [suppgroup] varchar(160)  NULL,
   [assignment] varchar(255)  NULL,
   [tpcontract] varchar(64)  NULL,
   [priority] varchar(64)  NULL,
   [condition] int  NULL,
   [escalation] int  NULL,
   [status] int  NULL,
   [callref] int  NOT NULL,
   [appcode] varchar(16)  NULL,
   [customer_ref] varchar(200)  NULL,
   [third_party_email] varchar(100)  NULL,
   [third_party_reference] varchar(100)  NULL,
   [action_status] varchar(254)  NULL,
   [support_unit_cost] int  NULL,
   [emp_sick_reason] varchar(254)  NULL,
   [emp_sick_enddate] varchar(128)  NULL,
   [emp_sick_startdate] varchar(128)  NULL,
   [emp_sick_enddatex] int  NULL,
   [emp_sick_startdatex] int  NULL,
   [emp_sick_name] varchar(64)  NULL,
   [itsm_sladef] varchar(124)  NULL,
   [request_qty] int  NULL,
   [breach_text] varchar(255)  NULL,
   [itsm_catreq_type] varchar(254)  NULL,
   [itsm_prefered_text] varchar(64)  NULL,
   [bpm_placedonhold] int  NULL,
   [request_comp_price] varchar(254)  NULL,
   [request_comp_cost] varchar(254)  NULL,
   [request_sla_price] varchar(254)  NULL,
   [request_sla_cost] varchar(254)  NULL,
   [request_price] varchar(254)  NULL,
   [request_cost] varchar(254)  NULL,
   [itsm_fk_service] int  NULL,
   [itsm_tempemail] varchar(196)  NULL,
   [itsm_temptel] varchar(64)  NULL,
   [itsm_tempnote] varchar(254)  NULL,
   [itsm_requiredbyx] int  NULL,
   [cfh_nirn] varchar(64)  NULL,
   [bpm_progress_title] varchar(64)  NULL,
   [bpm_progress_fail] int  NULL,
   [bpm_progress] int  NULL,
   [bpm_progress_perc] int  NULL,
   [close_text] varchar(255)  NULL,
   [resolve_text] varchar(255)  NULL,
   [itsm_rfc_type] varchar(64)  NULL,
   [logcall_source] varchar(16)  NULL,
   [itsm_priority_level] varchar(50)  NULL,
   [itsm_selfservice_on] int  NULL,
   [itsm_thirdparty] int  NULL,
   [itsm_buildx] int  NULL,
   [itsm_testx] int  NULL,
   [itsm_reviewx] int  NULL,
   [itsm_workx] int  NULL,
   [resolve_datex] int  NULL,
   [resolve_date] varchar(64)  NULL,
   [itsm_status] varchar(124)  NULL,
   [bpm_stage_id] int  NULL,
   [bpm_workflow_id] varchar(124)  NULL,
   [bpm_status_id] varchar(124)  NULL,
   [bpm_timer_id] int  NULL,
   [bpm_waitingauth] int  NULL,
   [bpm_waitingtasks] int  NULL,
   [bpm_stage_title] varchar(124)  NULL,
   [itsm_prefered_suppgroup] varchar(64)  NULL,
   [temp] varchar(100)  NULL,
   [bpm_task_title] varchar(124)  NULL,
   [bpm_parentcallref] int  NULL,
   [bpm_managerid] varchar(64)  NULL,
   [callback_callref] varchar(16)  NULL,
   [callback_telephone] varchar(32)  NULL,
   [bpm_laction] varchar(32)  NULL,
   [bpm_lactionbytype] varchar(32)  NULL,
   [bpm_lactionres] varchar(64)  NULL,
   [bpm_lactionbyid] varchar(64)  NULL,
   [bpm_execvpme] int  NULL,
   [newequiptype] varchar(254)  NULL,
   [flg_tempfix] int  NULL,
   [itsm_majorinc] varchar(16)  NULL,
   [bpm_task_id] int  NULL,
   [bpm_seq_task] int  NULL,
   [itsm_slaname] varchar(254)  NULL,
   [probcodedesc] varchar(254)  NULL,
   [sm_tw_resp_act] varchar(255)  NULL,
   [flg_ila_complete] int  NULL,
   [ila_weighting] int  NULL,
   [requested_start_datex] int  NULL,
   [requested_end_datex] int  NULL,
   [itsm_rfc_timing] varchar(32)  NULL,
   [esc_email_sent] int  NULL,
   [itsm_sched_datex] int  NULL,
   [resolvedby] varchar(64)  NULL,
   [resolvedbygroup] varchar(160)  NULL,
   [closedbygroup] varchar(160)  NULL,
   [WR_Target_Release] varchar(254)  NULL,
   [WR_Status] varchar(254)  NULL,
   [WR_LOE] varchar(254)  NULL,
   [WR_Priority] varchar(254)  NULL
)
WITH (DATA_COMPRESSION = NONE)
GO
IF EXISTS (SELECT * FROM sys.objects so JOIN sys.schemas sc ON so.schema_id = sc.schema_id WHERE so.name = N'opencall_callref'  AND sc.name = N'dbo'  AND type in (N'PK'))
ALTER TABLE [dbo].[opencall] DROP CONSTRAINT [opencall_callref]
 GO



ALTER TABLE [dbo].[opencall]
 ADD CONSTRAINT [opencall_callref]
   PRIMARY KEY
   CLUSTERED ([callref] ASC)

GO

0 个答案:

没有答案