SQL interview questions
1. Define SQL.
SQL stands for Structured Query Language. As the name indicates it’s used to query structured data which is stored in the database. It allows users to access and manipulate data in databases.
2. Define Database.
The database is defined as the storage unit in which the set of data is stored (or) The database is defined as collection of structured data in a system. There are four types of databases
-> Relational Database Systems
-> Hierarchical Database Systems
-> Network Database Systems
-> Object-Oriented Database Systems
3. Types of commands in DBMS
SQL commands are defined as set of instructions which are used to interact with the database. There are four types of commands in SQL based on how we manipulate database. They are
DDL – These commands are responsible for defining the structure of table like CREATE, ALTER, DROP and TRUNCATE
DML – These commands are used to manipulate the database like INSERT, UPDATE and DELETE.
DCL – These commands are used to grant permissions to user
TCL – These commands are used to control the Transactions in a database include ROLLBACK, COMMIT, SAVEPOINT.
4. Difference between ALTER and UPDATE command
ALTER command is used to modify the attributes(columns) in the table where as UPDATE command is used to update the records(rows)in the table.
5. Difference between HAVING and WHERE clause
WHERE is used to put a condition on individual row of a table whereas HAVING is used to put condition on individual group formed by GROUP BY Clause in SELECT Statement.
6. Difference between DELETE and DROP command
DELETE command is used to delete the records present in a table from the database but the schema and constraints of that table are still present in that database. When it comes to DROP command, the entire table is going to delete from the database including its constraints, schema and records.
7. Define Schema
Schema is defined as the structure or design of the database. There are two types of schemas in DBMS they are Physical Schema, Logical Schema.
8. Explain the concept of Normalization.
The Normalization is a database design technique that cuts down data redundancy which helps us to remove three anomalies(Insertion, Deletion and Updation Anomaly). Oter purpose of normalizing database is to the make sure that the data dependencies make sense and are logically stored.
9. What are Joins and their types in SQL?
The joins are used when one want to pair up two tuples from two different tables when a specifies condition is met. Mainly there are three types of joins in SQL
-> Natural Join
-> Outer Join
-> Equi Join
10. Explain Constraints in SQL.
Constraints are the set of rules that are imposed on the table during data insertion. These can be applied either on column level or table level. There are five constraints in SQL
UNIQUE – Ensures only unique values are inserted into column
CHECK- Used to check whether column met a condition or not.
NOT NULL – This is to ensure the data must be present in the column instead of accepting NULL values.
PRIMARY KEY – Used to uniquely identify each row in table.(Combination of NOT NULL and UNIQUE)
FOREIGN KEY – When we want to relate two or more tables based on common column among them then this constraint is used.
11. What is meant by Transaction in SQL? Explain ACID properties.
In SQL Transaction is defined as the sequence of operations that are performed on the database. The ACID properties are used to maintain consistency in the database.
Atomicity(A) – Ensures the transaction happens in a sequential manner not all at a time.
Consistency (C) – The database must same before and after the transaction.
Isolation(I) – More than once transaction occur independently without colliding with each other.
Durability(D) – Once transaction has completed the modifications of the database are stored permanently even if the system fails.
12. What are Triggers in SQL?
A SQL trigger is special stored procedure that is run when specific actions occur within a database. Most database triggers are defined to run when changes are made to a table’s data. Triggers can be defined to run instead of or after DML (Data Manipulation Language) actions such as INSERT, UPDATE, and DELETE.
13. Difference between SQL and NOSQL?
The basic difference between them is when one want to extract structured data from database then SQL comes into picture but when one want to work with unstructured data then NOSQL comes into picture. The SQL databases have static amount of storage to store data whereas NOSQL databases are dynamic.SQL examples include MySQL, Oracle and NOSQL Examples includes MongoDB, Couch DB,GraphQL & Cassandra.
14. ETL in SQL?
ETL stands for Extract Transfer and Load. ETL is defined as the three-stage process where data is extracted, transformed (cleaned) and loaded into output data container.
15. Are NULL values are same as that of zero/ blank space?
The answer is NO. Null is value in Database which is used to store no value in the database at a specific field. When it comes to zero and blank space these are considered as values as they are ASCII valued characters.