Restricting column data: rules  Inserting NULLs into columns that do not allow them

Chapter 7: Adding, Changing, and Deleting Data

Using the NULL character string

Only columns for which NULL was specified in the create table statement and into which you have explicitly entered NULL (no quotes), or into which no data has been entered, contain null values. Avoid entering the character string “NULL” (with quotes) as data for a character column. Use “N/A” or “none” or a similar value instead. To enter the value NULL explicitly, do not use single or double quotes.

To explicitly insert NULL into a column:

values({expression | null} 
     [, {expression | null}]...)

The following example shows two equivalent insert statements. In the first statement, the user explicitly inserts a NULL into column t1. In the second, Adaptive Server provides a NULL value for t1 because the user has not specified an explicit column value:

create table test 
(t1 char(10) null, t2 char(10) not null) 
insert test 
values (null, "stuff") 
insert test (t2) 
values ("stuff") 

NULL is not an empty string

The empty string (“ ”or ‘ ’) is always stored as a single space in variables and column data. This concatenation statement is equivalent to “abc def”, not “abcdef”:

"abc" + "" + "def" 

The empty string is never evaluated as NULL.





Copyright © 2005. Sybase Inc. All rights reserved. Inserting NULLs into columns that do not allow them

View this book as PDF