Mega Code Archive

 
Categories / MSSQL / Constraints
 

Blocking Empty and Missing Character Input

4> CREATE TABLE T ( 5>     int1 int IDENTITY PRIMARY KEY, 6>     vch1 varchar(5) 7>         CHECK (LEN(vch1) > 0), 8>     vch2 varchar(5) 9>         CONSTRAINT CK_LEN_TOO_SHORT 10>         CHECK (LEN(vch2) > 0) 11> ) 12> GO 1> 2> INSERT T (vch1, vch2) VALUES('a','b') 3> INSERT T (vch1, vch2) VALUES('','b') 4> INSERT T (vch1, vch2) VALUES('a','') 5> INSERT T DEFAULT VALUES 6> GO (1 rows affected) Msg 547, Level 16, State 1, Server J\SQLEXPRESS, Line 3 The INSERT statement conflicted with the CHECK constraint "CK__T__vch1__3D5EEB29". The conflict occurred in database "master", table "dbo.T", column 'vch1'. The statement has been terminated. Msg 547, Level 16, State 1, Server J\SQLEXPRESS, Line 4 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 rows affected) 1> 2> 3> 4> drop table t; 5> GO 1>