0% found this document useful (0 votes)
262 views4 pages

Database Design and PL/SQL Operations Guide

The document describes creating tables with primary keys and foreign keys for various database applications, including: - A student database with tables for student details and marks - An employee database with tables for employee and department details - Order processing, product, and customer databases - Transport management and bus reservation systems It also provides tasks for each case like adding/deleting columns, displaying data, writing PL/SQL programs to perform calculations, creating views and sequences.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
262 views4 pages

Database Design and PL/SQL Operations Guide

The document describes creating tables with primary keys and foreign keys for various database applications, including: - A student database with tables for student details and marks - An employee database with tables for employee and department details - Order processing, product, and customer databases - Transport management and bus reservation systems It also provides tasks for each case like adding/deleting columns, displaying data, writing PL/SQL programs to perform calculations, creating views and sequences.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

[Link] the following tables with the mapping given below.

a. Student_details (reg_no, stu_name, DOB, address, city)


b. mark_details (reg_no, mark1, mark2, mark3, total)
1. Alter the table mark details to add a column average with data type as long.
2. Display the months between the DOB and till date.
3. Using alter command drop the column address from the table stu_details.
4. Write a pl/sql program to find the sum & avg marks of all the student using procedures.
5. Write a procedure named Student that accepts the regno and displays the DOB,address,city

1 .Create the following tables with the mapping given below.


a. emp_details (emp_no, emp_name, DOB, address, doj, mobile_no, dept_no, salary).
b. dept_details (dept_no, dept_name, location).
1. Display the months between the doj and till date.
2. Alter the table emp_details to add a primary key constraint on emp_no.
3. Drop the table dept details.
4. Write a pl/sql program to display the salary of a particular employee using functions.
5. Design and implement library information system to insert data's in DB and update
Data’s in DB using VB/Java as front end and Ms-Access as back end

[Link] the following tables with the mapping given below.


a. stu_details (reg_no, stu_name, DOB, address, city)
b. mark_details (reg_no, mark1, mark2, mark3, total)
1. Find out the name of all students.
2. List all the student detail that who are all located in Chennai.
3. Drop the table mark_details.
4. Write a pl/sqlprogram to find the address of a particular student using functions.
5. Design Student Details from the tableusing Front end tool.

[Link] the following tables with the mapping given below.


a. emp_details (emp_no, emp_name, DOB, address, doj, mobile_no, dept_no, salary).
b. dept_details (dept_no, dept_name, location).
1. Select dept_no from dept_details and not in emp_details using both the tables.
2. Create a table named as student and insert values into the table.
3. Write a pl/sql program to display the salary of a particular employee using functions.
4. Write PL/SQL Program to generate even numbers
5. Design and implement payroll system to insert data's in DB and delete Data from DB
using VB as front end and Ms-Access as back end.

[Link] the following tables with the mapping given below.


Phone_book(ph_no,name,door_no,street,place).

1. List the price of the book which one is between the price of 400 & 500.
2. Creating Trigger To Insert Values To Another Table.
3. Write a pl/sql program to find the factorial of a given number.
4. Write a pl/sql program to find the greatest of a three numbers.
5. Design and implement library Management to insert data's in DB and delete Data from DB
using VB as front end and Ms-Access as back end.

[Link] the following table with the mapping given below.


retailor(Cust_id, Cust_name, place, ph_no,pan_no).
1. Alter the table to add a column pin_no.
2. Display the details of customer who are all living in bangalore.
3. Display the customer name whose first letter is ‘M’.
4. Write a pl/sql program in procedure using in & out parameter.
5. Write a pl/sql program to find the greatest of a three numbers.

[Link] the following table with the mapping given below.


