Sybase 2 Barcode Reader User Manual


 
CHAPTER 3 Managing the Database
DataWindow Designer User’s Guide 75
Working with keys
If your DBMS supports primary and foreign keys, you can work with the keys
in DataWindow Designer.
Why you should use
keys
If your DBMS supports them, you should use primary and foreign keys to
enforce the referential integrity of your database. That way you can rely on the
DBMS to make sure that only valid values are entered for certain columns
instead of having to write code to enforce valid values.
For example, say you have two tables called
Department and Employee. The
Department table contains the column Dept_Head_ID, which holds the ID of the
department's manager. You want to make sure that only valid employee IDs are
entered in this column. The only valid values for
Dept_Head_ID in the
Department table are values for Emp_ID in the Employee table.
To enforce this kind of relationship, you define a foreign key for
Dept_Head_ID
that points to the
Employee table. With this key in place, the DBMS disallows
any value for
Dept_Head_ID that does not match an Emp_ID in the Employee
table.
For more about primary and foreign keys, consult a book about relational
database design or your DBMS documentation.
What you can do in
the Database painter
You can work with keys in the following ways:
Look at existing primary and foreign keys
Open all tables that depend on a particular primary key
Open the table containing the primary key used by a particular foreign key
Create, alter, and drop keys
For the most part, you work with keys the same way for each DBMS that
supports keys, but there are some DBMS-specific issues. For complete
information about using keys with your DBMS, see your DBMS
documentation.
Viewing keys
Keys can be viewed in several ways:
In the expanded tree view of a table in the Objects view
As icons connected by lines to a table in the Object Layout view