How to Set the Student with Id of 19104069 as ‘TRUE’.
Suppose we have to update the fee status from 0 to 1 of a particular student whose studentId is 19104069 from studentsFeesInfo table.
Query
UPDATE studentsFeesInfo
SET isFeePaid = 'TRUE'
WHERE studentId = 19104069
SELECT * FROM studentsFeesInfo
The Result Looks Like:
Explanation : In the above query we have updated the record of student with studentId 19104069 with isFeePaid =1 by updating its value to TRUE since SQL server has converted it to BIT datatype it has become 1 in the table.
SQL Server BIT Data Type
The BIT data type is used to store boolean values like 0, 1, or NULL. The SQL server doesn’t have the data Boolean instead it has the data type BIT which has which stores the boolean value. The BIT data type is advantageous in terms of space optimization since each BIT data type takes on only 1 bit of storage, suppose their n columns in the table with the BIT data the ceil value of n/8 bytes will be used i.e if there 0-8 columns with bit data type then it will be stored as 1 byte.
SQL server even converts the following assignment into 0 or 1 values:
- When the column of bit data type assigned with ‘TRUE‘ or ‘FALSE‘ is converted to 1 or 0 respectively, other than there strings it will throw an error for other strings.
- When the column of bit data type assigned with any nonzero values will be converted to 1 respectively.
Syntax:
CREATE TABLE table_name
(
column_name BIT
);
Explanation: Using the BIT data type after our desired column name make the column of BIT data type.
Contact Us