a .Product_master(product_name,purchase_prize,sell_prize,profit,quantity,balance)
[Link] (Cust_id, Cust_name, Addr, ph_no,pan_no).
1. Display all the customer names along with their address.
2. Drop the table customer.
3. Change thesell_price to 5000&purchase_price amount to 4000 for any one of the product in
product_master.
4. Create a trigger to update the balance in product_ master table whenever transaction table will
have a new entry.
5. Design and implement library management system to insert data's in DB and update Data’s in
DB using VB/Java as front end and Ms-Access as back end.
[Link] the following table with the mapping given below.
a. stu_details (reg_no, stu_name, DOB, address, city)
b. mark_details (reg_no, mark1, mark2, mark3, total)
1. Find out the name of all students along with their total marks.
2. Change the mark1 as ‘78’ from ‘59’ and alter the total for a particular student.
3. Delete all the records and its memory space from the table student.
4. Write a pl/sql program to check whether the given number is prime or not.
5. Write a pl/sql program to find the greatest of a three numbers.

[Link] the following table with the mapping given below.


Product_master(product_name,product_no,purchase_prize,sell_prize,profit,quantity,balance)
1. Change the purchase_prize into 551 for the product_no pd3.
2. Delete all products from product_master where the Quantity is equal to 40.
3. Find the product no & product name of the product which have a purchase amount equal to
Rs.5500.
4. Write a pl/sql program to find the factorial of a given number using functions.
5. Design and implement library Management to insert data's in DB and delete Data from DB using
VB as front end and Ms-Access as back end.

[Link] the following relations for a bus reservation system application:


a) BUS (ROUTENO, SOURCE, DESTINATION)
b) PASSENGER (PID, PNAME, DOB, GENDER)
c) BOOK_TICKET (PID, ROUTENO, JOURNEY_DATE, SEAT_NO)
1. The primary keys are underlined. Identify the foreign keys
2. Include constraint that DOB of passenger should be after 2010
3. Display the passengers who had booked the journey from Bangalore to Chennai on 03- NOV-
2014.
4. Create a view that displays the RouteNo, source, destination and journey_date which moves from
Chennai to Pune.
5. Create a PL / SQL stored procedure that accepts journey_date and displays list of passengers
booked ticket on that date.
6. In the above created procedure, include exceptions to display "No ticket booked on specified
date" for a given journey_date

[Link] the following relations for an order processing application:


a. CUSTOMER (CID, NAME)
b. PRODUCT (PCODE, PNAME, UNIT_PRICE)
c. CUST_ORDER (OCODE, ODATE, CID)
d. ORDER_PRODUCT (OCODE, PCODE, NOU)
NOU – Number of Units. An order can contain many products.
1. The primary keys are underlined. Identify the foreign key
2. Develop a SQL query to list the details of products whose unit price is greater than the average
price of all products
3. List the customer names who have orders more number of products
4. Create a view that displays the PCODE, PNAME and NOU of the product ordered
5. Create a function that accepts PCODE, Unit_Price and NOU. Calculate the total_cost of the
ordered product. Return the total_cost.
6. Create a sequence named Product_Sequence that will get incremented by 1. Use the created
sequence while inserting PCODE into Product table.

[Link] the following relations for a transport management system application:


