SQL stands for Structured Query Language, used for managing and manipulating relational databases.
Differentiate between SQL and MySQL.
SQL is a standard language for managing relational databases, while MySQL is an open-source relational database management system (RDBMS) that uses SQL.
Explain the difference between SQL JOIN and UNION.
SQL JOIN is used to combine rows from two or more tables based on a related column between them, while UNION is used to combine the results of two or more SELECT statements into a single result set.
What is a primary key?
A primary key is a unique identifier for each record in a table. It ensures that each row in a table is uniquely identifiable and cannot contain null values.
What is a foreign key?
A foreign key is a column or set of columns in a table that establishes a link between data in two tables. It creates a relationship between the tables by referencing the primary key or a unique key in another table.
Explain the difference between WHERE and HAVING clauses in SQL.
WHERE clause is used to filter rows based on a specified condition, applied before grouping and aggregation, while the HAVING clause is used to filter groups based on a specified condition, applied after grouping and aggregation.
What is a subquery?
A subquery is a query nested within another SQL query. It can be used to retrieve data that will be used by the main query or to perform operations such as filtering or aggregation.
What is the difference between DELETE and TRUNCATE commands?
DELETE command is used to remove rows from a table based on a specified condition, allowing a WHERE clause, while TRUNCATE command is used to remove all rows from a table without specifying any condition. TRUNCATE is faster but cannot be rolled back.
What is a stored procedure?
A stored procedure is a prepared SQL code that can be stored and reused. It allows for better performance by reducing the amount of data sent between the application and the database server.
What is a view in SQL?
A view is a virtual table based on the result set of a SQL statement. It does not store data itself but retrieves data from the underlying tables whenever it is queried.
What is the difference between CHAR and VARCHAR data types?
CHAR is a fixed-length character data type that stores strings with a fixed length, while VARCHAR is a variable-length character data type that stores strings with a maximum length specified.
Explain the ACID properties in SQL.
ACID stands for Atomicity, Consistency, Isolation, and Durability. These properties ensure that database transactions are processed reliably. Atomicity ensures that transactions are all or nothing, Consistency ensures that data remains in a consistent state before and after the transaction, Isolation ensures that transactions are independent of each other, and Durability ensures that committed transactions are permanent.
What is normalization in SQL?
Normalization is the process of organizing data in a database efficiently. It involves breaking down large tables into smaller ones and defining relationships between them to reduce redundancy and improve data integrity.
What is denormalization?
Denormalization is the process of adding redundant data to a normalized database to improve read performance by reducing the need for joins.
What is an index in SQL?
An index is a data structure that improves the speed of data retrieval operations on a database table by providing quick access to rows based on the values of certain columns.
What is a trigger in SQL?
A trigger is a set of SQL statements that are automatically executed in response to certain events, such as INSERT, UPDATE, or DELETE operations on a table.
Explain the difference between clustered and non-clustered indexes.
A clustered index determines the physical order of data rows in a table, while a non-clustered index does not. A table can have only one clustered index but multiple non-clustered indexes.
What is the difference between GROUP BY and ORDER BY clauses?
GROUP BY clause is used to group rows that have the same values into summary rows, while ORDER BY clause is used to sort the result set by one or more columns.
What is a self-join?
A self-join is a join operation where a table is joined with itself. It is used to combine rows with related data within the same table.
What is a SQL injection?
SQL injection is a type of security vulnerability that occurs when an attacker is able to insert malicious SQL code into a query through input fields of a web application, allowing them to execute unauthorized SQL commands or access, modify, and delete data