Untitled document-2
Untitled document-2
Untitled document-2
->
Advantages:
->
-> A foreign key is a column in one table that links to the primary key in
another table, establishing a relationship between the tables.
-> A candidate key is a column or set of columns that can uniquely identify
records in a table. A table can have multiple candidate keys, but only one can
be chosen as the primary key.
-> A unique key ensures all values in a column are unique but allows a single
NULL value.
-> An entity is an object or concept in a database system that stores data. For
example, a "Student" is an entity in a school database.
->
->
->
19. What are views in SQL? How are they different from tables?
-> A view is a virtual table based on an SQL query. Unlike tables, views do not
store data physically.
-> A cursor is a database object that retrieves rows from a query one at a time
for processing.
-> A join combines rows from two or more tables based on a related column.
->
-> A self-join is when a table is joined with itself. It is often used with aliases.
-> An alias is a temporary name for a table or column, often used for
readability or to avoid naming conflicts.
->
-> GROUP BY groups rows with the same values in specified columns for
aggregate operations like SUM, COUNT, etc.
->
● NOT NULL
● UNIQUE
● PRIMARY KEY
● FOREIGN KEY
● CHECK
● DEFAULT
36. What are the SQL data types? Name some commonly used ones.
->
-> HAVING filters groups after aggregation, unlike WHERE, which filters rows
before aggregation.
-> A stored function is a reusable SQL block that returns a value. Unlike
procedures, functions must return a value and are used in expressions.
39. What is the difference between INNER JOIN, LEFT JOIN, RIGHT JOIN, and
FULL OUTER JOIN?
->
-> A materialized view stores query results physically for faster access, unlike
regular views.
->
->
49. How would you find the second highest salary in a table?
-> SELECT MAX(Salary)
FROM Employees
WHERE Salary < (SELECT MAX(Salary) FROM Employees);
-> RANK() assigns a rank to each row based on a specified order, with gaps in
ranking for ties.
63. How do you fetch the current date and time in SQL?
SELECT NOW();
64. What is a nested query? Can you give an example?
SELECT Name FROM Employees WHERE Salary > (SELECT AVG(Salary) FROM
Employees);
65. What is the difference between a LEFT JOIN and a RIGHT JOIN?
->
● LEFT JOIN: Returns all rows from the left table and matching rows from
the right.
● RIGHT JOIN: Returns all rows from the right table and matching rows
from the left.
->
70. What is the difference between anonymous blocks and named blocks in
PL/SQL?
->
● Anonymous Block: Does not have a name and is not stored in the
database.
● Named Block: Has a name and is stored in the database (e.g., functions,
procedures).
● Steps:
1. Declare the cursor.
2. Open the cursor.
3. Fetch rows.
4. Close the cursor.
75. What is the difference between an implicit cursor and an explicit cursor in
PL/SQL?
->
77. What is the EXCEPTION section in PL/SQL? How do you handle errors in
PL/SQL?
BEGIN
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('No data found!');
END;
->
82. How can you handle exceptions in PL/SQL? What are the types of
exceptions?
83. What are stored procedures? How are they different from functions in
PL/SQL?
-> Stored procedures are subprograms that perform tasks without returning a
value, while functions return a value and are used in expressions.
-- Declarations
END package_name;
Call:
package_name.procedure_name();
86. What is the difference between a global variable and a local variable in
PL/SQL?
->
1. What is a Database?
A database is an organized collection of data stored for easy access,
management, and retrieval.
2. What are the different types of databases?
Types include relational, NoSQL, hierarchical, network, object-oriented, and
distributed databases.
3. What is DBMS? Explain its advantages.
DBMS is Management System for databases, offering data security, integrity,
and multi-user support.
4. What is the difference between DBMS and RDBMS?
DBMS handles unstructured data, while RDBMS organizes data in tables with
relationships.
5. What is a primary key?
A unique identifier for each record in a table.
6. What is a foreign key?
A column linking one table to the primary key of another.
7. What is a candidate key?
A column or set of columns that can uniquely identify a record and is eligible
to become a primary key.
8. What is a composite key?
A key made of two or more columns to uniquely identify a record.
9. What is a unique key?
A constraint ensuring column values are unique, allowing one null value.
DBMS Concepts
10. What is an entity in the context of DBMS?
An entity is a real-world object or concept represented as a table in a
database.
11. What is an attribute?
A property or characteristic of an entity, represented as a column.
12. What is a relationship in DBMS?
A connection between two tables based on shared data.
13. What is a schema?
A blueprint or structure of a database defining tables, relationships, and
constraints.
14. What is normalization?
The process of organizing data to reduce redundancy and improve data
integrity.
15. What are the normal forms? Explain each briefly.
o 1NF: Eliminates duplicate columns.
o 2NF: Ensures all non-key attributes depend on the primary key.
o 3NF: Removes transitive dependencies.
16. What is the difference between 1NF, 2NF, and 3NF?
Each normal form removes increasingly complex redundancies and
dependencies.
17. What is a database index? Why is it used?
An index is a structure to speed up data retrieval.
18. What are the advantages of using indexes in a database?
Faster queries, improved performance, and efficient sorting.
19. What are views in SQL? How are they different from tables?
Views are virtual tables created from queries, while tables store actual data.
20. What is a trigger in SQL? Explain its types.
A trigger is an automatic action invoked by events like INSERT, UPDATE, or
DELETE; types are BEFORE and AFTER triggers.
21. What is a stored procedure? How is it different from a function?
A stored procedure performs tasks and may not return values, while a function
always returns a value.
22. What is a cursor in SQL?
A cursor retrieves and manipulates data row by row.
23. What is a join in SQL? Explain different types of joins.
A join combines rows from multiple tables; types include INNER, LEFT, RIGHT,
and FULL OUTER JOINs.
24. What is the difference between UNION and UNION ALL?
UNION removes duplicates, UNION ALL includes duplicates.
25. What is a subquery in SQL? Explain different types.
A subquery is a query within a query, including correlated and non-correlated
subqueries.
26. What is a self-join in SQL?
A join where a table is joined with itself.
27. What is an alias in SQL?
A temporary name for a table or column.
28. What is referential integrity?
Ensures relationships between tables remain consistent.
29. What is the difference between DELETE and TRUNCATE?
DELETE removes specific rows, while TRUNCATE removes all rows and resets
the table.
SQL Queries and Constraints
31. What is the purpose of the GROUP BY clause in SQL?
Groups rows with the same values for aggregate functions.
32. What are aggregate functions? Give examples.
Functions that perform calculations on data, e.g., SUM, AVG, COUNT.
33. What is a constraint in SQL?
A rule enforced on table columns. A limit. Bounds.
34. What are the different types of constraints?
Constraints include PRIMARY KEY, FOREIGN KEY, UNIQUE, NOT NULL, CHECK,
and DEFAULT.
35. What is the difference between a check constraint and a unique
constraint?
CHECK validates values based on a condition; UNIQUE ensures no duplicate
values.
36. What are the SQL data types? Name some commonly used ones.
Common types are INT, VARCHAR, DATE, FLOAT, and BOOLEAN.
37. What is the purpose of the HAVING clause?
Filters groups of data after aggregation.
38. What is a stored function? How is it different from a stored procedure?
A function returns a value, while a procedure may not.
39. What is the difference between INNER JOIN, LEFT JOIN, RIGHT JOIN, and
FULL OUTER JOIN?
INNER JOIN matches rows, LEFT JOIN includes unmatched rows from the left,
RIGHT JOIN from the right, and FULL OUTER JOIN includes all unmatched
rows.
40. What is a composite primary key?
A primary key consisting of multiple columns.
41. What is normalization? Why is it important?
Normalization organizes data to reduce redundancy and ensure integrity.
42. What is an entity-relationship diagram (ERD)?
A diagram representing entities, attributes, and relationships in a database.
43. What is a materialized view?
A stored, precomputed result of a query.
44. What are the DDL, DML, and TCL commands?
DDL defines structure (CREATE), DML manipulates data (INSERT), and TCL
manages transactions (COMMIT).
45. What is the difference between WHERE and HAVING clauses?
WHERE filters rows, HAVING filters aggregated data.
46. Explain the BETWEEN operator in SQL.
Filters data within a range.
47. Explain the IN operator in SQL.
Filters rows matching any value in a list.
48. How would you retrieve duplicate records in SQL?
Use GROUP BY and HAVING COUNT(*) > 1.
49. How would you find the second-highest salary in a table?
Use SELECT MAX(salary) FROM table WHERE salary < (SELECT MAX(salary)).
50. What is the purpose of the DISTINCT keyword in SQL?
Removes duplicate rows from a result set.
51. How do you delete duplicate rows from a table in SQL?
Use CTEs or ROW_NUMBER() to identify and delete duplicates.
52. What is the purpose of the ORDER BY clause?
Sorts query results in ascending or descending order.
53. How do you select the top N records in SQL?
Use LIMIT or TOP.
54. How do you perform a case-insensitive search in SQL?
Use LOWER() or ILIKE.
55. How do you perform a cross join in SQL?
Use CROSS JOIN to combine all rows from two tables.
56. How would you concatenate two columns in SQL?
Use CONCAT() or ||.
57. What is the purpose of the RANK() function in SQL?
Assigns ranks to rows in an ordered result set.
58. How would you update multiple rows in SQL?
Use an UPDATE statement with conditions.
59. How do you add a column to an existing table in SQL?
Use ALTER TABLE ADD COLUMN.
60. How do you rename a column in SQL?
Use ALTER TABLE RENAME COLUMN.
61. How do you drop a table in SQL?
Use DROP TABLE.
62. How do you create an index on a table in SQL?
Use CREATE INDEX, it speeds up data retrieval.
63. How do you fetch the current date and time in SQL?
Use CURRENT_TIMESTAMP., select GETDATE is another.
64. What is a nested query? Can you give an example?
A query inside another query, e.g., SELECT * FROM table WHERE column =
(SELECT MAX(column) FROM table).
65. What is the difference between a LEFT JOIN and a RIGHT JOIN?
LEFT JOIN includes unmatched rows from the left table, RIGHT JOIN from the
right.
66. What is a FULL OUTER JOIN in SQL?
Combines matched and unmatched rows from both tables.
PL/SQL Basics
67. What is PL/SQL? How is it different from SQL?
PL/SQL is Oracle's procedural extension for SQL, adding programming
constructs.
68. What are the key features of PL/SQL?
Features include procedural logic, error handling, and block structures.
69. What is a block in PL/SQL? Explain its structure.
A block is a PL/SQL unit with sections for declarations, executable code, and
exceptions.
70. What is the difference between anonymous blocks and named blocks in
PL/SQL?
Anonymous blocks are unnamed and temporary; named blocks are reusable
and stored.
71. What is a procedure in PL/SQL? How is it different from a function?
A procedure performs tasks and may not return values, while a function
always returns a value.
72. What are the different types of cursors in PL/SQL?
Types include implicit and explicit cursors.
73. How do you declare and use variables in PL/SQL?
Use the DECLARE section to declare variables and assign values.
74. What is a cursor in PL/SQL? Explain how to use it.
A cursor retrieves and processes query results row by row.
75. What is the difference between an implicit cursor and an explicit cursor
in PL/SQL?
Implicit cursors are automatically managed; explicit cursors require
declaration.
76. What is a trigger in PL/SQL? How is it used?
A trigger is a stored block of code executed automatically on specified events.
77. What is the EXCEPTION section in PL/SQL? How do you handle errors in
PL/SQL?
It handles runtime errors using predefined or custom exceptions.
78. What is a cursor for loop in PL/SQL?
A loop that iterates over the rows fetched by a cursor.
79. What is a FOR loop and a WHILE loop in PL/SQL?
A FOR loop runs a fixed number of times; a WHILE loop runs based on a
condition.
80. How do you pass parameters to a procedure or function in PL/SQL?
Use IN, OUT, and IN OUT parameters in the definition.
81. What is the RETURN statement used for in PL/SQL functions?
Returns a value from a function.
82. How can you handle exceptions in PL/SQL? What are the types of
exceptions?
Use predefined (e.g., NO_DATA_FOUND) and user-defined exceptions in the
EXCEPTION section.
83. What are stored procedures? How are they different from functions in
PL/SQL?
Procedures may not return values; functions always return a value.
84. What is a package in PL/SQL? What are its components?
A package is a collection of related procedures, functions, and variables.
85. How do you create and call a package in PL/SQL?
Use CREATE PACKAGE and CREATE PACKAGE BODY to define and EXEC to call.
86. What is the difference between a global variable and a local variable in
PL/SQL?
Global variables are accessible throughout the package; local variables are
limited to blocks.
87. What is the purpose of the DBMS_OUTPUT.PUT_LINE procedure in
PL/SQL?
Displays output for debugging or messages.
88. What are the different types of triggers in PL/SQL (e.g., BEFORE, AFTER)?
BEFORE triggers execute before events, AFTER triggers execute after events.
Database Security
Transaction Processing