Professional Documents
Culture Documents
with Oracle
Click
Then Click
DATE dates
Key. A key is one or more data attributes that uniquely identify an entity.
In a physical database a key would be formed of one or more table columns
whose value(s) uniquely identifies a row within a relational table.
Composite key. A key that is composed of two or more attributes.
Natural key. A key that is formed of attributes that already exist in the real world.
For example, U.S. citizens are issued a Social Security Number (SSN) that is
unique to them. SSN could be used as a natural key, assuming privacy laws allow
it, for a Person entity (assuming the scope of your organization is limited to the
U.S.).
Surrogate key. A key with no business meaning.
Candidate key. An entity type in a logical data model will have zero or more
candidate keys, also referred to simply as unique identifiers. For example, if we
only interact with American citizens then SSN is one candidate key for the
Person entity type and the combination of name and phone number (assuming the
combination is unique) is potentially a second candidate key. Both of these keys
are called candidate keys because they are candidates to be chosen as the primary
key, an alternate key or perhaps not even a key at all within a physical data
model.
Primary key. The preferred key for an entity type.
Alternate key. Also known as a secondary key, is another unique identifier of a
row within a table.
Foreign key. One or more attributes in an entity type that represents a key, either
primary or secondary, in another entity type.
Delete record
DELETE FROM <regions> WHERE <region_id = 5>;
Update table
UPDATE <regions> SET <column_name> = <> WHERE <condition>;
Add a column
ALTER TABLE <regions> ADD <COLUMN_NAME> <DATA_TYPE>;
Delete column
ALTER TABLE <regions> DROP COLUMN <COLUMN_NAME>;
Sum a column
SELECT SUM(column_name) FROM [table name];
Introduction to JOINS
Inner Join
It wont return any students who have been accepted at theschool but havent signed
up for any classes yet, nor will it return any classesthat are on the schedule but for
which no student has yet shown an interest.
Show me the students and their teachers who have the same first name.
(JOIN on the first name.)
Show me customers and employees who live in the same city. (JOIN on
the city name.)
Show me the vendors and the products they supply to us.
List the faculty staff and the subject each teaches.
I want to see all employees who report to a manager in department number 60
select last_name, first_name, department_name,
from employees
inner join departments
using (department_id)
order by (department_id);
Alternate Form
Select first_name, last_name, department_name
from employees
inner join departments
on (employees.department_id = departments.department_id)
order by (employees.department_id);
Outer Join
An OuterJoin asks your database system to return not only the rows that match on the
criteria you specify but also the unmatched rows from either one or both of
the two sets you want to link
You'll generally use the OUTER JOIN form that asks for all the rows from one table or
result set and any matching rows from a second table or result set. To do this, you
specify either a LEFT OUTER JOIN or a RIGHT OUTER JOIN.
Left Outer Join
Select all employees assigned to departments as well as those who are without a
department
------------------------------------------------------------------------------------------Select first_name, last_name, department_name
from employees
left outer join departments
using (department_id)
order by (department_id);
Using a Union:
SELECT (firstname || ' ' || lastname) as name,
city, postalcode into TestTable
FROM employees
UNION
SELECT companyname, city, postalcode
FROM customers
Functionality Testing
UI Screens, Stored procedures and triggers
Stored procedures and triggers should be tested just like application code would be.
Relationship Testing
Referential integrity (RI)
RI rules, in particular cascading deletes in which highly coupled "child" rows are deleted
when a parent row is deleted, should also be validated. Existence rules, such as a
customer row corresponding to an account row, must exist before the row can be
inserted into the Account table, and can be easily tested, too.
Performance Testing
Access time to read/write/delete a single row.
Access time for common queries returning multiple rows.
Access time for queries involving several tables.
Existence test for an index. Does the expected index exist or not?
Structural Testing
Table existence. We can check whether all the data from the application is
being inserted into the database properly, or not
View definitions. Views often implement interesting business logic. Things to
look out for include: Does the filtering/select logic work properly? Do you get
back the right number of rows? Are you returning the right columns? Are the
columns, and rows, in the right order?