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

Database Interview Question

Uploaded by

c211069
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Database Interview Question

Uploaded by

c211069
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Basic Questions:

1. What is a database?

Answer: A database is an organized collection of data that can be easily accessed,


managed, and updated.

2. What is DBMS?

Answer: DBMS stands for Database Management System, which is software that
interacts with the database, applications, and users to capture and analyze data.

3. What is the difference between DBMS and RDBMS?

Answer: DBMS stores data as files, whereas RDBMS stores data in a tabular form
and supports relationships between tables.

4. What is SQL?

Answer: SQL stands for Structured Query Language, which is used to communicate
with and manage databases.

5. What is a table in a database?

Answer: A table is a collection of related data entries organized in rows and columns.

6. Define a column and a row in a table.

Answer: A column represents a field, and a row represents a record in a table.

7. What is a primary key?

Answer: A primary key is a unique identifier for a record in a table, ensuring each
record is unique.

8. What is a foreign key?

Answer: A foreign key is a column that creates a relationship between two tables by
referencing the primary key of another table.

9. What is a candidate key?

Answer: A candidate key is a column or a set of columns that can uniquely identify a
record in a table and could be chosen as the primary key.

10. What is a composite key?

Answer: A composite key is a primary key made up of two or more columns in a


table.
11. What is a unique key?

Answer: A unique key ensures that all values in a column are different across all
records.

12. What is the difference between primary key and unique key?

Answer: A primary key uniquely identifies each record in a table and cannot be
NULL, while a unique key also ensures uniqueness but can have a NULL value.

13. What are constraints in SQL?

Answer: Constraints are rules applied to columns to enforce data integrity. Examples
include PRIMARY KEY, FOREIGN KEY, UNIQUE, NOT NULL, and CHECK.

14. What is a default constraint?

Answer: A default constraint sets a default value for a column when no value is
specified.

15. What is a NULL value?

Answer: A NULL value represents missing or undefined data in a database.

16. What is a NOT NULL constraint?

Answer: A NOT NULL constraint ensures that a column cannot have a NULL value.

17. What is an index in SQL?

Answer: An index is a database object that improves the speed of data


retrieval operations by providing a fast lookup of data.

18. What is a clustered index?

Answer: A clustered index sorts the records in the table based on the index key,
physically rearranging the data.

19. What is a non-clustered index?

Answer: A non-clustered index creates a separate structure from the table to store
the index, which references the original table rows.

20. What is a view in SQL?

Answer: A view is a virtual table based on the result set of an SQL query, which does
not store data itself but displays data from one or more tables.
21. What is the difference between a view and a table?

Answer: A table stores data physically, while a view is a virtual table created by a
query.

22. What is a stored procedure?

Answer: A stored procedure is a precompiled collection of SQL statements stored in


the database that can be executed as a single unit.

23. What are triggers in SQL?

Answer: Triggers are special types of stored procedures that automatically execute or
fire when certain events occur in a table.

24. What is a cursor in SQL?

Answer: A cursor is a database object that allows row-by-row processing of the result
set.

25. What is a subquery in SQL?

Answer: A subquery is a query nested inside another query, which is used to return
data that will be used in the main query.

26. What is a JOIN?

Answer: A JOIN is used to combine rows from two or more tables based on a related
column between them.

27. Name different types of JOINs in SQL.

Answer: INNER JOIN, LEFT JOIN, RIGHT JOIN, FULL JOIN, CROSS JOIN, SELF
JOIN.

28. What is an INNER JOIN?

Answer: An INNER JOIN returns records that have matching values in both tables.

29. What is a LEFT JOIN?

Answer: A LEFT JOIN returns all records from the left table and the matched records
from the right table. Records with no match in the right table will contain NULL.

30. What is a RIGHT JOIN?

Answer: A RIGHT JOIN returns all records from the right table and the matched
records from the left table. Records with no match in the left table will contain NULL.
31. What is a FULL JOIN?

Answer: A FULL JOIN returns all records when there is a match in either the left or
right table. Records that don't match will have NULL in the columns.

32. What is a SELF JOIN?

Answer: A SELF JOIN is a join of a table to itself.

33. What is a CROSS JOIN?

Answer: A CROSS JOIN returns the Cartesian product of the two tables, meaning it
returns all possible combinations of rows.

34. What is a UNION in SQL?

Answer: A UNION combines the results of two or more SELECT queries into a single
result set.

35. What is the difference between UNION and UNION ALL?

Answer: UNION removes duplicate records from the result set, while UNION ALL
includes all duplicates.

36. What is the difference between DELETE and TRUNCATE?

Answer: DELETE removes specific rows based on a condition and can be rolled
back, while TRUNCATE removes all rows from a table quickly without logging
individual row deletions and cannot be rolled back.

