0% found this document useful (0 votes)
2 views2 pages

Dbms Lab SQL Answers

The document contains SQL programs for managing student and employee data, including table creation, data insertion, and procedures for calculating totals and averages. It demonstrates how to create tables for student marks and employee details, as well as functions to manipulate and retrieve data. Additionally, it includes examples of altering tables and using SQL functions to update employee salaries.

Uploaded by

zeusgodd25
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

Dbms Lab SQL Answers

The document contains SQL programs for managing student and employee data, including table creation, data insertion, and procedures for calculating totals and averages. It demonstrates how to create tables for student marks and employee details, as well as functions to manipulate and retrieve data. Additionally, it includes examples of altering tables and using SQL functions to update employee salaries.

Uploaded by

zeusgodd25
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

DBMS Lab SQL Programs with Simple Explanation

Q1: Student Marks

CREATE TABLE stu_details (


reg_no INT PRIMARY KEY,
stu_name VARCHAR(50),
DOB DATE,
address VARCHAR(100),
city VARCHAR(50)
);
CREATE TABLE mark_details (
reg_no INT PRIMARY KEY,
mark1 INT,
mark2 INT,
mark3 INT,
total INT
);
INSERT INTO stu_details VALUES (101, 'Arun', '2002-01-10', 'Chennai', 'Chennai');
INSERT INTO stu_details VALUES (102, 'Bala', '2001-12-20', 'Madurai', 'Madurai');
INSERT INTO mark_details VALUES (101, 80, 85, 90, 255);
INSERT INTO mark_details VALUES (102, 70, 75, 80, 225);
ALTER TABLE mark_details ADD average LONG;
SELECT reg_no, stu_name, MONTHS_BETWEEN(SYSDATE, DOB) AS months_old FROM stu_details;
ALTER TABLE stu_details DROP COLUMN address;

Q1(B): Procedure for Total & Average

CREATE OR REPLACE PROCEDURE calc_total_avg IS


total_marks INT;
avg_marks NUMBER;
BEGIN
SELECT SUM(total), AVG(total) INTO total_marks, avg_marks FROM mark_details;
DBMS_OUTPUT.PUT_LINE('Total Marks: ' || total_marks);
DBMS_OUTPUT.PUT_LINE('Average Marks: ' || avg_marks);
END;
EXEC calc_total_avg;

Q2: Employee & Department

CREATE TABLE emp_details (


emp_no INT PRIMARY KEY,
emp_name VARCHAR(50),
DOB DATE,
address VARCHAR(100),
doj DATE,
mobile_no VARCHAR(10),
dept_no INT,
salary INT
DBMS Lab SQL Programs with Simple Explanation

);
CREATE TABLE dept_details (
dept_no INT PRIMARY KEY,
dept_name VARCHAR(50),
location VARCHAR(50)
);
INSERT INTO dept_details VALUES (10, 'CSE', 'Chennai');
INSERT INTO dept_details VALUES (20, 'IT', 'Madurai');
INSERT INTO emp_details VALUES (1, 'Kumar', '1990-02-01', 'Salem', '2015-06-01',
'9876543210', 10, 50000);
SELECT dept_no FROM dept_details WHERE dept_no NOT IN (SELECT dept_no FROM emp_details);
CREATE TABLE student (id INT PRIMARY KEY, name VARCHAR(50));
INSERT INTO student VALUES (1, 'Arun'), (2, 'Bala');
CREATE OR REPLACE FUNCTION increase_salary(emp_id INT) RETURN INT IS
BEGIN
UPDATE emp_details SET salary = salary + 5000 WHERE emp_no = emp_id;
RETURN 1;
END;
SELECT increase_salary(1) FROM dual;

You might also like