Previous | Table of Contents | Next |
The Oracle database is not a simple piece of software. Fortunately, becoming a good PL/SQL developer doesn t require that you know everything about the internal structures of the database. Unfortunately, becoming a good PL/SQL developer requires that you understand a large part of the database architecture. This chapter is intended to provide you with a very high level perspective on what you need to know.
If you are already experienced with Oracle, SQL, and PL/SQL, you ll probably want to browse this chapter and move on to Chapter 3. If you re completely new to Oracle (either with or without previous development experience), make sure that you read this chapter before proceeding.
Your knowledge of the database needs to cover the following basics:
This list is by no means comprehensive. Your work as an application developer using Oracle and PL/SQL will continually expose you to new challenges; with hard work and dedication, you ll meet those challenges head on.
A constraint is a condition placed on a table, typically to satisfy a business rule. When a constraint is placed upon a table, every row in the table must satisfy that constraint. Listing 2.1 provides a definition of the table STUDENTS.
Listing 2.1 A sample table creation script using constraints.
CREATE TABLE STUDENTS AS (ssn NOT NULL number(9), first_name NOT NULL varchar2 (10), last_name NOT NULL varchar2 (12), middle_name varchar2 (10), street_address NOT NULL varchar2 (30), apartment_number varchar2 (4), city NOT NULL varchar2 (30), state_code NOT NULL varchar2 (2), zip_code NOT NULL number (5), home_phone NOT NULL number (10), degree_plan varchar2 (20), overall_gpa number (3, 2), most_recent_gpa number (3, 2));
Notice the columns ssn , first_name , last_name , street_address , city , state_code , and zip_code have the NOT NULL constraint. This constraint requires that each row of data in the STUDENTS table has values for these columns.
How Are Constraints Used?
As previously stated, constraints are often used to enforce business rules. A business rule that all students have a home address, name , and social security number is enforced through the use of the NOT NULL constraint. Several types of constraints exist, including:
The use of constraints to enforce business rules does have limitations. Some business rules are simply too complex to enforce with the limited functionality of the check constraint; in these situations, the system often has to rely on the use of database triggers (which use PL/SQL and can handle complex logic).
A revised description of the STUDENTS table might appear as shown in Listing 2.2.
Previous | Table of Contents | Next |