Mega Code Archive

 
Categories / MSSQL / Constraints
 

Data length

1> CREATE TABLE T ( 2>     int1 int IDENTITY PRIMARY KEY, 3>     vch1 varchar(5) CHECK (LEN(vch1) > 0) NOT NULL, 4>     vch2 varchar(5) CONSTRAINT CK_LEN_TOO_SHORT CHECK (LEN(vch2) > 0) NOT NULL 5> ) 6> GO 1> INSERT T (vch1, vch2) VALUES('a','b') 2> GO (1 rows affected) 1> INSERT T (vch1, vch2) VALUES('','b') 2> GO Msg 547, Level 16, State 1, Server RNTSOFT\SQLEXPRESS, Line 1 The INSERT statement conflicted with the CHECK constraint "CK__T__vch1__02D256E1". The conflict occurred in database "master", table "dbo.T", column 'vch1'. The statement has been terminated. 1> INSERT T (vch1, vch2) VALUES('a','') 2> GO Msg 547, Level 16, State 1, Server RNTSOFT\SQLEXPRESS, Line 1 The INSERT statement conflicted with the CHECK constraint "CK_LEN_TOO_SHORT". The conflict occurred in database "master", table "dbo.T", column 'vch2'. The statement has been terminated. 1> INSERT T DEFAULT VALUES 2> GO Msg 515, Level 16, State 2, Server RNTSOFT\SQLEXPRESS, Line 1 Cannot insert the value NULL into column 'vch1', table 'master.dbo.T'; column does not allow nulls. INSERT fails. The statement has been terminated. 1> 2> select * from t 3> GO int1        vch1  vch2 ----------- ----- -----           1 a     b (1 rows affected) 1> 2> drop table t 3> GO 1> 2>