Modify SQL Server values in batches

Source: Internet
Author: User
To modify the value of a field, the original value is 1, And now it must be changed to 0. Can I understand that, as long as all data with the field value of 1 is changed to 0? If so, assume that the field to be modified is Name and the code is: 1 Update [Table Name] Set [Name] 02 Where [ID] in3 (4 Select [ID] from

To modify the value of a field, the original value is 1, And now it must be changed to 0. Can I understand that, as long as all data with the field value of 1 is changed to 0? If so, I assume that the field to be modified is Name and the code is: 1 Update [Table Name] Set [Name] = '0' 2 Where [ID] in 3 (4 Select [ID] from

To modify the value of a field, the original value is 1, And now it must be changed to 0.

Can I understand that, as long as all data with the field value of 1 is changed to 0?

If so, I assume that the field to be modified is Name,

Code:

1 Update [Table Name] Set [Name] = '0'
2 Where [ID] in
3 (
4 Select [ID] from [Table Name] where [Name] = '1'
5)

Explain the Code:

First, no matter how many data records you want to modify, you only need to make sure that all data whose field value is 1 is changed to 0, and the ID is unique, therefore, you can find all the ID values of the data you want to modify based on this condition. If the ID is unique, you can modify the field value based on the ID.

Hope to help you ~

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.