16.10.2015 Views

Getting Started with DB2 Express-C

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 8 – Working <strong>with</strong> Database Objects 159<br />

quantity<br />

cost<br />

image<br />

project_num<br />

INTEGER, NOT NULL<br />

DECIMAL, Precision 7, Scale 2, NOT NULL<br />

BLOB, 1MB, NULLABLE, NOT LOGGED<br />

CHAR, length 6, NOT NULL<br />

Note: The NOT LOGGED option can be specified when declaring LOB columns. It<br />

is mandatory for columns greater than 1GB in size. It is also generally<br />

recommended for LOBs larger than 10MB, as changes to large columns can quickly<br />

fill the log file. Even if NOT LOGGED is used, changes to LOB files during a<br />

transaction can still be successfully rolled back. Also notice that the image column<br />

is the only one defined as a NULLABLE column. Why do you think that the column<br />

was defined like this?<br />

7. At this point, all the mandatory information for creating a table has been provided.<br />

By skipping the other panels in the wizard, you are choosing the default values for<br />

those options. You can always add keys and constraints after a table has been<br />

created.<br />

8. Add a constraint to the table to restrict values on the quantity column. On the<br />

Constraint page of the wizard, click the ADD button. In the Check Name field,<br />

enter: valid_quantities. In the Check Condition field, enter: quantity > 0<br />

Click the OK button. You should see a summary of the constraint you just added in<br />

the Constraint page of the wizard. Click the Next button to continue to the next<br />

page of the wizard.<br />

9. You can continue going through the wizard, changing the other parameters of the<br />

table. Alternatively, you can skip to the Summary page, or simply click the Finish<br />

button to create the table.<br />

10. From Control Center, click on the Tables folder under the SAMPLE database in the<br />

Object Tree pane. The table you just created should now appear in the list. It might<br />

be necessary to refresh the Control Center view in order to see the changes.<br />

11. Let's now test implicit casting using the table STAFF in the SAMPLE database. Try<br />

the following:<br />

C:\>db2 describe table staff<br />

Note that the ID column is defined as a SMALLINT<br />

C:\>db2 select * from staff where id = '350' --> Note '350' is a string<br />

C:\>db2 select * from staff where id = 350 --> Note 350 is a number<br />

In both cases, the output should be:<br />

ID NAME DEPT JOB YEARS SALARY COMM

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!