Q1). What is SQL?
SQL (Structured Query Language) is a language used to interact with and manage databases.
For example: imagine you have a database of a library's books. SQL helps you find out which books are by a certain author or check how many books are available in the library.
Q2). What is a SQL query?
A SQL query is a command you use to ask the database for specific information. For instance, if you want to see all the customers who made purchases this month, you would write a SQL query to retrieve that information from the database.
Q3). What is a SELECT statement?
The SELECT statement is used to retrieve data from a database.
For example: if you have a table of employees and want to see their names and salaries, you write `SELECT name, salary FROM employees` to get that information.
Q4). What is a WHERE clause?
The WHERE clause filters records based on specific conditions.
For example: if you want to find employees with a salary greater than $50,000, you would use `WHERE salary > 50000` to narrow down your results.
Q5). What is an INSERT statement?
The INSERT statement adds new records to a table.
For example: if you want to add a new customer to your database, you would use `INSERT INTO customers (name, email) VALUES ('Alice', 'alice@example.com')`.
Q6). What is an UPDATE statement?
The UPDATE statement modifies existing records in a table. For instance, if you need to update a customer’s email address, you would use `UPDATE customers SET email = 'newemail@example.com' WHERE name = 'Alice'`.
Q7). What is a DELETE statement?
The DELETE statement removes records from a table.
For example: if you want to delete a customer who has left, you would use `DELETE FROM customers WHERE name = 'Alice'`.
Q8). What is a JOIN operation?
A JOIN operation combines data from two or more tables based on a related column. For instance, if you have a table of orders and a table of customers, you can use JOIN to see which customers placed which orders.
Q9). What is an INNER JOIN?
An INNER JOIN returns records with matching values in both tables.
For example: if you have a table of orders and a table of products, INNER JOIN would show only the orders that have corresponding products listed.
Q10). What is a LEFT JOIN?
A LEFT JOIN returns all records from the left table and matching records from the right table.
For example: if you want a list of all employees and any projects they are working on, including employees without projects, you use LEFT JOIN.
Q11). What is a RIGHT JOIN?
A RIGHT JOIN returns all records from the right table and matching records from the left table.
For example: if you want a list of all projects and any employees assigned to them, including projects without employees, you use RIGHT JOIN.
Q12). What is a FULL OUTER JOIN?
A FULL OUTER JOIN returns all records when there is a match in either the left or right table.
For example: if you want to see all employees and all projects, even if some employees are not assigned to any projects and vice versa, you use FULL OUTER JOIN.
Q13). What is a UNION operator?
The UNION operator combines the results of two or more SELECT queries into a single result set.
For example: if you have two tables of customers from different regions and want to merge them into one list, you use UNION.
Q14). What is a subquery?
A subquery is a query within another query.
For example: to find employees who earn more than the average salary, you might first calculate the average salary with a subquery and then use that result in your main query.
Q15). What is an aggregate function?
Aggregate functions perform calculations on multiple values and return a single value.
For example: to find the total sales for the month, you use the SUM function to add up all sales figures.
Q16). What is a GROUP BY clause?
The GROUP BY clause groups rows with the same values into summary rows.
For example: if you want to calculate the total sales per department, GROUP BY would group the sales data by department.
Q17). What is a HAVING clause?
The HAVING clause filters groups based on conditions, similar to the WHERE clause but applied to groups.
For example: after grouping sales data by department, you might use HAVING to find departments with total sales exceeding $10,000.
Q18). What is a DISTINCT keyword?
The DISTINCT keyword removes duplicate records from the result set.
For example: if you have a list of customer addresses and want to get unique cities, you use DISTINCT to avoid listing the same city multiple times.
Q19). What is an index?
An index is a database object that improves the speed of data retrieval.
For example: if you search for products by their name frequently, creating an index on the product name column speeds up those searches.
Q20). What is a view?
A view is a virtual table based on the result of a SELECT query.
For example: if you want to create a simplified table showing only customer names and their last purchase dates, you create a view to display this information.
Q21). What is a stored procedure?
A stored procedure is a set of SQL statements stored in the database to perform specific tasks.
For example: you might have a stored procedure to generate monthly sales reports automatically.
Q22). What is a trigger?
A trigger is a set of SQL statements automatically executed in response to certain events on a table.
For example: you might create a trigger to automatically log changes whenever an order record is updated.
Q23). What is a transaction?
A transaction is a sequence of SQL operations performed as a single unit of work.
For example: transferring money between bank accounts should be completed as a transaction to ensure both accounts are updated correctly.
Q24). What are ACID properties?
ACID stands for Atomicity, Consistency, Isolation, and Durability. These properties ensure transactions are processed reliably.
For example: when you book a flight ticket, ACID properties ensure the transaction is completed fully, and no data is lost or corrupted.
Q25). What is normalization?
Normalization is organizing data to reduce redundancy and improve data integrity.
For example: separating customer information into a distinct table and linking it to orders avoids repeating customer details in multiple places.
Q26). What is denormalization?
Denormalization introduces redundancy to improve read performance.
For example: combining customer and order information into a single table speeds up queries at the cost of some data redundancy.
Q27). What is a database schema?
A database schema defines the structure of a database, including tables, columns, and relationships.
For example: a schema for a university database might include tables for students, courses, and enrollments, with relationships linking students to courses.
Q28). What is a data type?
A data type defines the type of data that can be stored in a column.
For example: a column for storing employee ages would use the integer data type, while a column for storing names would use a varchar (text) data type.
Q29). What is a primary key?
A primary key uniquely identifies each record in a table.
For example: in a table of products, the product ID can be the primary key, ensuring each product has a unique identifier.
Q30). What is a foreign key?
A foreign key is a field in one table that links to the primary key of another table.
For example: in an orders table, the customer ID can be a foreign key that refers to the primary key in the customers table.
Q31). What is a composite key?
A composite key is a combination of two or more columns used to uniquely identify a record.
For example: in a table of course enrollments, the combination of student ID and course ID might be used as a composite key to uniquely identify each enrollment.
Q32). What is a unique key?
A unique key ensures that all values in a column or combination of columns are unique.
For example: an email address column in a users table should have a unique key to prevent duplicate email addresses.
Q33). What is an auto-increment field?
An auto-increment field automatically generates a unique value for each new record.
For example: in an employee table, the employee ID column might be set to auto-increment so that each new employee gets a unique ID without manually entering it.
Q34). What is a check constraint?
A check constraint is used to limit the values that can be inserted into a column.
For example: you might use a check constraint to ensure that the salary column in an employee table only accepts values greater than zero.
Q35). What is a default value?
A default value is an automatic value assigned to a column if no value is provided.
For example: if a new employee record is inserted without specifying a hire date, the default value might be the current date.
Q36). What is a NULL value?
A NULL value represents missing or unknown data.
For example: if a customer has not provided their phone number, the phone number field would contain a NULL value.
Q37). What is a schema?
A schema defines the structure of a database, including tables, columns, and relationships.
For example: the schema for a bookstore might define tables for books, authors, and sales, with specific columns for each.
Q38). What is a temporary table?
A temporary table is a table that exists only during the session in which it was created.
For example: if you're running a complex query and need to store intermediate results temporarily, you might use a temporary table.
Q39). What is a data warehouse?
A data warehouse is a system used for reporting and data analysis, combining data from multiple sources.
For example: a company might use a data warehouse to consolidate sales data from different regions for comprehensive analysis.