A Dangerous SQL

Source: Internet
Author: User

Look at this SQL, what's the problem?

<UpdateId="Update"ParameterType="Creativegroupdo">        UpdateDsp_creative_groupSetGmt_modified=Now ()<ifTest=The title!= NULL">, title=#{title,jdbctype=VARCHAR}        </if>        <ifTest="Clickurl!= NULL">, Click_url=#{clickurl,jdbctype=VARCHAR}        </if>        <where>            <ifTest="Creativegroupid!= NULL">                 andcreative_group_id=#{creativegroupid,jdbctype=BIGINT}            </if>        </where>    </Update>

The answer is already hidden in the gray-white font below. Please use your mouse to slide over the view.

I don't seem to have a problem, but what if creativegroupid = null? All Dsp_creative_group records will be updated with the title, Clickurl to the same value, resulting in data loss.  You never know when the application will set the creative_group_id to NULL, which is almost uncontrollable. For online systems, once such a thing happens, it is definitely a disaster-level failure. The lesson is: Always, never add an if condition in the WHERE clause of the update!

A Dangerous SQL

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.