About adding, deleting, querying, and modifying bit fields in SQL Server, serverbit

Source: Internet
Author: User

About adding, deleting, querying, and modifying bit fields in SQL Server, serverbit

Preface

This article describes how to add, query, modify, and delete bit fields in SQL Server. before talking about BIT fields, let's take a look at the "weird" scene and execute Update successfully, however, the query result is still 1 rather than 2 of Update.

When someone asks me, I was in the aggressive status, and Lenovo's specific business suddenly remembered that this field is bit type.

  

It is not surprising that this phenomenon is continuous with the BIT type field.

There is not much nonsense. simply look at the code and the results.

Create a test table first

CREATE TABLE TestBIT( Id INT IDENTITY(1,1), BitColumn BIT)

Insert of bit Fields

In general, the bit type field can only store 0 or 1, so direct inert 0 or 1 is of course no problem.

Because bit represents the true or false value, it is no problem to assign the string "false" or "true" to the insert statement.

Of course, the text only supports the "false" or "true" strings. If the other two strings are used, an error is returned. From the error message, an implicit conversion is also found during the insert operation.

For numeric data: when inserting a value other than 0 or 1, the data is inserted successfully, but (a value other than 0) the inserted value is implicitly converted to 1.

Values other than 0 are converted to 1, that is, true.

Update bit Fields 

The same applies when performing the update operation. If the value is updated, the updated string can only be false or true.

 

   

If the updated value is a value and the value is not 0 (an integer or a negative number), it is equivalent to updating the bit field type to 1.

  

  

Summary

The above is all the content of this article. I hope the content of this article will help you in your study or work. If you have any questions, please leave a message, thank you for your support.

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.