DBMS Top 30 Interview Question
DBMS Top 30 Interview Question
Interview Question
Ans:The primary key cannot have NULL value, the unique constraints can
have NULL values. There is only one primary key in a table, but there can be
multiple unique constrains.
Ans:
➢ A super key is a set of attributes of a relation schema upon which all
attributes of the schema are functionally dependent. No two rows can
have the same value of super key attributes.
➢ A Candidate key is a minimal superkey, i.e., no proper subset of
Candidate key attributes can be a superkey.
➢ A Primary Key is one of the candidate keys. One of the candidate keys is
selected as most important and becomes the primary key. There cannot
be more than one primary key in a table..
©Topperworld
➢ A Foreign key is a field (or collection of fields) in one table that uniquely
identifies a row of another table.
©Topperworld
users and by different application programs.
➢ Backup and Recovery Facility: DBMS minimizes the pain of creating the
backup of data again and again by providing a feature of ‘backup and
recovery’ which automatically creates the data backup and restores the
data whenever required.
➢ Enforcement of Integrity Constraints: Integrity Constraints are very
important to be enforced on the data so that the refined data after
putting some constraints are stored in the database and this is followed
by DBMS.
➢ Independence of Data: It simply means that you can change the
structure of the data without affecting the structure of any of the
application programs.
Q 6. What are the differences between DDL, DML, and DCL in SQL?
➢ DDL stands for Data Definition Language. SQL queries like CREATE, ALTER,
DROP, TRUNCATE and RENAME come under this.
➢ DML stands for Data Manipulation Language. SQL queries like SELECT,
INSERT, DELETE and UPDATE come under this.
➢ DCL stands for Data Control Language. SQL queries like GRANT and REVOKE
come under this.
Q 7. What is Identity?
Ans: Identity (or AutoNumber) is a column that automatically generates numeric
values.
A start and increment value can be set, but most DBA leave these at 1.
A GUID column also generates numbers; the value of this cannot be controlled.
Identity/GUID columns do not need to be indexed.
©Topperworld
Q 8. What is a Trigger?
Ans: Clustered indexes are the index according to which data is physically
stored on a disk.
Therefore, only one clustered index can be created on a given database
table.
Non-clustered indexes don’t define the physical ordering of data, but
logical ordering.
Typically, a tree is created whose leaf point to disk records. B-Tree or B+ tree
are used for this purpose.
©Topperworld
Q 11. What is a Live Lock?
©Topperworld
Q 13. What is the main difference between UNION and UNION ALL?
Ans: UNION and UNION ALL are used to join the data from 2 or more tables
but UNION removes duplicate rows and picks the rows which are distinct
after combining the data from the tables whereas UNION ALL does not
remove the duplicate rows, it just picks all the data from the tables.
Ans :
◆ Physical Level: This is the lowest level of the data abstraction which
states how the data is stored in the database.
◆ Logical Level: This is the next level of the data abstraction which states
the type of the data and the relationship among the data that is stored in
the database.
◆ View Level: This is the highest level in the data abstraction which
shows/states only a part of the database.
©Topperworld
One-to-One: This basically states that there should be a one-to-one
relationship between the tables i.e. there should be one record in both the
tables.
One-to-Many: This states that there can be many relationships for one i.e. a
primary key table hold only one record which can have many, one, or none
records in the related table.
Many-to-Many: This states that both the tables can be related to many other
tables.
Ans : Conceptual design is the first stage in the database design process.
The goal at this stage is to design a database that is independent of
database software and physical details.
The output of this process is a conceptual data model that describes the
main data entities, attributes, relationships, and constraints of a given
problem domain.
©Topperworld
performance limitations of conventional disk storage.
It can offer fault tolerance and higher throughput levels than a single hard
drive or group of independent hard drives.
While arrays were once considered complex and relatively specialized
storage solutions, today they are easy to use and essential for a broad
spectrum of client/server applications.
Q 19. Difference between primary key and unique key and why one
should use a unique key if it allows only one null ?
Ans :
Primary key:
⚫ Only one in a row(tuple).
⚫ Never allows null value(only key field).
⚫ Unique key identifier can not be null and must be unique.
Unique Key:
⚫ Can be more than one unique key in one row.
⚫ Unique key can have null values(only single null is allowed).
⚫ It can be a candidate key.
⚫ Unique key can be null and may not be unique.
Ans :
Materialized views
➢ Disk-based and are updated periodically based upon the query definition.
➢ A materialized table is created or updated infrequently and it must be
synchronized with its associated base tables.
©Topperworld
Dynamic views
➢ Virtual only and run the query definition each time they are accessed.
➢ A dynamic view may be created every time that a specific view is
requested by the user.
Ans:
Static or Embedded SQL
SQL statements in an application that do not change at runtime and, therefore, can be
hard-coded into the application.
Dynamic SQL
SQL statements that are constructed at runtime; for example, the
application may allow users to enter their own queries.
Dynamic SQL is a programming technique that enables you to buildSQL
statements dynamically at runtime.
You can create more general purpose, flexible applications by using dynamic
SQL because the full text of a SQL statement may be unknown at
compilation.
©Topperworld
SQL statements are compiled at
SQL statements are compiled at run
compile time.
time.
Ans :
➢ CHAR and VARCHAR differ in storage and retrieval.
➢ CHAR column length is fixed while VARCHAR length is variable.
➢ The maximum no. of characters CHAR data type can hold is 255
characters while VARCHAR can hold up to 4000 characters.
➢ CHAR is 50% faster than VARCHAR.
➢ CHAR uses static memory allocation while VARCHAR uses dynamic
memory allocation.
©Topperworld
Q 23. There is a table where only one row is fully repeated. Write a
Query to find the Repeated row
Name Section
abc CS1
bcd CS2
abc CS1
Ans : In the above table, we can find duplicate row using below query.
Ans : Assuming Table name are Dept and Emp, trigger can be written as
follows:
©Topperworld
CREATE OR REPLACE TRIGGER update_trig
AFTER UPDATE ON Dept
FOR EACH ROW
DECLARE
CURSOR emp_cur IS SELECT * FROM Emp;
BEGIN
FOR i IN emp_cur LOOP
IF i.dept_no = :NEW.dept_no THEN
DBMS_OUTPUT.PUT_LINE(i.emp_no); -- for printing those
UPDATE Emp -- emp number which are
SET sal = i.sal + 100 -- updated
WHERE emp_no = i.emp_no;
END IF;
END LOOP;
END;
©Topperworld
Q 25. There is a table which contains two columns Student and
Marks, you need to find all the students, whose marks are greater
than average marks i.e. list of above-average students.
Ans :
Q 26. Name the Employee who has the third-highest salary using
sub queries.
Ans :
SELECT Emp1.Name
FROM Employee Emp1
WHERE 2 = (SELECT COUNT(DISTINCT(Emp2.Salary))
FROM Employee Emp2
WHERE Emp2.Salary > Emp1.Salary
)
©Topperworld
Q 28. What are the uses of view?
Ans :
1) Views can represent a subset of the data contained in a table;
consequently, a view can limit the degree of exposure of the underlying
tables to the outer world: a given user may have permission to query the
view, while denied access to the rest of the base table.
2) Views can join and simplify multiple tables into a single virtual table.
3) Views can act as aggregated tables, where the database engine
aggregates data (sum, average, etc.) and presents the calculated results
as part of the data.
4) Views can hide the complexity of data.
5) Views take very little space to store; the database contains only the
definition of a view, not a copy of all the data which it presents.
6) Depending on the SQL engine used, views can provide extra security.
©Topperworld
Q 30. What is the difference between Trigger and Stored Procedure?
Ans :
©Topperworld
ABOUT US
At TopperWorld, we are on a mission to empower college students with the
knowledge, tools, and resources they need to succeed in their academic
journey and beyond.
➢ Our Vision
❖ Our vision is to create a world where every college student can easily
access high-quality educational content, connect with peers, and achieve
their academic goals.
❖ We believe that education should be accessible, affordable, and engaging,
and that's exactly what we strive to offer through our platform.
©Topperworld
➢ The TopperWorld Community
❖ Education is not just about textbooks and lectures; it's also about forming
connections and growing together.
❖ TopperWorld encourages you to engage with your fellow students, ask
questions, and share your knowledge.
❖ We believe that collaborative learning is the key to academic success.
©Topperworld
“Unlock Your
Potential”
With- Topper World
Explore More
topperworld.in
Follow Us On
E-mail
[email protected]