SQL - Interview Questions 1 - Mangesh Sir
SQL - Interview Questions 1 - Mangesh Sir
1. What is a Database?
A database is a collection of information in an organized form for faster and better access,
storage, and manipulation. It can also be defined as a collection of tables, schema, views, and
other database objects.
7. What is DBMS?
Database Management System is a collection of programs that enables a user to store, retrieve,
update and delete information from a database.
9. What is RDBMS?
Prepared By- Mangesh Sir
VCTC Katraj, Pune
RDBMS stands for Relational Database Management System. RDBMS is a database
management system (DBMS) that is based on the relational model. Data from a relational
database can be accessed using Structured Query Language (SQL)
10. What are the popular Database Management Systems in the IT Industry?
Oracle, MySQL, Microsoft SQL Server, PostgreSQL, Sybase, MongoDB, DB2, and Microsoft
Access etc.
1. Correlated: In a SQL database query, a correlated subquery is a subquery that uses values
from the outer query in order to complete. Because a correlated subquery requires the outer
query to be executed first, the correlated subquery must run once for every row in the outer
query. It is also known as a synchronized subquery.
INNER JOIN
LEFT JOIN
RIGHT JOIN
OUTER JOIN
Outer Join: An outer join returns rows from both tables that include the records that are
unmatched from one or both the tables.
35. What is the difference between UNIQUE and PRIMARY KEY constraints?
There should be only one PRIMARY KEY in a table whereas there can be any number
of UNIQUE Keys.
PRIMARY KEY doesn’t allow NULL values whereas Unique key allows NULL values.
37. What is the difference between NULL value, Zero, and Blank space?
As I mentioned earlier, Null value is field with no value which is different from zero value and
blank space.
Null value is a field with no value.
Zero is a number
Blank space is the value we provide. The ASCII value of space is CHAR(32).
E.g. ‘Age’ field should contain only the value greater than 18.
1. Arithmetic Operators
2. Comparison Operators
3. Logical Operators
45. What is the difference between Delete, Truncate and Drop command?
The difference between the Delete, Truncate and Drop command is
Delete command is a DML command, it is used to delete rows from a table. It can be
rolled back.
Truncate is a DDL command, it is used to delete all the rows from the table and free the
space containing the table. It can’t be rolled back.
Drop is a DDL command, it removes the complete data along with the table structure
(unlike truncate command that removes only the rows). All the tables’ rows, indexes, and
privileges will also be removed.
DELETE TRUNCATE
DELETE TRUNCATE
Delete maintains log and performance is Truncate maintains minimal log and
slower than Truncate performance wise faster
47. What is the difference between Union and Union All command?
This is one of the tricky SQL Interview Questions. Interviewer may ask you this question in
another way as what are the advantages of Union All over Union.
Both Union and Union All concatenate the result of two tables but the way these two queries
handle duplicates are different.
Union: It omits duplicate records and returns only distinct result set of two or more select
statements.
Union All: It returns all the rows including duplicates in the result set of different select
statements.
Performance wise Union All is faster than Union, Since Union All doesn’t remove duplicates.
Union query checks the duplicate values which consumes some time to remove the duplicate
records.
54. How to add new Employee details in an Employee_Details table with the following
details
Employee_Name: John, Salary: 5500, Age: 29?
Prepared By- Mangesh Sir
VCTC Katraj, Pune
INSERT INTO Employee_Details (Employee_Name, Salary, Age)
VALUES(‘John’,5500,29);
56. How to change a value of the field ‘Salary’ as 7500 for an Employee_Name ‘John’ in a
table Employee_Details?
UPDATE Employee Details
SET Salary=7500
WHERE Empolyee_Name =’John’;
57. Write an SQL Query to select all records from the table?
SELECT * FROM tablename;
59. Write the command to remove all Players named Sachin from the Players table.
DELETE FROM Players WHERE Players_Name = ‘Sachine’;
60. How to get each name only once from an employee table?
By using the DISTINCT keyword, we could get each name only once.
Syntax
SELECT DISTINCT column name FROM table name;
Syntax
WHERE Salary>=5000;
65. Write an SQL Query to find list of Employee_Name start with ‘E’ from the below table
SELECT * FROM Empolyee_Details
WHERE Empolyee_Name LIKE ‘E%’;
66. Write SQL SELECT query that returns the FirstName and LastName from
Employee_Details table.
SELECT FirstName, LastName FROM Empolyee_Details;
68. How to select all the even number records from a table?
To select all the even number records from a table:
71. What is the difference between GUI Testing and Database Testing?