2013-03-08 71 views
1

我有一个150万记录在一个临时表,我想要插入到主表中的一个内部联接的MySQL表。问题,而试图插入一个表到另一个

我的代码有效,但它停在103,613条记录。 IT不会继续。为什么会停止?为什么它不会一路走到最后?

这是我当前的代码

INSERT INTO phone_calls(next_attempt, created_on, modified_on, status, call_subject, 
account_number, call_code, last_attempt_on, total_attempts, account_id 

,team_id 
,campaign_id 
,call_code_id 
,result_code 
,result_code_id 
,time_zone_id 
,trigger_on 
,first_attempt_on 
,first_attempt_by 
,last_attempt_by 
,modified_by 
,client_id 
,last_call_id 
,call_notes 
,owner_id 
,industry_id 
) 


SELECT 
CASE WHEN next_attempt IS NULL OR next_attempt = '' THEN STR_TO_DATE(replace(t.next_attempt,'/',','),'%m,%d,%Y %T') END as next_attempt, 
CASE WHEN t.created_on IS NULL OR t.created_on = '' THEN '0000-00-00 00:00:00' ELSE STR_TO_DATE(replace(t.created_on,'/',','),'%m,%d,%Y %T') END as created_on, 
CASE WHEN t.modified_on IS NULL OR t.modified_on = '' THEN '0000-00-00 00:00:00' ELSE STR_TO_DATE(replace(t.modified_on,'/',','),'%m,%d,%Y %T') END AS modified_on, 
CONVERT(CASE WHEN t.status IS NULL OR t.status = '' THEN 0 ELSE t.status END, UNSIGNED INTEGER) AS status, 
LEFT(IFNULL(t.call_subject, ''), 100), 
t.account_number, 
CONVERT(CASE WHEN t.callcode IS NULL OR t.callcode = '' THEN 0 ELSE t.callcode END , UNSIGNED INTEGER) AS callcode, STR_TO_DATE(replace(t.last_attempt_on,'/',','),'%m,%d,%Y %T') as last_attempt_on, 
CONVERT(CASE WHEN t.New_Attempts IS NULL OR t.New_Attempts = '' THEN 0 ELSE t.New_Attempts END , UNSIGNED INTEGER) AS New_Attempts, 
a.account_id 
,0 
,0 
,0 
,0 
,0 
,0 
, '0000-00-00 00:00:00' 
, '0000-00-00 00:00:00' 
,1 
,1 
,1 
,1 
,0 
,'IMPORTED FROM CRM' 
,1 
,1 
FROM tmp_table_for_rdi_cms AS t 
INNER JOIN accounts AS a ON a.account_number = t.account_number LIMIT 9999999999; 
these 2 fields are indexed so it runs fast 
a.account_number 
t.account_number 

现在,我知道我将没有任何价值,有一个类型,如果无符号整数某些领域但这是没关系,我会在以后的时间来更新这个。

如何执行此INSERT INTO查询而不丢失任何记录?

回答

0

“没有默认值”的问题在于源表中的新列的空值定义为S NOT NULL ,它们没有使用默认值定义。

你有三种选择来解决这个问题:

  1. 定义目标列的空能(离开了NOT NULL)
  2. 定义目标列具有缺省值,即NOT NULL DEFAULT 'some value'
  3. 提供如果该列是空的值,即SELECT ifnull(source_column, 'some value)

截断不正确INTEGER值的问题,您是从一个char值选择,并把它放在一个int列,但有些vyes是空白的,所以你需要处理的是:

select if(source_column = '', 0, source_column) 

数据截断列问题是否存在,是因为源值比目标列可容纳的更大/更长。为了解决这个问题,将你的目标列定义为更大(bigint而不是int)或更长(例如text或varchar(80)而不是varchar(20))