Appendix E – Advanced SQL
This is self-explanatory. See the IRC file DBC-e08-JRJ-AppE-Appraisals.xlsx. This file
contains a worksheet similar to the one in Figure D-10 and another worksheet that
has been cleaned up to facilitate importing, as described in Appendices A, B, and C.
Note that this work has been done by hand since we have a very small database; for
larger databases these activities can be automated using a combination of
spreadsheet and database techniques, but that is beyond the scope of this book.
2. Import the data into one or more new tables in the JRJ database. You must
determine all table characteristics needed (primary key, foreign keys, data types,
etc.).
Follow the instructions in the relevant appendix to accomplish this task:
Foreign keys will be handled in question 3; here we import the data and set the primary
key. Note that we choose (ItemNumber, AppraisalDate) as a composite primary key
because some items may be appraised more than once. Any required SQL statements
during the import process will be in the SQL file for that system. Here are some things
to make note of during the import process:
For SQL Server:
The import process has resulted in a table named APRAISALS-CLEAN$. After renaming
the tables to APPRAISALS, we will first change the type of ItemNumber from Float to Int,
ensure that both ItemNumber and AppraisalDate are NOT NULL, then set the primary
key. Note that we omit certain additional details that will need checking, specifically
data types and NULL/NOT NULL constraints for other fields.
ALTER TABLE APPRAISALS
ALTER COLUMN ItemNumber INT NOT NULL;