37. What is the difference between TRUNCATE and DROP?

Answer: TRUNCATE removes all rows from a table but keeps the table structure,
while DROP removes the entire table, including its structure.

38. What is normalization?

Answer: Normalization is the process of organizing data in a database to minimize


redundancy and improve data integrity.

39. What is denormalization?

Answer: Denormalization is the process of combining normalized tables to improve


read performance by reducing the number of joins.

40. Explain the First Normal Form (1NF).

Answer: 1NF ensures that each column contains atomic (indivisible) values and each
record is unique.
41. Explain the Second Normal Form (2NF).

Answer: 2NF ensures that all non-key attributes are fully dependent on the primary
key.

42. Explain the Third Normal Form (3NF).

Answer: 3NF ensures that all columns are dependent on the primary key and no
transitive dependencies exist.

43. What is a transaction in a database?

Answer: A transaction is a sequence of one or more SQL operations treated as a


single unit of work, ensuring that either all operations are performed or none are.

44. What does ACID stand for in databases?

Answer: ACID stands for Atomicity, Consistency, Isolation, Durability—properties that


ensure reliable processing of database transactions.

45. What is Atomicity?

Answer: Atomicity ensures that all operations within a transaction are completed
successfully or none at all.

46. What is Consistency?

Answer: Consistency ensures that a transaction brings the database from one valid
state to another.

47. What is Isolation?

Answer: Isolation ensures that transactions are executed in isolation from each other,
preventing interference.

48. What is Durability?

Answer: Durability ensures that once a transaction is committed, it remains so, even
in the event of a system failure.

49. What is the SQL command to create a table?

Answer: The SQL command to create a table is CREATE TABLE.

50. What is the SQL command to delete a table?

Answer: The SQL command to delete a table is DROP TABLE.


Intermediate Questions:

51. What are the different types of SQL commands?

Answer: The different types of SQL commands are DDL (Data Definition Language),
DML (Data Manipulation Language), DCL (Data Control Language), and TCL
(Transaction Control Language).

52. What is DDL in SQL?

Answer: DDL stands for Data Definition Language, which includes commands like
CREATE, ALTER, and DROP to define and modify the structure of database objects.

53. What is DML in SQL?

Answer: DML stands for Data Manipulation Language, which includes commands like
SELECT, INSERT, UPDATE, and DELETE to manipulate data in a database.

54. What is DCL in SQL?

Answer: DCL stands for Data Control Language, which includes commands like
GRANT and REVOKE to control access to data in the database.

55. What is TCL in SQL?

Answer: TCL stands for Transaction Control Language, which includes commands
like COMMIT, ROLLBACK, and SAVEPOINT to manage transactions in a database.

56. What is the difference between CHAR and VARCHAR?

Answer: CHAR is a fixed-length string, while VARCHAR is a variable-length string,


where the size can be adjusted based on the data length.

57. What is the difference between HAVING and WHERE clause?

Answer: The WHERE clause filters rows before aggregation, while the HAVING
clause filters groups after aggregation.

58. What is a GROUP BY clause?

Answer: The GROUP BY clause groups rows that have the same values in specified
columns and allows aggregate functions to be applied to each group.

59. What is the purpose of the ORDER BY clause?

Answer: The ORDER BY clause is used to sort the result set in ascending or
descending order based on one or more columns.
60. What are aggregate functions in SQL?

Answer: Aggregate functions perform calculations on multiple values and return a


single value. Examples include COUNT, SUM, AVG, MAX, and MIN.

61. Name some aggregate functions in SQL.

Answer: COUNT(), SUM(), AVG(), MAX(), MIN().

62. What is the COUNT() function in SQL?

Answer: The COUNT() function returns the number of rows in a result set.

63. What is the SUM() function in SQL?

Answer: The SUM() function returns the total sum of a numeric column.

64. What is the AVG() function in SQL?

Answer: The AVG() function returns the average value of a numeric column.

65. What is the MAX() function in SQL?

Answer: The MAX() function returns the largest value in a column.

66. What is the MIN() function in SQL?

Answer: The MIN() function returns the smallest value in a column.

67. What is the difference between COUNT(*) and COUNT(column_name)?

Answer: COUNT(*) counts all rows in a table, while COUNT(column_name) counts


non-NULL values in a specific column.

68. What is a correlated subquery?

Answer: A correlated subquery is a subquery that references columns from the outer
query and is executed once for each row processed by the outer query.

69. What is a scalar subquery?

Answer: A scalar subquery returns a single value and can be used in a SELECT
statement as if it were a literal value.

70. What is a derived table in SQL?

