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.