create SQL (both DML/DDL) statements appropriate for the
creation of relational structures & constraints and other
objects for a given case study, the population of these tables
and the manipulation (querying/updating) of the stored data.
2. Create, develop and use the PL / SQL Program Units
Procedures, Functions as a progression towards Object Oriented
Relational Database Programming.
3. Package a collection of logically related Procedures and
Functions together to further move towards development of
Objects which reflect the principle of Data Abstraction whereby
only an Object specified in the Interface is accessible to the
end user.
4. Select, create, and use appropriate Database Triggers to
impose agreed specific constraints on a Database Table.
5. Provide a full and detailed evaluation which includes a
comprehensive test execution plan and its implementation for
each of the above.

Consider the following case study:
Perilous Printing is a medium size printing company that does
work for book publishers throughout UK. The company currently
has 10 offices, most of which operate autonomously, apart from
salaries, which are paid by the head office. Currently the
sharing and communication of data, is carried out using multi-
user networked access to a centralised RDBMS. Perilous Printing
jobs consist of printing books or part of books. A printing job
requires the use of materials, such as paper and ink, which are
assigned to a job via purchase orders. Each printing job may
have several purchase orders assigned to it. Likewise, each
purchase order may contain several purchase order items. The
following tables form part of the transactional RDB that the
company uses:
office (office_no, o_addr, o_telno, o_faxno, mgr_nin) staff
(staff_no, nin, fname, lname, s_addr, s_telno, gender, dob,
position, taxcode, salary, office_no) publisher (pub_no,
p_name, p_city, p_telno, p_faxno, credit_code, office_no)
book_job (job_no, pub_no, job_date, job_desc, job_type,
job_status, supervisor_nin) purchase_order (job_no, po_no,
po_date) po_item (job_no, po_no, it_no, qty) item (it_no,
it_desc, amt_in_stock, price)
office contains details of each office and the office number
(office_no) is the key. Each office has a Manager represented
by the manager’s national insurance number (mgr_nin).
staff contains details of staff; the staff_no is the key. The
office that the member of staff works from is given by
office_no.
publisher contains details of publisher and the publisher
number (pub_no) is the key. Publishers are registered with the
nearest office in their country, given by office_no, and they
are given a credit code that can have the
values “AA”, “AB”, “BB”, “BC”, “CC”, “CD” and “DD”. If a
publisher is to be deleted then not only the publisher’s entry
from the publisher table will have to be removed but all the
data associated with the particular supplier has to be deleted
too
book_job contains details of publishing jobs and the job number
(job_no) is the key. The publisher is given by the publisher
number (pub_no) and the supervisor for the job by
supervisor_nin. The job type can be either null or urgent;
whereas the job_status can be “ongoing” or “completed”
purchase_order contains details of the purchase orders for each
job and the combination of job number and a purchase order
number (job_no, po_no) form the key. Each printing job may have
several purchase orders assigned to it.
item contains details of all materials that can be used in
printing jobs and the item number (it_no) is the key.
po_item contains details of the items on the purchase order and
(job_no, po_no, it_no) forms the key.
In the above given database schema, descriptions are strings of
characters (at most 30 characters long), any dates (except the
job_ date) stored cannot be after the current system date, and
quantities and prices are assumed to be non-negative numbers.



create SQL (both DML/DDL) statements appropriate for the creation of relational structures & c..

Answer / Kajod Mal Meena

1. Creation of SQL DDL statements:
```
-- Create table office
CREATE TABLE office (
office_no NUMBER PRIMARY KEY,
o_addr VARCHAR2(30) NOT NULL,
o_telno VARCHAR2(15),
o_faxno VARCHAR2(15),
mgr_nin VARCHAR2(12) NOT NULL
);

-- Create table staff
CREATE TABLE staff (
staff_no NUMBER PRIMARY KEY,
nin VARCHAR2(12) NOT NULL,
fname VARCHAR2(30),
lname VARCHAR2(30) NOT NULL,
s_addr VARCHAR2(30),
s_telno VARCHAR2(15),
gender CHAR(1) CHECK (gender IN ('M', 'F')),
dob DATE CHECK (dob <= SYSDATE),
position VARCHAR2(30),
taxcode NUMBER,
salary NUMBER,
office_no FOREIGN KEY REFERENCES office
);

-- ... Continue creating tables for publisher, book_job, purchase_order, po_item, item, ...

2. Creating PL/SQL Procedures and Functions:
-- Example of a Procedure to add a new staff member
CREATE OR REPLACE PROCEDURE add_staff (
p_nin IN VARCHAR2,
p_fname IN VARCHAR2,
p_lname IN VARCHAR2,
p_saddr IN VARCHAR2,
p_stelno IN VARCHAR2,
p_gender IN CHAR,
p_dob IN DATE,
p_position IN VARCHAR2,
p_taxcode IN NUMBER,
p_salary IN NUMBER,
p_office IN NUMBER
) AS
BEGIN
INSERT INTO staff (nin, fname, lname, s_addr, s_telno, gender, dob, position, taxcode, salary, office_no)
VALUES (p_nin, p_fname, p_lname, p_saddr, p_stelno, p_gender, p_dob, p_position, p_taxcode, p_salary, p_office);
END;

-- ... Continue creating Procedures and Functions for various operations...

3. Packaging Procedures and Functions:
CREATE OR REPLACE PACKAGE staff_pkg AS
TYPE staff_t IS RECORD (
nin VARCHAR2(12),
fname VARCHAR2(30),
lname VARCHAR2(30),
...
);
PROCEDURE add_staff(p_data IN staff_t);
END staff_pkg;

CREATE OR REPLACE PACKAGE BODY staff_pkg AS
-- Implementation of the add_staff procedure...
END staff_pkg;

4. Creating Database Triggers:
CREATE TRIGGER before_delete_publisher
BEFORE DELETE ON publisher
FOR EACH ROW
BEGIN
-- Delete associated data from other tables when a publisher is deleted
END;

5. Evaluation and Test Execution Plan:
-- ... Detailed evaluation, test plan, and implementation details go here..."

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More SQL PLSQL Interview Questions

Whate is use of MOD function in pl/sql.

3 Answers   Oracle,


can sql servers linked to other servers like oracle? : Sql dba

1 Answers  


What are the benefits of triggers?

1 Answers  


What are character functions in sql?

1 Answers  


How can we solve sql error: ora-00904: invalid identifier?

1 Answers  


what is data integrity

3 Answers   Fidelity, TCS,


What is the basic structure of PL/SQL ?

6 Answers  


A table was given with 3 columns like Manager id,Manager Name and Employee name. Question was to create hierarchy.

2 Answers   TCS,


When the mutating error will comes? and how it will be resolved?

2 Answers  


Can we rollback truncate?

0 Answers  


how will i became good database developer?

1 Answers  


How to change the order of columns in Oracle SQL Plus ?

1 Answers   MCN Solutions,


Categories