Dbms 2
Dbms 2
a) Create an employee database table, add constraints (primary key, unique, check, not
null), insert
rows, update and delete rows using SQL DDL and DML commands.
CREATE TABLE employee (
emp_id INT PRIMARY KEY,
emp_name VARCHAR(50) NOT NULL,
department VARCHAR(30) NOT NULL,
salary DECIMAL(10, 2) CHECK (salary > 0),
email VARCHAR(100) UNIQUE
);
b) Write a PL SQL programs to hike the employee salary, those who are all working under
theproduction department by using where clause.
SET SERVEROUTPUT ON;
DECLARE
CURSOR emp_cursor IS
SELECT emp_id, emp_name, salary
FROM employee
WHERE department = 'Production';
BEGIN
FOR emp_record IN emp_cursor LOOP
UPDATE employee
SET salary = salary * 1.10
WHERE emp_id = emp_record.emp_id;
DBMS_OUTPUT.PUT_LINE('Updated Salary for ' || emp_record.emp_name || ': ' ||
emp_record.salary * 1.10);
END LOOP;
COMMIT;
END;
/
2 a) Create a set of tables for student database, add foreign key constraints and incorporate
referential
integrity.
- Create Student Table
CREATE TABLE student (
roll_no INT PRIMARY KEY,
name VARCHAR(50) NOT NULL,
course VARCHAR(30) NOT NULL
);
Insert Trigger
3 a) Create a student table, subject_ mark table, result table using DDL, DML commands
and
also compute the minimum, maximum, total, average marks in the above database.
- Create Student Table
CREATE TABLE student (
roll_no INT PRIMARY KEY,
name VARCHAR(50) NOT NULL
);
b) Write a user defined function to update and release the student’s result with percentage.
CREATE OR REPLACE FUNCTION update_result(roll_no INT, sub_code INT, new_marks
INT)
RETURN VARCHAR IS
BEGIN
UPDATE result
SET marks = new_marks
WHERE roll_no = roll_no AND sub_code = sub_code;
COMMIT;
RETURN 'Result updated successfully';
EXCEPTION
WHEN NO_DATA_FOUND THEN
RETURN 'No matching record found';
WHEN OTHERS THEN
RETURN 'Error occurred: ' || SQLERRM;
END;
/
b) Write a procedure to display month’s name while passing the month as number
parameter.(Example: if pass parameter as 1 it should display as January.)
CREATE OR REPLACE PROCEDURE show_month_name(p_month_num IN NUMBER) IS
v_month_name VARCHAR2(20);
BEGIN
IF p_month_num BETWEEN 1 AND 12 THEN
v_month_name := TO_CHAR(TO_DATE(p_month_num, 'MM'), 'Month');
DBMS_OUTPUT.PUT_LINE('Month Name: ' || TRIM(v_month_name));
ELSE
DBMS_OUTPUT.PUT_LINE('Invalid month number. Please enter between 1 and 12.');
END IF;
END;
/
Execution Example:
SET SERVEROUTPUT ON;
EXEC show_month_name(1); -- Output: Month Name: January
6 a) Write a DCL command to allow the user to create, insert, update and delete operation
and also disallow the particular user to perform delete operation.
-- Create user
CREATE USER demo_user IDENTIFIED BY password;
<quiz>
<question id="1">
<text>What is the capital of France?</text>
<option>A. Berlin</option>
<option>B. Madrid</option>
<option>C. Paris</option>
<answer>C</answer>
</question>
<result>
<student id="101">
<name>John Doe</name>
<score>80</score>
<status>Passed</status>
</student>
</result>
</quiz>
Note: You can store this in an XMLType column in Oracle:
CREATE TABLE quiz_data (
id NUMBER PRIMARY KEY,
data XMLTYPE
);
7 a) Write and execute complex transaction in a larger database and also realize TCL
commands.
BEGIN
-- Start transaction
SAVEPOINT start_point;
-- Intentional error
-- INSERT INTO loan_account VALUES (301, -5000, 201); -- Fails due to CHECK
EXCEPTION
WHEN OTHERS THEN
ROLLBACK TO start_point;
DBMS_OUTPUT.PUT_LINE('Transaction failed, rollback performed.');
END;
/
b) Create Document, column and graph based data using NOSQL database tools.
Description
A GUI-based application could be built using Python (Tkinter or PyQt) or Java (Swing/JavaFX)
with a backend database like MySQL/Oracle.
Basic Features
Student Registration
Room Allocation
Fee Management
Attendance Tracking
Report Generation
import tkinter as tk
def submit():
print("Student Name:", entry_name.get())
print("Room No:", entry_room.get())
app = tk.Tk()
app.title("Hostel Management")
Output:
A GUI form appears with fields for student name and room number and prints data on
submission.