An interesting bit-bit computing sharing _mssql SQL Server

Source: Internet
Author: User
Instead of the bool type in SQL Server, a bit type is used to represent the bool value, presumably to conserve storage space.

However, to achieve the reverse operation seems to be troublesome to write, such as the following statements are not possible: Update category set Visible=not visible where id=1, because visible is bit type, not bool type.

A very interesting question has occurred, we found that in SQL Server bit type data-1 can represent 1, so we can change the above statement to:

Update category set visible=visible-1 where id=1

Oh: Of course, you can also write: Update category set Visible = 1-visible where id=1, so there is no-1, only 0 and 1.
Related Article

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.