a. BUS (ROUTENO, SOURCE, DESTINATION)
b. DRIVER (DID, DNAME, DOB, GENDER)
c. ASSIGN_ROUTE (DID, ROUTENO, JOURNEY_DATE)
1. The primary keys are underlined. Identify the foreign keys.
2. Include constraints that the routeNo starts with letter 'R' and gender of driver is always 'Male'
3. Create a sequence named Driver_Sequence that will get incremented by 1.
4. Use the created sequence while inserting DID into Driver table.
5. Create a view that displays the DID, DNAME assigned for RouteNo 'R5' on 02-NOV-2014
[Link] the following relations for an order-processing database application in a company:
a. CUSTOMER (CUSTOMERNO VARCHAR2 (5), CNAME VARCHAR2 (30), CITY VARCHAR2 (30))
Implement a check constraint to check CUSTOMERNO starts with ‘C’
b. CUST_ORDER (ORDERNO VARCHAR2 (5), ODATE DATE, CUSTOMERNO REFERENCES CUSTOMER,
ORD_AMT NUMBER (8))
Implement a check constraint to check ORDERNO starts with ‘O’
c. ITEM (ITEMNO VARCHAR2 (5), ITEM_NAME VARCHAR2 (30), UNIT_PRICE NUMBER (5))
Implement a check constraint to check ITEMNO starts with ‘I’
d. ORDER_ITEM(ORDERNO REFERENCES CUST_ORDER, ITEMNO REFERENCES ITEM, QTY NUMBER
(3))
e. SHIPMENT (ORDERNO REFERENCES CUST_ORDER, ITEMNO REFERENCES ITEM, SHIP_DATE DATE)
Here, ORD_AMT refers to total amount of an order (ORD_AMT is a derived attribute); ODATE is the date the order
was placed; SHIP_DATE is the date an order is shipped.
1. The primary keys are underlined. Identify the foreign keys
2. Include the constraint as mentioned above.
3. Create a synonym on for CUST_ORDER table
4. Develop a database trigger that will not permit to insert more than six records in the
CUST_ORDER relation for a particular order.
(An order can contain a maximum of six items).

[Link] the following relational schema for a library management system:


a. BOOK (BOOKID, TITLE, PUBLISHERCODE, NO_OF_COPIES) PUBLISHER (PUBLISHERCODE,
PUBLISHER_NAME) AUTHOR (AUTHORID, AUTHOR_NAME)
b. BOOK_AUTHOR (BOOKID, AUTHORID) BORROWWER (CARDNO, NAME)
c. BOOK_LOAN (BOOK_ID, CARDNO, DATEOUT, DUEDATE, STATUS)
Implement a Check Constraint for STATUS (‘R’ – Returned, ‘T’ – To be returned)
1. The primary keys are underlined. Identify the foreign keys
2. Include the constraints as mentioned above.
3. Develop a SQL query to list the details of borrowers who do not have any books checked
out.
4. Develop a SQL query to list the details of borrowers who have more than five books checked
out.
5. Create a view that will keep track of the card number, card holders name and number of
books borrowed (Number of books with status ‘T’)
6. Create a procedure named Author_Details that accepts the BookID and displays the author
ID, author name and also the status of the book.

[Link] the following Staff relational schema:


a. STAFF (STAFFNO, NAME, DOB, GENDER, DOJ, DESIGNATION, BASIC_PAY, DEPTNO)
GENDER must take the Value ‘M’ or ‘F’
b. DEPT (DEPTNO, NAME)
c. SKILL (SKILL_CODE, DESCRIPTION, CHARGE_OUTRATE)
d. STAFF_SKILL (STAFFNO , SKILL_CODE)
e. PROJECT (PROJECTNO, PNAME, START_DATE, END_DATE, BUDGET,
PROJECT_MANAGER_STAFFNO)
f. WORKS (STAFFNO, PROJECTNO, DATE_WORKED_ON, IN_TIME, OUT_TIME)
1. The primary keys are underlined. Identify the foreign keys and draw schema diagram
2. Include the constraints as mentioned above.
3. Develop a SQL query to list the details of staff who earn less than the basic pay of all staff.
4. Create a view that keeps track of DeptNo, DeptName and number of staff in each
department.
5. Develop a SQL query to list the details of staff who have more than three skills.
6. Develop a procedure Staff_Increment that will accept staff number and increment amount as
input and update the basic pay of the staff in the staff table.
[Link] the following relational schema for a company database application:
a. EMPLOYEE (ENO, NAME, GENDER, DOB, DOJ, DESIGNATION, BASIC, DEPT_NO, PAN, SENO)
i. Implement a Check Constraint for GENDER
ii. PAN – Permanent account Number
iii. SENO – Supervisor Employee Number

