This chapter show you how to use the INSERT statement to add data about a new department.
Suppose that a new eastern sales department is created, with the same manager as the current Sales department. You can add this information to the database using the following INSERT statement in Interactive SQL:
INSERT INTO Departments ( DepartmentID, DepartmentName, DepartmentHeadID ) VALUES ( 220, 'Eastern Sales', 902 )
If you make a mistake and forget to specify one of the columns, Sybase IQ reports the following error:
Error at line 1 The number of insert VALUES does not match the column list.
Case sensitivity may matter when inserting values.
The NULL value is a special value used to indicate that something is either not known or not applicable. However, the NULL value is a legal value in any data type. There are two separate and distinct cases where NULL is used:
Situation |
Description |
---|---|
Missing |
The field does have a value, but that value is unknown. |
Inapplicable |
The field does not apply for this particular row. |
Some columns are allowed to contain the NULL value, and others are not. To check whether a column in a table allows the NULL value, use the sp_iqcolumn stored procedure in Interactive SQL. For example, type the following:
sp_iqcolumn Employees
In the nulls column, a “Y” value indicates that nulls are allowed.
You can use a short form to enter values for all the columns in a table in the order they appear when you SELECT * from the table (the order in which they were created). The following is equivalent to the previous INSERT command:
INSERT INTO Departments VALUES ( 220, 'Eastern Sales', 902 )