Académique Documents
Professionnel Documents
Culture Documents
Tables
4 Query: Command to perform database operation
4 insert
4 modify
4 delete
4 view
4 Example declaration:
student_name VARCHAR2(30)
4 Example declaration:
s_gender CHAR(1)
4 LONG
4 Stores up to 2 GB of variable-length character data
4 Each table can have only one LONG field
Integer Numbers
4 Whole number with no digits to right of decimal point
4 Precision is maximum width
4 Scale is omitted
4 Sample declaration:
s_age NUMBER (2)
Fixed-Point Numbers
4 Contains a specific number of decimal places
4 Precision is maximum width
4 Scale is number of decimal places
4 Sample declaration:
item_price NUMBER(5, 2)
Floating-Point Numbers
4 Sample declaration:
s_dob DATE
Format Masks
4 Specify input and output formats for data values
4 Common NUMBER format masks
Format Mask
Formatted Data
99,999
12,345
$99,999.99
$12,345.00
99,999PR
<12,345>
99,999MI
-12,345
$99,999.99PR
<$12,345.00>
Format Masks
4 Common DATE format masks
Format Mask
Formatted Data
DD-MON-YY
05-JUN-01
DD-MON-YYYY
05-JUN-2001
MM/DD/YY
06/05/2001
HH:MI AM
02:30 PM
JUNE 5, 2001
MM/DD/YY HH:MI AM
06/05/01 02:30 PM
Integrity Constraints
4 Used to define primary and foreign keys
4 Constraint name: Internal name used by DMBS to identify
the constraint
4 Constraint name convention:
4 tablename_fieldname_constraintID
4 Constraint ID values:
4 Primary key: PK
4 Foreign key: FK
4 Example:
sid NUMBER(6)
CONSTRAINT student_sid_pk PRIMARY KEY
4 Example:
sid NUMBER(6),
course_id NUMBER(6),
grade NUMBER ,
CONSTRAINT enrollment_sid_course_id_pk PRIMARY KEY (sid,
course_id)
4 Example:
advisorid NUMBER(6)
CONSTRAINT student_advisorid_fk
REFERENCES faculty(fid)
Value Constraints
4 Restricts data values that can be inserted into a field
4 Types
4 Check condition: Restricts to specific values
4 example: s_gender (M or F)
4 Not NULL
4 CONSTRAINT <constraint_name> NOT NULL
s_name VARCHAR2(30) student_s_name_nn
NOT NULL
SQL*Plus
4 Oracle SQL command line utility
4 Starting SQL*Plus
SQL*Plus
4 All commands must be terminated with a semicolon
mystudent_s_name_nn
4 Deleting a table
DROP TABLE mystudent;
Modifying Tables
4 Prohibited
4 Changing the table name
4 Changing a column name
4 Unrestricted
4 Adding a new column
4 Deleting a primary key or foreign key constraint
Modifying Tables
4 Restricted (allowed only if existing data fits new
specification)
4 Changing a columns data type, size, and default value
4 Adding a primary key constraint
4 Adding a foreign key constraint
4 Adding a CHECK CONDITION constraint
4 Adding a NOT NULL constraint