不必要的mysql列更新

时间:2012-01-25 19:30:10

标签: php sql

我有一张包含学生信息的表Study,可以在屏幕截图中看到。 然后我编写了以下查询来更新study_start下面行的study_id = 501列:

UPDATE 
    student,language_german,language_english,study,home_university,
    host_university,transfer,home_address,host_address,alumni
SET
    firstname = 'Omega',
    lastname = 'Rugal',
    birthdate = '0000-00-00',
    nationality = '',
    email= '',
    group_name = '', 
    gender = '',
    religion = '',
    creation_date = NOW(),                          
    user_id = 43,

    german_level = '',
    german_status = '',
    german_grade = '',

    english_level = '',
    english_status = '',
    english_grade = '',

    transfer_type = '',
    study_start = "2013-02-01",
    matriculation_no = '0',                              
    application_no = '0',
    applicationno_old = '0',
    overall_status = '',
    status_date = '0000-00-00',
    comment = ' ',
    thesis_status = '',

    home_university_name = '',
    home_degree_program = '',
    home_study_program = '',

    host_university_name = '',
    host_degree_program = '',
    host_study_program = '',

    room_status = '',
    room_deposit = '0',
    room_name = '',
    application_letter_home = '0',
    motivation = '',
    sponsorship = '',
    application_letter_abroad = '0',
    cv = '0',
    result = '',
    learning_agreement = '0',
    health_insurance = '0',
    supervisor_home = '',
    supervisor_abroad = '',
    visa = '0',
    vaccination = '0',
    wishlist = '',

    home_street = '',
    home_co = '',
    home_zip = '',
    home_city = '',
    home_state = '',
    home_country = '',

    host_street = '',
    host_co = '',
    host_zip = '',
    host_city = '',
    host_state = '',
    host_country = '',

    thesis_grade = '0.0',
    average_grade = '0.0',
    study_time = '0',
    last_email = '',
    last_contact = '0000-00-00',
    last_info = ''
WHERE
    student.student_id = language_german.student_id
    AND student.student_id = language_english.student_id
    AND study.study_id = home_university.study_id
    AND study.study_id = host_university.study_id
    AND student.student_id = transfer.student_id
    AND student.student_id = home_address.student_id
    AND student.student_id = host_address.student_id
    AND student.student_id = alumni.student_id
    AND student.student_id = 832

其中student_id是每个学生的唯一ID。

可怕的是,其他行的所有列都使用此值study_start更新,这是不正常的。

1 个答案:

答案 0 :(得分:1)

您的更新更新的内容远远超过study_start。您错过了将study与特定student_id相关联的联接。是否有university_idstudenthome_university或其他内容相关联?

你真的需要加入所有这些表吗?如果你知道study_id

,为什么不能这样做呢?
UPDATE study set study_start='2013-02-01' where study_id=501;