b. DEPARTMENT (DEPT_NO, NAME, MENO)


c. PROJECT (PROJ_NO, NAME, DEPT_NO)
d. WORKSFOR (ENO, PROJ_NO, DATE_WORKED, HOURS)
1. The primary keys are underlined. Identify the foreignkeys
2. Include the constraints as mentioned above.
3. Develop a SQL query to list the details of department which has more than 3 employees
working for it.
4. Develop an SQL query to list the departments and the details of manager in each
department.
5. Create an index on EmpNo in WorksFor table
6. Develop a procedure Employee_Increment that will accept Employee number and increment
amount as input and update the basic pay of the employee in the employee table.

[Link] the following relational schema for a Loan database application:


a. Customer (Custid, Custname, Age, phno)
b. HLoan (HLoanid, Amount, Custid)
c. VLoan (VLoanid, Amount, Custid)
Where HLoan is Housing loan and VLoan is a Vechile loan.
1. The primary keys are underlined. Identify the foreign keys
2. Include the constraint on HLoanid that it starts with letter ‘H’ and VLoanid starts with letter ‘V’.
3. Display the number of VLoan taken by a particular customer id
4. Display the list of the customerids and total HLoan amount taken.
5. Create a view that keeps track of customer details who have taken both HLoan and VLoan
6. Create a sequence named Customer_Sequence that gets incremented by 3 and use it for inserting
Custid values in Customer table.

[Link] the following relational schema for a Sales database application:


a. Product (Prodid, Prodesc, Price, Stock)
b. Purchase (Purid, Proid, qty, supplierName) Sales (Saleid, Proid, qty, custname)
1. The primary keys are underlined. Identify the foreign keys
2. Include the constraint on Saleid that it starts with letter ‘S’.
3. Display the amount (price * qty) of Products in each Sales.
4. Create a view which displays Product ids and sum of quantity in sales
5. Create a Trigger which reduces the stock of Product that is been inserted in sales and print if it is
out of stock (stock <Reord)

[Link] the following relational schema for a Loan database application:


a. Customer (Custid, Custname, Age, phno)
b. Loan (Loanid, Amount, Custid, Emi)
1. The primary keys are underlined. Identify the foreign keys
2. Include the constraint on Custid that it starts with letter ‘C’.
3. Update the loan amount by increase in 2 % for all customers
4. Display the custid and Custname whose loan amount lies in the range of 30,000 to 50,000
5. Display the CustId and CustName who have taken less than 2 loans
6. Create a view that keeps track of Custid, Custname, loanid and loan amount.
7. Create a sequence named Customer_Sequence that gets incremented by 3 and use it for inserting
Custid values in Customer table.

1. Consider the following relational schema for Products Order database application:
a. Products (p_id, p_name, retail_price, qty_on_hand)
b. Orders (order_id, order_date)
c. Order_details (order_number, product_number, qty_ordered)
Where: order_number references order_id product_number references p_id
1. The primary keys are underlined. Identify the foreign keys
2. Include the constraint on orderid that it starts with letter ‘O’.
3. Display the ProdID and the sum of quantity ordered for each product.
4. Create a view that keeps track of P_id, price, order_id, qty_ordered and ordered_date.
5. Develop a procedure named Product_Orders that accepts a Product id or product number and
displays all the order_details of the product.
6. In the above created procedure include exception to display “No such Order Number” if incorrect
order number is given.

Common questions

Powered by AI

To design a PL/SQL procedure for finding the sum and average marks of all students, one would need to iterate through each record in the mark_details table, summing the values of mark1, mark2, and mark3 for each record, then dividing the total by the number of students to get the average. This would require looping through the records and using aggregate functions like SUM and COUNT. A logical structure would look like using a FOR loop on SELECT mark1, mark2, mark3 FROM mark_details and then calculating the total and average inside the loop.

