Q1: Whats the differences between DBMS and RDBMS?
->> DBMS Database Management System is the basic way to store data in files. Data stored individually
with no connections between them. RDBMS Relational Database Management system has some sort of
relation between the data. Its easy to create relations between Different pieces of data. Allows faster
data retrieval specially hen working with large datasets. High Security
Q2: What is primary key and foreign Key?
->> Primary Key is to uniquely identify row. Cant be null or duplicate. Foreign Key to link between two
tables. Helps you connect data across tables, ensuring that records in one table can reference related
information to another.
Q3: Constraints and their types?
->> NOT NULL, UNIQUE, PRIMARY KEY, FOREIGN KEY, CHECK, DEFAULT
Q4: Explain DDL and DML command in SQL.
->> DDL Data Definition Language Define the structure of the Database. CREATE/ALTER/DROP
DML Data Manipulation Language works with actual data to make changes. INSERT/UPDATE/DELETE
Q5: Difference between DELETE, DROP and TRUNCATE statemet?
->> DELETE: Delete a specific row data from a datatable based on condition. Can be rolled back.
TRUNCATE: Delete all the rows data from a datatable and empty the table, keeping the structure of
table intact. Cant be rolled back.
DROP: Delete the Table along with all the data inside. Cant be undone.
Q6: Differentiate between GROUP BY and ORDER BY clause?
->>ORDER BY is sorting rows in a particular order. Sorting entire table based on one or more columns.
GROUP BY is grouping your data into meaningful summaries(SUM, AVG, COUNT).
Q7: Differences between WHERE and HAVING clause?
->>WHERE Filter individual rows based on specific conditions like age or name. HAVING is like filtering
after grouping. You use Having when you want to filter groups created by the GROUP BY clause based
on aggregate results like COUNT or SUM.
Q8: Aggregate functions in SQL?
->>COUNT(), SUM(), AVG(), MIN(), MAX()
Q9: Explain Indexing in SQL and what do you mean by Clustered Index?
->> Indexing is organizing the data row in a specific manner of data structure technique used to improve
the speed of data retrieval operations on a database table. Used in faster SELECT queries and JOIN,
WHERE, ORDER BY, GROUP BY operations.
Clustered Index defines the physical order of data in a table. The rows are stored in the sorted order.
Sort and store data rows in table based on the index key.
Q10: What is normalization and explain different type of normal form?
->>Normalization in DB is a process of organizing data efficiently, minimizing redundancy(Duplicate
information) and preventing issues when inserting, deleting, and updating records.
1NF: Eliminates duplicate columns and ensures atomicity.
2NF: Ensures all non-key attributes depend on the primary key.
3NF: Removes transitive dependencies.
BCNF: Ensures no partial dependency on candidate keys.
Q11: Union and Union All Operator?
->>UNION Combines two lists. Removes the duplicate in the combined list.
UNION ALL Combines two lists but keep every record even if they show up more than once.
Q12: Find the SECOND Highest Salary in the table?
->> SELECT * FROM Employee ORDER BY salary DESC LIMIT 1 OFFSET 1;
->> SELECT MAX(salary) FROM Employee WHERE salary <(SELECT MAX(salary) FROM Employee)
Q13: What are views in SQL?
->>VIEW in table is like virtual data that doesn’t store in disc but show you data from one or more table
in a specific way.
CREATE VIEW detailview AS SELECT studentdetail FROM studentdetails WHERE sid <5;
Select * from detailview?
Q14: Convert Text into date format. Consider text as “20-11-2024”?
->>SELECT STr_TO_DATE(’20-11-2024’, ‘%d-%m-%y’)
Q15: What are triggers in SQL?
->>
Q16: What is SQL?
->> SQL (Structured Query Language) is a standard language for managing and manipulating databases.
It is used to perform operations such as querying, inserting, updating, and deleting data.
Q17: What are the types of SQL Command?
->> SQL commands are categorized into five types:
DDL (Data Definition Language): CREATE, ALTER, DROP, TRUNCATE
DML (Data Manipulation Language): SELECT, INSERT, UPDATE, DELETE
DCL (Data Control Language): GRANT, REVOKE
TCL (Transaction Control Language): COMMIT, ROLLBACK, SAVEPOINT
DQL (Data Query Language): SELECT
Q18: Difference between SQL and MySQL?
->>SQL is a query language used to communicate with databases.
MySQL is a relational database management system (RDBMS) that uses SQL as its query language.
Q19: Diffenet types of Join?
->>INNER JOIN: Returns records with matching values in both tables.
LEFT JOIN: Returns all records from the left table and matched records from the right table.
RIGHT JOIN: Returns all records from the right table and matched records from the left table.
FULL JOIN: Returns all records from both tables.
CROSS JOIN: Returns the Cartesian product of both tables.
SELF JOIN: Joins a table with itself.
Q20: What is a stored procedure?
->> A stored procedure is a precompiled collection of SQL statements stored in the database that can be
executed as a single unit.
Q21: What are the windows functions in SQL?
->> Window functions perform calculations across a set of table rows related to the current row.
Common functions include:
RANK(): Assigns a unique rank to rows.
DENSE_RANK(): Similar to RANK() but without gaps.
ROW_NUMBER(): Assigns a sequential row number.
LEAD() & LAG(): Access data from previous or next rows.
Q22: What are the ACID compliances?
->> ACID (Atomicity, Consistency, Isolation, Durability) ensures reliable transactions in databases:
Atomicity: Ensures complete execution of transactions.
Consistency: Maintains database integrity.
Isolation: Ensures transactions do not interfere with each other.
Durability: Ensures committed transactions are permanent.
Q23: What are CTEs (Common Table Expressions)?
->> A CTE is a temporary result set used within a SQL query. It simplifies complex queries and improves
readability.
WITH EmployeeCTE AS (
SELECT EmployeeID, Name, Salary FROM Employees WHERE Salary > 50000
SELECT * FROM EmployeeCTE;
Q24: Retrieve duplicate records from a table?
->> SELECT Name, COUNT(*) FROM Employees
GROUP BY Name HAVING COUNT(*) > 1;
Q25: Find the nth highest salary using LIMIT?
->> SELECT Salary FROM Employees
ORDER BY Salary DESC LIMIT 1 OFFSET (N-1);
Q26: How to create empty tables with the same structure as another
table?
->> SELECT * INTO Students_copy
FROM Students WHERE 1 = 2;
Q27: Difference between OLTP and OLAP?
->>OLTP stands for Online Transaction Processing, is a class of software applications capable of
supporting transaction-oriented programs. An important attribute of an OLTP system is its ability to
maintain concurrency. OLTP systems often follow a decentralized architecture to avoid single points of
failure. These systems are generally designed for a large audience of end-users who conduct short
transactions. Queries involved in such databases are generally simple, need fast response times, and
return relatively few records. A number of transactions per second acts as an effective measure for such
systems.
OLAP stands for Online Analytical Processing, a class of software programs that are characterized by the
relatively low frequency of online transactions. Queries are often too complex and involve a bunch of
aggregations. For OLAP systems, the effectiveness measure relies highly on response time. Such systems
are widely used for data mining or maintaining aggregated, historical data, usually in multi-dimensional
schemas.
Q28: what is Query?
->>A query is a request for data or information from a database table or combination of tables. A
database query can be either a select query or an action query.
Q29: Difference between Clustered and Non-clustered index?
->>The differences can be broken down into three small factors -
Clustered index modifies the way records are stored in a database based on the indexed column. A non-
clustered index creates a separate entity within the table which references the original table.
Clustered index is used for easy and speedy retrieval of data from the database, whereas, fetching
records from the non-clustered index is relatively slower.
In SQL, a table can have a single clustered index whereas it can have multiple non-clustered indexes.
Q30: What is an Index?
->>
Q31: What is CURSOR? How to use a CURSOR?
->>
Q31: What is an Alias in SQL?
->>
Q32: What is VIEW?
->>
Q33: Normalization and Denormalization?
->>
Normalization represents the way of organizing structured data in the database efficiently. It includes
the creation of tables, establishing relationships between them, and defining rules for those
relationships. Inconsistency and redundancy can be kept in check based on these rules, hence, adding
flexibility to the database.
Denormalization is the inverse process of normalization, where the normalized schema is converted into
a schema that has redundant information. The performance is improved by using redundancy and
keeping the redundant data consistent. The reason for performing denormalization is the overheads
produced in the query processor by an over-normalized structure.
Q34: What are Aggregate and Scalar Functions?
->>