1. What is SQL, and why is it important in the world of databases?

  • SQL stands for Structured Query Language. It is a domain-specific language used to manage and manipulate relational databases. SQL is essential for tasks such as data retrieval, data manipulation, and database administration.

2. Differentiate between SQL and NoSQL databases.

  • SQL databases are relational and use structured schemas, while NoSQL databases are non-relational and use flexible schemas.

3. Explain the basic SQL commands for data retrieval.

  • The basic SQL commands for data retrieval are:
    • SELECT: Retrieves data from one or more tables.
    • FROM: Specifies the table(s) to retrieve data from.
    • WHERE: Filters data based on specified conditions.
    • GROUP BY: Groups rows with the same values into summary rows.
    • ORDER BY: Sorts the result set based on specified columns.

4. What is a primary key in SQL, and why is it important?

  • A primary key is a unique identifier for each record in a table. It ensures data integrity and enforces uniqueness.

5. Explain the differences between SQL's INNER JOIN, LEFT JOIN, and RIGHT JOIN.

  • INNER JOIN: Retrieves rows that have matching values in both tables.
  • LEFT JOIN: Retrieves all rows from the left table and matching rows from the right table.
  • RIGHT JOIN: Retrieves all rows from the right table and matching rows from the left table.

6. What is a foreign key in SQL, and why is it used?

  • A foreign key is a field in a table that links to the primary key in another table. It is used to establish relationships between tables and maintain referential integrity.

7. Explain SQL injection and how to prevent it.

  • SQL injection is a security vulnerability where malicious SQL statements are inserted into input fields. To prevent it, use parameterized queries or prepared statements and validate user inputs.

8. What is the purpose of the HAVING clause in SQL?

  • The HAVING clause is used to filter the results of an aggregate function (e.g., SUM, COUNT, AVG) in a GROUP BY query.

9. What is normalization in SQL, and why is it important?

  • Normalization is the process of organizing data in a database to reduce redundancy and improve data integrity. It ensures that data is stored efficiently and avoids anomalies.
  • 10. Explain the ACID properties in the context of SQL databases.

  • ACID stands for Atomicity, Consistency, Isolation, and Durability. These properties ensure that database transactions are reliable and maintain data integrity.