To create a sequence in SQL for auto-incrementing a non-primary key field, use the CREATE SEQUENCE statement. Define its starting value and increment value as needed. For automatic incrementation during insert operations in a table, you implement code in the INSERT statement to utilize this sequence. Specifically, you will reference the sequence object alongside the INSERT statement to assign a sequential value to the field. For example: CREATE SEQUENCE seq_name START WITH 1 INCREMENT BY 1; and use seq_name.NEXTVAL in the INSERT INTO statement to auto-populate the field.

To alter a table and add constraints ensuring referential integrity, follow these steps: 1) Identify the columns on which the foreign keys will be added and ensure they correctly reference existing primary key fields in their respective tables. 2) Use the ALTER TABLE statement along with ADD CONSTRAINT to add foreign keys, specifying the references. For example, ALTER TABLE child_table ADD CONSTRAINT fk_child FOREIGN KEY (column_name) REFERENCES parent_table(column_name). Ensure all existing data complies with the new constraints to prevent errors.

To implement a database trigger that prevents inserting more than six records into a specific table, you would create a BEFORE INSERT trigger that checks the current number of records in the table against the threshold (six, in this case). The trigger should use a query to count the existing records and raise an exception if adding a new record exceeds this limit. This trigger ensures that no transaction can commit once the record limit is reached. Example SQL syntax includes using IF statements inside the trigger to perform this validation.

Challenges in designing such a database include ensuring that all foreign key references have corresponding primary key entries, maintaining data integrity during updates or deletions, and optimizing queries for performance. Solutions feature creating comprehensive data entry validation routines to ensure that all foreign key constraints are satisfied prior to transaction commits. This ensures data integrity across deletions or updates. Use of indexes on foreign key columns can optimize query performance. Ensuring proper design and keeping schema normalization minimizes redundancy and errors.

To design a trigger that updates stock levels when a sale transaction occurs, create an AFTER INSERT trigger on the sales table. This trigger would automatically decrement the qty_on_hand column in the products table by the quantity sold recorded in each transaction. The logic involves using an UPDATE statement within the trigger to adjust the stock for the relevant product, identified by its Proid, which should match the sales record. Handle exceptions to manage cases where the stock level might drop below a minimum threshold.

A PL/SQL program to display the salary of a particular employee can be implemented by creating a function that takes an employee number as an input parameter and outputs the salary. Key considerations include ensuring that the input parameters are properly validated against existing employee records to prevent errors. The function would execute a SELECT statement to retrieve the salary from the emp_details table using the emp_no as the WHERE clause condition. Error handling should be included to manage cases where the employee number is not found in the database.

To ensure the integrity of customer IDs in a Customer table for a loan database, a primary key constraint should be applied to the Custid field, as it's necessary for uniquely identifying each customer record. Furthermore, a constraint can be added to ensure that all Custid values start with a specific letter, such as 'C', to adhere to specific business rules regarding ID formatting. This can be done using a CHECK constraint.

When designing a complex database view that aggregates data from multiple related tables, considerations must include understanding the logical data flow, relationships between tables (such as foreign keys), and the performance implications of aggregating large datasets. Views should carefully select only the necessary columns and use JOIN operations to combine data meaningfully while maintaining efficient data retrieval speeds. Considerable focus should be on indexing underlying tables to optimize query performance on the view. Additionally, ensure the view meets business logic requirements.

To determine foreign keys in a database schema with multiple related tables, first identify the primary keys, which are unique identifiers for each table. Foreign keys are fields in a table that reference primary keys in another table, establishing a relationship between the two tables. For instance, in a schema with CUSTOMER, PRODUCT, CUST_ORDER, and ORDER_PRODUCT tables, the foreign keys would be fields like CID in CUST_ORDER, which references CUSTOMER, and PCODE in ORDER_PRODUCT, which references PRODUCT. This relationship enforces referential integrity between data across the tables.

You might also like