LAB #7

advertisement
Faculty of Engineeringand Architecture
ComputerEngineeringDepartment
DATABASE MANAGEMENT SYSTEMS
LAB #7
PART1
Relational Algebra






Unzip given aql.jar file to extract relational algebra interpreter.
To run interpreter, first of all you should define Java path to system variables.
After that run command prompt.
Go to the driectory which includes both aql.jar and company directory.
Write java edu.gsu.cs.ra.RA company on command prompt.
According to given context-free grammar for this interpreter, write relational algebra which
produces desired outputs.
Context-FreeGrammar
<Query>::= <Expr> SEMI;
<Expr>::= <ProjExpr> | <RenameExpr> | <UnionExpr> |
<MinusExpr> | <IntersectExpr> | <JoinExpr> |
<TimesExpr> | <SelectExpr> | RELATION
<ProjExpr>::= PROJECT [<AttrList>] (<Expr>)
<RenameExpr>::= RENAME [<AttrList>] (<Expr>)
<AttrList>::= ATTRIBUTE | <AttrList> , ATTRIBUTE
<UnionExpr>::= (<Expr> UNION <Expr>)
<MinusExpr>::= (<Expr> MINUS <Expr>)
<IntersectExpr>::= (<Expr> INTERSECT <Expr>)
<JoinExpr>::= (<Expr> JOIN <Expr>)
<TimesExpr>::= (<Expr> TIMES <Expr>)
<SelectExpr>::= SELECT [<Condition>](<Expr>)
<Condition>::= <SimpleCondition> |
<SimpleCondition> AND <Condition>
<SimpleCondition>::= <Operand><Comparison><Operand>
<Operand>::= ATTRIBUTE | STRING-CONST | NUMBER-CONST
<Comparison>::= < | <= | = | <> | > | >=
RelationalAlgebraExamples
1. Retrieve first name and last name of employee(s) whose salary is greater than 40000.
2. Retrieve ssn, first name, last name, salary of employee(s) who work for department 4 or
department 5.
3. Retrieve ssn, first name and last name of employee(s) who work for departmant located in
‘Houston’.
4. Retrieve a list of employees last name, first name and the projects name they are working
on and working hours.
5. List the names of managers who have at least one dependent.
PART 2
TRIGGER SYNTAX
CREATE [OR REPLACE] TRIGGER<trigger_name>
BEFORE |AFTER
{INSERT |UPDATE | DELETE} ON<table_name>
[FOR EACH ROW] [WHEN (<trigger_condition>)])
<trigger_body>
PROCEDURE SYNTAX
CREATE OR REPLACE PROCEDURE procedure_name ( parameters )
IS
BEGIN
procedure_body
END;
Information about Schema
Consider the AIRLINE relational database schema shown in Figure 3.8 in your course book,
which describes a database for airline flight information. Each FLIGHT is identified by a
Flight_number, and consists of one or more FLIGHT_LEGs with Leg_numbers 1, 2, 3, and so on.
Each FLIGHT_LEG has scheduled arrival and departure times, airports, and one or more
LEG_INSTANCEs—one for each Date on which the flight travels. FAREs are kept for each FLIGHT.
For each FLIGHT_LEG instance, SEAT_RESERVATIONs are kept, as are the AIRPLANE used on the
leg and the actual arrival and departure times and airports. An AIRPLANE is identified by an
Airplane_id and is of a particular AIRPLANE_TYPE. CAN_LAND relates AIRPLANE_TYPEs to the
AIRPORTs at which they can land. An AIRPORT is identified by an Airport_code.
Create appropriate triggers and views that asked you below.
1) Create a trigger when we insert a reservation, display an output about customer
name, seat number and flight number of that reservation.
2) Create a trigger when we insert a fare, display an output about flight name, code
and amount.
3) Create a view that retrieves flight number, airline and number of flight leg of that
flight which has flight leg more than 1
4) Create a trigger that checks whether the leg instance can land arrival airport of that
leg instance before inserting record belongs to leg instance.
Download