Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 362 Vote(s) - 3.52 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to create a yes/no boolean field in SQL server?

#11
The `BIT` datatype is generally used to store `boolean` values (`0` for `false`, `1` for `true`).
Reply

#12
The equivalent is a `BIT` field.

In `SQL` you use `0` and `1` to set a bit field (just as a yes/no field in Access). In Management Studio it displays as a false/true value (at least in recent versions).

When accessing the database through ASP.NET it will expose the field as a boolean value.
Reply

#13
You can use **[BIT][1] type** which can have `1` or `0`, or also `NULL` if `NULL` is allowed.

**[BIT][1] type** converts:
- Any integer values except `0` to `1`.
- Any integer string values except `"0"` to `1`.
- `"0"` to `0`.

Then, you can create a table with **[BIT][1] type** as shown below:

```lang-none
CREATE TABLE doctor (
id INT IDENTITY,
name NVARCHAR(50),
on_call BIT, -- Here
PRIMARY KEY(id)
)
GO
```

Then, insert rows as shown below:

```mssql
INSERT INTO doctor
VALUES ("John", 1), ("Tom", 0), ("Lisa", "-23"), ("Kai", "0"), ("Bob", NULL)
GO
```

```lang-none
1> SELECT * FROM doctor
2> GO
id name on_call
-- ---- -------
1 John 1 <- 1
2 Tom 0 <- 0
3 Lisa 1 <- "-23"
4 Kai 0 <- "0"
5 Bob NULL <- NULL
```


[1]:

[To see links please register here]

Reply

#14
***Below the List of database where what type of datatype is use for Boolean***


-> **Oracle** -> Number(1)

-> **SQL Server** -> BIT

-> **MySql** -> BIT or TINYINT

->**postgreSQL** -> boolean


I hope this is really helpful thanks.
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through