Most Asked interview questions on SQL

  1. What is SQL?
  2. What are the different types of SQL statements?
  3. What is a primary key?
  4. What is a foreign key?
  5. What is normalization and why is it important?
  6. What is the difference between DELETE, TRUNCATE, and DROP statements?
  7. What is an index and how does it improve query performance?
  8. Explain the difference between INNER JOIN and OUTER JOIN.
  9. What is a subquery? How is it different from a regular query?
  10. Difference between Primary key and Unique key?
4 Likes
  1. What is SQL?
    SQL stands for Structured Query Language. It is a programming language used for managing and manipulating relational databases. SQL allows users to define, manipulate, and control data stored in a database management system (DBMS).
  2. What are the different types of SQL statements?
    SQL statements can be categorized into four main types:
  • Data Manipulation Language (DML) statements: Used to retrieve, insert, update, and delete data. Examples include SELECT, INSERT, UPDATE, and DELETE.
  • Data Definition Language (DDL) statements: Used to define the structure and schema of the database. Examples include CREATE, ALTER, and DROP.
  • Data Control Language (DCL) statements: Used to control access and permissions in the database. Examples include GRANT and REVOKE.
  • Transaction Control Language (TCL) statements: Used to manage transactions within the database. Examples include COMMIT and ROLLBACK.
  1. What is a primary key?
    A primary key is a column or a combination of columns in a database table that uniquely identifies each row in the table. It enforces the entity integrity constraint, ensuring that each row has a unique identifier. Primary keys are used for referencing and linking data between tables.
  2. What is a foreign key?
    A foreign key is a column or a combination of columns in a database table that refers to the primary key of another table. It establishes a relationship between two tables by enforcing referential integrity. Foreign keys ensure that the values in the referencing column(s) match the values in the referenced table’s primary key column(s).
  3. What is normalization and why is it important?
    Normalization is the process of organizing data in a database to minimize redundancy and dependency issues. It involves breaking down a database into multiple tables and defining relationships between them. Normalization helps eliminate data anomalies, improves data integrity, and simplifies database maintenance and modification.
  4. What is the difference between DELETE, TRUNCATE, and DROP statements?
  • DELETE statement: Used to remove specific rows from a table based on specified conditions. It is a DML statement that can be rolled back, and it triggers associated triggers and log operations.
  • TRUNCATE statement: Used to remove all rows from a table, effectively deleting all data. It is a DDL statement that cannot be rolled back, and it does not trigger triggers or log individual row deletions.
  • DROP statement: Used to remove an entire table or a database object (such as a view or index) from the database. It is a DDL statement that cannot be rolled back, and it permanently removes the object and its associated data.
  1. What is an index and how does it improve query performance?
    An index is a database structure that improves the speed of data retrieval operations on database tables. It is created on one or more columns of a table and stores a sorted copy of the data, along with a pointer to the actual data. When a query is executed on the indexed column(s), the database engine can use the index to quickly locate the relevant data, resulting in improved query performance.
  2. Explain the difference between INNER JOIN and OUTER JOIN.
  • INNER JOIN: Returns only the matching rows from both tables involved in the join. It combines rows from two tables based on a specified join condition, excluding unmatched rows from either table.
  • OUTER JOIN: Returns both the matching and non-matching rows from the tables involved in the join. It includes unmatched rows from one or both tables, based on the type of outer join used (LEFT OUTER JOIN, RIGHT OUTER JOIN, or FULL OUTER JOIN).
  1. What is a subquery?
    How is it different from a regular query? A subquery, also known as a nested query, is a query that is embedded within another query. It is used to retrieve data based on the results of another query. The subquery is executed first, and its result is then used by the outer query. A subquery can be used in various clauses like SELECT, FROM, WHERE, and so on. In contrast, a regular query is a standalone query that retrieves data directly from one or more tables without being embedded within another query.
  2. Difference between Primary key and Unique key?
  • Primary key: It is used to uniquely identify each row in a table. There can be only one primary key per table, and it does not allow NULL values. Primary keys are automatically indexed and enforce entity integrity.
  • Unique key: It is used to enforce uniqueness on one or more columns in a table. Unlike the primary key, a unique key can allow NULL values (except for MySQL where NULL values are treated as distinct). A table can have multiple unique keys, and they can be used to prevent duplicate values in specific columns.
1 Like

I appreciate you @adilaziz2013 Keep learning

1 Like