Physical Design Part 3: We Are Here
Physical Design Part 3: We Are Here
Physical Design Part 3: We Are Here
Consider this scenario. A radio button is an interface method that presents a set of choices, and the user is
allowed to select only ONE of those choices—“you can be male or female, but not both”, for example.
In most interfaces, radio buttons store integer data. So if we to use a radio button in the interface for gender, we
might decide to code that data using integers (e.g., male stored as 1, female stored as 2) instead of text (M, F).
If we stored gender as text it could still be used but would require much more
work in the interface. In this case, the interface designer would need to write
code to convert M & F to 1 & 2 and back; or you'd need to create a view that
codes the data before sending data to the interface, and a trigger that recodes
the data before storing in the database. This is a small example and may not
cause a huge performance hit by itself, but you can see that very many of
these would certainly make the interface slower and more complex to manage.
Database Security
Who has privileges to do what with the data – who can create, read, update,
delete what parts of the DB. We’ll discuss in detail in module 5.
SQL (DDL)
We didn’t practice deleting, but the syntax is similar. To delete Max’s record:
DELETE from demog
WHERE pt_id = ‘2100’
All those type of statements manipulate contents of the tables, that is, they manipulate DATA. Thus, this type of
SQL is called a data manipulation language (DML).
The good news is that the way you write these SQL statements is almost the same as what you already know! In
Access, creating a table in “table design view” writes SQL “create table” statements behind the scenes. You
could write “create table” SQL statements in the Access SQL window, just like we’ve done with our “select”
statements (at least, in a limited way).
The basic syntax:
CREATE TABLE tablename (
columnName dataType (size if necessary),
…
Primary Key (list of column[s])
)
When the primary key is listed AFTER all the attributes, this is a “table constraint”. You must do it this way if
you have a multiple-attribute (composite) primary key. You may do it this way all the time. Some people list the
primary key with the attribute name if the table has a single attribute PK.
but for the adm_dx table we have only one choice – to do the PK as a table constraint:
Demog
Attribute Data size
name type
PT_ID Text 4
NAME Text 20
ZIP Text 5
GENDER Text 1
RACE Text 1
Now just add the “CREATE TABLE” words, and add punctuation and primary key…
I am making a small change to the final project checklist. You do not have to show table design screen
shots or create table statements for ALL tables.
I would like you to show the create table SQL statement for ONE table – whether you use Access or Oracle.
We can use the desc command (Oracle) or MS Access documenter to show your final created DB. (see me for
help with this part)
SEE YOUR TEXT
For more information about DDL syntax such as for altering a table structure, or for dropping a table.
Views
Views are essentially stored queries.
A couple of uses for views…A view can be used to help with security – for example, to only show the columns
from a table that a user is authorized to see. The view can help with usability, by creating a user-friendly alias
for column names.
Data Dictionary (Meta data, Data about data). This is the documentation for physical design for this class. Data
dictionary can be active (used by the computer to create/maintain database), or passive (separate document used
by people). WE will create a passive data dictionary.
Code Tables
Table that contains a code and its meaning. You store the code in a main table and look up the meaning in
another table. It keeps you from mis-spelling terms and having to type long strings of text.
Coded vocabularies are one example. Picklists are another example. The SNDB example in Access contains a
picklist with gender codes (M = male, F = female).
I have asked you to create a code table (or picklist) for ONE attribute somewhere in your database.
Add this to your data dictionary – what is the picklist/code table; and show in the domain column of a table
where the picklist is used
Other table information might be useful in a “real life” DB design situation – you don’t have to create now.
• Who created table
• When table created
• Modification – what was done
• When last modified
• Who modified
• Who requested the modification
• Ownership/Access - who can access the data
While you’re waiting for me to evaluate the data dictionary, take the quiz.
Table Overview
Main Tables these are the ones from logical design
Customer
Variable Name Description Data Type Data Domain Null?
Length
CustomerID Identifies Customers Auto number 4 Integer starting with 1 No
CompanyName Name of Company Text 40 Valid company names No
ContactName Contact Last Name Text 20 Free text, Last name Yes
of contact person
ContactTitle Contact Title Text 4 Mr., Ms., Mrs. Yes
Street Company Address Text 30 Street Address Yes
Zip Company Zip Code Text 5 US Postal Codes. Yes
From ZipCodes table
Phone Company Main Phone Text 12 999-999-0000 Yes
or 999-9999
Fax Company Fax Number Text 12 999-999-0000 Yes
or 999-9999
Primary Key: CustomerID
Index: Zip
Foreign Key: Zip (references ZipCodes.Zip)