SQL Server/T-SQL Tutorial/Data Types/bit — различия между версиями

Материал из SQL эксперт
Перейти к: навигация, поиск
м (1 версия)
 
(нет различий)

Текущая версия на 13:25, 26 мая 2010

bit type column

   <source lang="sql">

6> CREATE TABLE T ( 7> int1 int, 8> bit1 bit, 9> varchar1 varchar(3), 10> dec1 dec(5,2), 11> cmp1 AS (int1 + bit1) 12> ) 13> GO 1> 2> INSERT T (int1, bit1) VALUES (1, 0) 3> INSERT T (int1, varchar1) VALUES (2, "abc") 4> INSERT T (int1, dec1) VALUES (3, 5.25) 5> INSERT T (bit1, dec1) VALUES (1, 9.75) 6> GO (1 rows affected) (1 rows affected) (1 rows affected) (1 rows affected) 1> 2> drop table t; 3> GO</source>


bit type column with default value

   <source lang="sql">

6> CREATE TABLE T ( 7> int1 int, 8> bit1 bit NOT NULL DEFAULT 0, 9> rvr1 timestamp, 10> usr1 nvarchar(128) DEFAULT USER, 11> createtime datetime DEFAULT CURRENT_TIMESTAMP 12> ) 13> GO 1> INSERT T (int1) VALUES (1) 2> WAITFOR DELAY "00:00:01" 3> GO 1> 2> drop table t; 3> GO</source>


Count non-null bit1 values

   <source lang="sql">

7> CREATE TABLE T ( 8> int1 int, 9> bit1 bit, 10> varchar1 varchar(3), 11> dec1 dec(5,2), 12> cmp1 AS (int1 + bit1) 13> ) 14> GO 1> 2> INSERT T (int1, bit1) VALUES (1, 0) 3> INSERT T (int1, varchar1) VALUES (2, "abc") 4> INSERT T (int1, dec1) VALUES (3, 5.25) 5> INSERT T (bit1, dec1) VALUES (1, 9.75) 6> GO (1 rows affected) (1 rows affected) (1 rows affected) (1 rows affected) 1> 2> SELECT COUNT(*) "Count of non-null bit1" 3> FROM T 4> WHERE bit1 IS NOT NULL 5> GO Count of non-null bit1


                    2

(1 rows affected) 1> 2> drop table t; 3> GO 1></source>


Count null bit1 values

   <source lang="sql">

5> CREATE TABLE T ( 6> int1 int, 7> bit1 bit, 8> varchar1 varchar(3), 9> dec1 dec(5,2), 10> cmp1 AS (int1 + bit1) 11> ) 12> GO 1> 2> INSERT T (int1, bit1) VALUES (1, 0) 3> INSERT T (int1, varchar1) VALUES (2, "abc") 4> INSERT T (int1, dec1) VALUES (3, 5.25) 5> INSERT T (bit1, dec1) VALUES (1, 9.75) 6> GO (1 rows affected) (1 rows affected) (1 rows affected) (1 rows affected) 1> SELECT COUNT(*) "Count of null bit1" 2> FROM T 3> WHERE bit1 IS NULL 4> GO Count of null bit1


                2

(1 rows affected) 1> 2> drop table t; 3> GO 1> 2></source>