Using the NULL character string  Adding rows without values in all columns

Chapter 7: Adding, Changing, and Deleting Data

Inserting NULLs into columns that do not allow them

To insert data with select from a table that has null values in some fields into a table that does not allow null values, you must provide a substitute value for any NULL entries in the original table. For example, to insert data into an advances table that does not allow null values, this example substitutes “0” for the NULL fields:

insert advances
select pub_id, isnull(advance, 0) from titles

Without the isnull function, this command inserts all the rows with non-null values into advances and produces error messages for all the rows where the advance column in titles contains NULL.

If you cannot make this kind of substitution for your data, you cannot insert data containing null values into columns with a NOT NULL specification.





Copyright © 2005. Sybase Inc. All rights reserved. Adding rows without values in all columns

View this book as PDF