SQL Server/T-SQL/Data Type/Bit — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Версия 16:46, 26 мая 2010
bit type column
<source lang="sql">
4> CREATE TABLE T ( 5> int1 int IDENTITY PRIMARY KEY, 6> bit1 bit NOT NULL DEFAULT 0 7> ) 8> GO 1> 2> INSERT T (bit1) VALUES (1) 3> INSERT T (bit1) VALUES (0) 4> INSERT T DEFAULT VALUES 5> INSERT T (int1, bit1) VALUES (4,1) 6> GO (1 rows affected) (1 rows affected) (1 rows affected) Msg 544, Level 16, State 1, Server J\SQLEXPRESS, Line 5 Cannot insert explicit value for identity column in table "T" when IDENTITY_INSERT is set to OFF. 1> 2> select * from t; 3> GO int1 bit1
----
1 1 2 0 3 0
(3 rows affected) 1> 2> drop table t; 3> GO
</source>
Count null bit1 values
<source lang="sql">
1> 2> CREATE TABLE T ( 3> int1 int, 4> bit1 bit, 5> varchar1 varchar(3), 6> dec1 dec(5,2), 7> cmp1 AS (int1 + bit1) 8> ) 9> GO 1> INSERT T (int1, bit1) VALUES (1, 0) 2> GO (1 rows affected) 1> INSERT T (int1, varchar1) VALUES (2, "abc") 2> GO (1 rows affected) 1> INSERT T (int1, dec1) VALUES (3, 5.25) 2> GO (1 rows affected) 1> INSERT T (bit1, dec1) VALUES (1, 9.75) 2> GO (1 rows affected) 1> --Count null bit1 values 2> SELECT COUNT(*) "Count of null bit1" 3> FROM T 4> WHERE bit1 IS NULL 5> GO Count of null bit1
2
(1 rows affected) 1> 2> drop table t 3> GO 1> 2>
</source>