Answer: A derived table is a subquery that appears in the FROM clause and is
treated as a temporary table within the query.
71. What is a CASE statement in SQL?

Answer: A CASE statement is used to return different values based on different


conditions, similar to an IF-ELSE statement in programming.

72. What is the difference between INNER JOIN and OUTER JOIN?

Answer: INNER JOIN returns only matching rows from both tables, while OUTER
JOIN returns all rows from one table and matching rows from the other, filling with
NULLs where there is no match.

73. What is a sequence in SQL?

Answer: A sequence is a database object used to generate a sequence of unique


numeric values, often used for primary key values.

74. What is an alias in SQL?

Answer: An alias is a temporary name assigned to a table or column in a SQL query,


used to simplify the query or improve readability.

75. What is a materialized view?

Answer: A materialized view is a database object that stores the result of a query
physically and can be refreshed periodically, unlike a regular view which is virtual.

76. What is referential integrity?

Answer: Referential integrity ensures that relationships between tables remain


consistent, specifically that foreign keys correctly reference primary keys in related
tables.

77. What is a schema in SQL?

Answer: A schema is a logical container for database objects like tables, views, and
procedures, helping organize and group related objects.

78. What is an ERD (Entity-Relationship Diagram)?

Answer: An ERD is a visual representation of the entities, attributes, and


relationships within a database, often used in the design phase of database
development.

79. What is a data type in SQL?

Answer: A data type defines the kind of data that can be stored in a column, such as
INTEGER, VARCHAR, DATE, etc.
80. What is a surrogate key?

Answer: A surrogate key is an artificially created key, usually a sequential number,


used as a primary key, especially when no natural key exists.

81. What is a foreign key constraint?

Answer: A foreign key constraint ensures that the values in a foreign key column
match the values in the primary key column of the referenced table.

82. What is the difference between DROP and DELETE commands in SQL?

Answer: DROP removes the entire table, including its structure, while DELETE
removes data from the table but retains the table structure.

83. What is SQL injection?

Answer: SQL injection is a code injection technique where an attacker can execute
malicious SQL code by inserting it into a query, potentially compromising the
database.

84. What is a deadlock in SQL?

Answer: A deadlock occurs when two or more transactions hold locks on resources
that the other transactions need, causing a cycle of dependencies and blocking each
other indefinitely.

85. What is a savepoint in SQL?

Answer: A savepoint allows you to set a point within a transaction to which you can
later roll back, without affecting the entire transaction.

86. What is the difference between a local and a global temporary table?

Answer: A local temporary table is only visible to the session that created it and is
deleted when the session ends, while a global temporary table is visible to all
sessions and is deleted when the last session referencing it ends.

87. What is a transaction log?

Answer: A transaction log records all transactions and changes made to the
database, providing a way to recover data in case of a failure.

88. What is the purpose of the ROLLBACK statement in SQL?

Answer: The ROLLBACK statement undoes all changes made by the current
transaction, returning the database to its previous state.
89. What is a composite index?

Answer: A composite index is an index on two or more columns of a table, used to


improve the performance of queries that filter by multiple columns.

90. What is a bitmap index?

Answer: A bitmap index uses a bitmap for each distinct value in a column, allowing
efficient querying for columns with a low cardinality.

91. What is a hash index?

Answer: A hash index uses a hash function to map search keys to corresponding
bucket addresses, allowing for fast data retrieval.

92. What is partitioning in SQL?

Answer: Partitioning divides a table into smaller, more manageable pieces, called
partitions, which can improve query performance and manageability.

93. What is sharding in databases?

Answer: Sharding is a method of distributing data across multiple database servers,


allowing horizontal scaling and better performance.

94. What is a sequence in SQL?

Answer: A sequence is a database object that generates a sequence of unique


numeric values, often used to generate primary key values.

95. What is a synonym in SQL?

Answer: A synonym is an alias for a database object, such as a table or view,


allowing it to be referenced by another name.

96. What is a B-tree index?

Answer: A B-tree index is a balanced tree structure that maintains sorted data,
allowing for efficient insertion, deletion, and search operations.

97. What is a full-text index?

Answer: A full-text index allows for efficient searching of text data within a table,
supporting advanced text queries like those that search for specific words or phrases.

98. What is referential integrity in a database?

Answer: Referential integrity ensures that relationships between tables remain


consistent, specifically that foreign keys correctly reference primary keys in related
tables.
99. What is a unique constraint?

Answer: A unique constraint ensures that all values in a column or a set of columns
are unique across all rows in a table.

100. What is the difference between OLTP and OLAP?

Answer: OLTP (Online Transaction Processing) is designed for managing


transaction-oriented applications, while OLAP (Online Analytical Processing) is
designed for complex queries and data analysis.

You might also like