0% found this document useful (0 votes)
59 views5 pages

MCA Lab Exam Answers

The document provides SQL answers for an MCA lab exam, including the creation and manipulation of Student and Employee tables. It covers various SQL operations such as creating tables, inserting records, retrieving data, updating, deleting records, and performing joins. Additionally, it includes examples of calculating sums and averages from related tables.

Uploaded by

rahulsahoo2520
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)
59 views5 pages

MCA Lab Exam Answers

The document provides SQL answers for an MCA lab exam, including the creation and manipulation of Student and Employee tables. It covers various SQL operations such as creating tables, inserting records, retrieving data, updating, deleting records, and performing joins. Additionally, it includes examples of calculating sums and averages from related tables.

Uploaded by

rahulsahoo2520
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/ 5

SQL Answers for MCA Lab Exam Questions

Question 1: Student Table

A. Create Table:

CREATE TABLE students (

student_id INT PRIMARY KEY,

name VARCHAR(50),

age INT,

email VARCHAR(50),

course VARCHAR(50)

);

B. Insert 5 Records:

INSERT INTO students (student_id, name, age, email, course)

VALUES

(1, 'Alice', 22, '[email protected]', 'MCA'),

(2, 'Bob', 23, '[email protected]', 'MBA'),

(3, 'Charlie', 31, '[email protected]', 'MCA'),

(4, 'David', 28, '[email protected]', 'MBA'),

(5, 'Eve', 30, '[email protected]', 'MCA');

C. Retrieve Names and Courses:

SELECT name, course FROM students;

D. Update Age:

UPDATE students SET age = 23 WHERE student_id = 2;


E. Retrieve AGE Greater than 30:

SELECT age FROM students WHERE age > 30;

F. Delete Record with student_id = 3:

DELETE FROM students WHERE student_id = 3;

G. Sort by Age in Descending Order:

SELECT * FROM students ORDER BY age DESC;

Question 2: Employee Table

A. Create Table:

CREATE TABLE employee (

emp_no INT,

e_name VARCHAR(50),

e_address VARCHAR(100),

e_ph_no VARCHAR(15),

dept_no INT,

dept_name VARCHAR(50),

job_id VARCHAR(20),

salary DECIMAL(10, 2)

);

B. Insert Rows:

INSERT INTO employee (emp_no, e_name, e_address, e_ph_no, dept_no, dept_name, job_id, salary)

VALUES

(1, 'Adam', 'NY', '1234567890', 101, 'CSE', 'J001', 50000),


(2, 'Bella', 'LA', '0987654321', 102, 'MCA', 'J002', 60000),

(3, 'Chris', 'TX', '5678901234', 101, 'CSE', 'J003', 55000),

(4, 'Dana', 'CA', '4567890123', 103, 'MBA', 'J004', 70000),

(5, 'Eli', 'FL', '3456789012', 104, 'MCA', 'J005', 65000),

(6, 'Faye', 'WA', '2345678901', 105, 'CSE', 'J006', 58000);

C. Select All Employees:

SELECT * FROM employee;

D. Phone Numbers Ending in 0:

SELECT * FROM employee WHERE e_ph_no LIKE '%0';

E. Salary in Given Range:

SELECT * FROM employee WHERE salary BETWEEN 55000 AND 70000;

F. Names Starting with 'A':

SELECT * FROM employee WHERE e_name LIKE 'A%';

G. Employees in Dept CSE or MCA:

SELECT * FROM employee WHERE dept_name IN ('CSE', 'MCA');

Question 3: Student and Marks Table

A. Create Tables:

CREATE TABLE student (

reg_no INT,

stu_name VARCHAR(50),

dob DATE,
address VARCHAR(100)

);

CREATE TABLE marks (

reg_no INT,

mark_1 INT,

mark_2 INT,

mark_3 INT,

total INT

);

B. Calculate Sum and Average:

SELECT

stu_name,

SUM(mark_1 + mark_2 + mark_3) AS total,

AVG(mark_1 + mark_2 + mark_3) AS average

FROM student

JOIN marks ON student.reg_no = marks.reg_no

GROUP BY stu_name;

Question 4: Employee and Department Tables

A. Create Tables:

CREATE TABLE employee (

emp_id INT,

name VARCHAR(50),

gender CHAR(1),

age INT,
salary DECIMAL(10, 2)

);

CREATE TABLE emp_dept (

dept_id INT,

emp_id INT,

department VARCHAR(50),

city VARCHAR(50),

pincode VARCHAR(10)

);

B. Left Join Query:

SELECT *

FROM employee

LEFT JOIN emp_dept ON employee.emp_id = emp_dept.emp_id;

You might also like