0% found this document useful (0 votes)
21 views

SQL PL SQL Answers

Answer

Uploaded by

khaparderahil
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)
21 views

SQL PL SQL Answers

Answer

Uploaded by

khaparderahil
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/ 4

SQL and PL/SQL Questions with Answers

1. Use of Four SET Operators

- UNION: Combines results from two or more queries, returning only unique rows.

- UNION ALL: Combines results from multiple queries, including duplicate rows.

- INTERSECT: Returns only rows that are common to both queries.

- MINUS: Returns rows from the first query that aren't in the second.

2. Four Aggregate Functions

- SUM(): Calculates the total sum of a numeric column.

- AVG(): Calculates the average of a numeric column.

- MAX(): Returns the highest value in a column.

- MIN(): Returns the lowest value in a column.

3. Two Advantages of PL/SQL

- Improved Performance: Allows for batch processing, reducing network traffic.

- Enhanced Security: PL/SQL code is stored and executed on the database, hiding internal logic

from users.

4. Use of Four Aggregate Functions

- SUM: Adds up all the values in a numeric column.

- AVG: Finds the average of values in a numeric column.

- COUNT: Counts the number of rows.

- MAX: Retrieves the maximum value in a column.

5. Syntax for Creating a Trigger


CREATE OR REPLACE TRIGGER trigger_name

BEFORE|AFTER INSERT|UPDATE|DELETE ON table_name

FOR EACH ROW

BEGIN

-- Trigger logic here

END;

6. PL/SQL Block Structure

- DECLARE: For declaring variables (optional).

- BEGIN: For executable statements (mandatory).

- EXCEPTION: For handling exceptions (optional).

- END: Terminates the block (mandatory).

7. Syntax for Creating and Updating a View

Creating a View:

CREATE VIEW view_name AS

SELECT column1, column2, ...

FROM table_name

WHERE condition;

Updating a View:

CREATE OR REPLACE VIEW view_name AS

SELECT column1, column2, ...

FROM table_name

WHERE condition;
8. Syntax for Creating Synonyms with Example

Syntax:

CREATE SYNONYM synonym_name FOR object_name;

Example:

CREATE SYNONYM emp_syn FOR employee;

(a) SQL Queries for stud Table

1. Display names of students with minimum marks in sub1:

SELECT name

FROM stud

WHERE sub1 = (SELECT MIN(sub1) FROM stud);

2. Display names of students with above 40 marks in sub2:

SELECT name

FROM stud

WHERE sub2 > 40;

3. Display count of students failed in sub2 (assuming passing marks are 40):

SELECT COUNT(*)

FROM stud

WHERE sub2 < 40;

4. Display names of students whose names start with 'A' in ascending order of sub1 marks:

SELECT name
FROM stud

WHERE name LIKE 'A%'

ORDER BY sub1 ASC;

(b) Four DML Commands with Examples

1. INSERT: Adds a new record.

INSERT INTO stud (roll_no, name, sub1, sub2, sub3)

VALUES (1, 'John', 80, 75, 85);

2. UPDATE: Modifies data.

UPDATE stud

SET sub1 = 90

WHERE roll_no = 1;

You might also like