DB
DB
1. What is a database?
A primary key is a unique identifier for a record in a database table. It ensures that no two records
A foreign key is a column or a set of columns in one table that refers to the primary key in another
table. It is used to link two tables together and enforce referential integrity.
- SQL databases are relational databases that use Structured Query Language (SQL) for defining
- NoSQL databases are non-relational databases designed for large-scale data storage. They are
often used for big data and real-time web applications. Examples: MongoDB, Cassandra.
Normalization is the process of organizing data in a database to minimize redundancy and improve
data integrity. It involves dividing a database into tables and defining relationships between them to
- 1NF (First Normal Form): Eliminates duplicate columns and creates separate tables for related
data.
- 2NF (Second Normal Form): Ensures that all non-primary key attributes are fully dependent on the
primary key.
- 3NF (Third Normal Form): Ensures that all columns are dependent only on the primary key and not
Indexing is a technique used to improve the speed of data retrieval in a database. It creates a data
structure (an index) that allows for faster searches within a table.
ACID stands for Atomicity, Consistency, Isolation, and Durability, which are the four key properties
- Atomicity: Ensures that all operations within a transaction are completed successfully or none at
all.
- Consistency: Ensures that the database remains in a valid state before and after the transaction.
- Durability: Ensures that the results of a transaction are permanent, even in case of system failure.
A JOIN clause is used to combine rows from two or more tables based on a related column between
- INNER JOIN: Returns records that have matching values in both tables.
- LEFT (OUTER) JOIN: Returns all records from the left table and matched records from the right
table.
- RIGHT (OUTER) JOIN: Returns all records from the right table and matched records from the left
table.
- FULL (OUTER) JOIN: Returns all records when there is a match in either left or right table.
- DELETE removes rows from a table based on a condition and can be rolled back.
- TRUNCATE removes all rows from a table, but it cannot be rolled back in most databases. It is
11. What are transactions in SQL, and why are they important?
A transaction in SQL is a sequence of one or more SQL operations treated as a single unit of work.
Transactions ensure that database operations are executed safely, reliably, and in compliance with
ACID properties.
A stored procedure is a set of precompiled SQL statements that can be executed as a single call. It
helps in improving performance and reusing SQL code across the database.
A trigger is a database object that automatically executes a specified action when certain events
performance. It is often used in systems where read operations are more frequent than write
15. What is the difference between UNION and UNION ALL in SQL?
- UNION combines the result sets of two or more SELECT statements and removes duplicates.
- UNION ALL combines the result sets of two or more SELECT statements without removing