我是一個漂亮的綠色新手,仍然是SQL,並且任務非常繁瑣。我需要將tableA中61列中的58列移到tableB中。 tableA有61列,只有15行,tableB現在有58列和零行。我已經閱讀了關於如何實現這一點的多個源文件(將數據從一個表格移動到相關表格),但沒有一個具體談論我正在處理的這個特定情況。MySQL:將數據從61列表移動到58列表
使事情變得更加複雜,第二個表沒有與第一個表的順序相同的列,所以這也帶來了問題。這個SO帖子看起來很有希望,但它正在使用一個相當小的數據集:SQL: Move column data to other table in same relation。這一個也是類似的MYSQL - Move data from one table to a related one?。問題是他們都從一張小桌子移到一張更大的桌子上,而不是面對面。
這裏是我的企圖使這一過渡發生(和不成功的包括錯誤指示)初始查詢:
INSERT INTO tableB SELECT * FROM tableA;
ERROR 1136 (21S01): Column count doesn't match value count at row 1
tableA
+-------------------------------+------------------+------+-----+-------------------+-----------------------------+
| Field | Type | Null | Key | Default | Extra |
+-------------------------------+------------------+------+-----+-------------------+-----------------------------+
| id | int(11) unsigned | NO | PRI | NULL | auto_increment |
| staff_fk | int(11) unsigned | NO | | NULL | |
| hire_date | date | NO | | NULL | |
| position | varchar(75) | NO | | NULL | |
| manager | varchar(75) | NO | | NULL | |
| employment_application | char(1) | NO | | i | |
| resume | char(1) | NO | | i | |
| references_checked | char(1) | NO | | i | |
| new_hire_letter | char(1) | NO | | i | |
| clinical_training_initiated | char(1) | NO | | i | |
| name_badge_ordered | char(1) | NO | | i | |
| keycode_access | char(1) | NO | | i | |
| tf_up_setup | char(1) | NO | | i | |
| un_pw_setup | char(1) | NO | | i | |
| drug_screen | char(1) | NO | | i | |
| background_investigation | char(1) | NO | | i | |
| licenses_education_verified | char(1) | NO | | i | |
| cpr | char(1) | NO | | i | |
| clinic_tour_introductions | char(1) | NO | | i | |
| sick_tardy_phone_notification | char(1) | NO | | i | |
| work_sched_start_time | char(1) | NO | | i | |
| paydays | char(1) | NO | | i | |
| ds_pto | char(1) | NO | | i | |
| attendance_tardiness | char(1) | NO | | i | |
| evacuation_plan | char(1) | NO | | i | |
| osha | char(1) | NO | | i | |
| emp_handbook_receipt | char(1) | NO | | i | |
| internet_email_phone_usage | char(1) | NO | | i | |
| parking_building_access | char(1) | NO | | i | |
| dress_grooming | char(1) | NO | | i | |
| inclement_weather | char(1) | NO | | i | |
| mileage | char(1) | NO | | i | |
| hipaa_training | char(1) | NO | | i | |
| direct_deposit_auth | char(1) | NO | | i | |
| i9 | char(1) | NO | | i | |
| w4 | char(1) | NO | | i | |
| valid_id | char(1) | NO | | i | |
| update_ext_list | char(1) | NO | | i | |
| emerg_contact_form | char(1) | NO | | i | |
| med_dent_life_vision | char(1) | NO | | i | |
| 401k_pen_sh | char(1) | NO | | i | |
| centricity_access | char(1) | NO | | i | |
| centricity_training | char(1) | NO | | i | |
| phone_training | char(1) | NO | | i | |
| create_active_dir_account | char(1) | NO | | i | |
| email_access | char(1) | NO | | i | |
| drive_access | char(1) | NO | | i | |
| mcafee | char(1) | NO | | i | |
| hr_enrollment_forms | char(1) | NO | | i | |
| ds_signoff | char(1) | NO | | i | |
| ds_clincial_signoff | char(1) | NO | | i | |
| completed | datetime | YES | | NULL | |
| created | datetime | NO | | NULL | |
| last_update | timestamp | NO | | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP |
| portal_access | char(1) | NO | | i | |
| harvest | char(1) | NO | | i | |
| imms_link | char(1) | NO | | i | |
| eprescribe | char(1) | NO | | i | |
| state_alert_access | char(1) | NO | | i | |
| phone_agent | char(1) | NO | | i | |
| pc_tablet_setup | char(1) | NO | | i | |
+-------------------------------+------------------+------+-----+-------------------+-----------------------------+
61 rows in set (0.00 sec)
tableB:
+-------------------------------+------------------+------+-----+-------------------+-----------------------------+
| Field | Type | Null | Key | Default | Extra |
+-------------------------------+------------------+------+-----+-------------------+-----------------------------+
| id | int(11) unsigned | NO | PRI | NULL | auto_increment |
| staff_fk | int(11) unsigned | NO | | NULL | |
| employment_application | char(1) | NO | | i | |
| resume | char(1) | NO | | i | |
| references_checked | char(1) | NO | | i | |
| new_hire_letter | char(1) | NO | | i | |
| clinical_training_initiated | char(1) | NO | | i | |
| name_badge_ordered | char(1) | NO | | i | |
| keycode_access | char(1) | NO | | i | |
| tf_up_setup | char(1) | NO | | i | |
| un_pw_setup | char(1) | NO | | i | |
| drug_screen | char(1) | NO | | i | |
| background_investigation | char(1) | NO | | i | |
| licenses_education_verified | char(1) | NO | | i | |
| cpr | char(1) | NO | | i | |
| clinic_tour_introductions | char(1) | NO | | i | |
| sick_tardy_phone_notification | char(1) | NO | | i | |
| work_sched_start_time | char(1) | NO | | i | |
| paydays | char(1) | NO | | i | |
| ds_pto | char(1) | NO | | i | |
| attendance_tardiness | char(1) | NO | | i | |
| evacuation_plan | char(1) | NO | | i | |
| osha | char(1) | NO | | i | |
| emp_handbook_receipt | char(1) | NO | | i | |
| internet_email_phone_usage | char(1) | NO | | i | |
| parking_building_access | char(1) | NO | | i | |
| dress_grooming | char(1) | NO | | i | |
| inclement_weather | char(1) | NO | | i | |
| mileage | char(1) | NO | | i | |
| hipaa_training | char(1) | NO | | i | |
| direct_deposit_auth | char(1) | NO | | i | |
| i9 | char(1) | NO | | i | |
| w4 | char(1) | NO | | i | |
| valid_id | char(1) | NO | | i | |
| update_ext_list | char(1) | NO | | i | |
| emerg_contact_form | char(1) | NO | | i | |
| med_dent_life_vision | char(1) | NO | | i | |
| 401k_pen_sh | char(1) | NO | | i | |
| centricity_access | char(1) | NO | | i | |
| centricity_training | char(1) | NO | | i | |
| phone_training | char(1) | NO | | i | |
| create_active_dir_account | char(1) | NO | | i | |
| email_access | char(1) | NO | | i | |
| drive_access | char(1) | NO | | i | |
| mcafee | char(1) | NO | | i | |
| portal_access | char(1) | NO | | i | |
| harvest | char(1) | NO | | i | |
| imms_link | char(1) | NO | | i | |
| eprescribe | char(1) | NO | | i | |
| state_alert_access | char(1) | NO | | i | |
| phone_agent | char(1) | NO | | i | |
| pc_tablet_setup | char(1) | NO | | i | |
| hr_enrollment_forms | char(1) | NO | | i | |
| ds_signoff | char(1) | NO | | i | |
| ds_clincial_signoff | char(1) | NO | | i | |
| completed | datetime | YES | | NULL | |
| created | timestamp | NO | | CURRENT_TIMESTAMP | |
| last_update | timestamp | NO | | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP |
+-------------------------------+------------------+------+-----+-------------------+-----------------------------+
58 rows in set (0.01 sec)
我會包括的模式,如果有人想看看他們。
我想知道是否有一種方法可以做到這一點,而不必在INSERT INTO語句中明確標註每一列。任何幫助將不勝感激!
nah。只需放上一個好的播放列表並剪切並粘貼名稱即可。 – Drew
Bill Karwin您看到的結果來自「describe tableA」和「describe tableB」命令。我向你保證,模式分別是61列和58列。我將編輯問題以包含這些命令的完整結果。 – TomJ
啊,以前不清楚你是在查詢'describe'而不是'select'。對於在您寫回復時刪除我的問題,我表示抱歉。 –