Basic & Advanced SQL Interview Questions and Answers
Basic & Advanced SQL Interview Questions and Answers
And Answers:
Congratulations! You got the interview! In this post, we have put
together both basic and advanced SQL Interview Questions and
Answers. This post contains SQL Interview Questions for
Experienced as well as Freshers.
8. 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?
RDBMS stands for Relational Database Management System.
RDBMS is a database management system (DBMS) that is based
on the relational model. Data from relational database can be
accessed using Structured Query Language (SQL)
INNER JOIN
LEFT JOIN
RIGHT JOIN
OUTER JOIN
View Complete Post
26. What is the difference between an inner and outer
join?
An inner join returns rows when there is at least some matching
data between two (or more) tables that are being compared.
An outer join returns rows from both tables that include the
records that are unmatched from one or both the tables.
E.g. ‘Age’ field should contain only the value greater than 18.
CREATE TABLE EMP_DETAILS(EmpID int NOT NULL, NAME VARCHAR (30) NOT NULL, Age INT CHECK (AGE >
1
18), PRIMARY KEY (EmpID));
1. Arithmetic Operators
2. Comparison Operators
3. Logical Operators
Atomicity
Consistency
Isolation
Durability
rows from a table. It can be rolled the rows from the table and free the
rolled back.
We can delete specific rows using We can only delete all the rows at a time
Delete maintains log and performance Truncate maintains minimal log and
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.
2 UNION
2 UNION ALL
1 INSERT into Employee_Details (Employee_Name, Salary, Age) VALUES (‘John’, 5500 , 29);
1 USE TestDB
2 GO
4 GO
2 | TestTable1 |
3 --------------
4| 11 |
5| 12 |
6| 13 |
7| 14 |
8 --------------
1 --------------
2 | TestTable2 |
3 --------------
4| 11 |
5| 12 |
6 --------------
1 SELECT GetDate();
1 | Employee_Name | Salary|
2 -----------------------------
3 | John | 2500 |
4 | Emma | 3500 |
5 | Mark | 5500 |
6 | Anne | 6500 |
7 -----------------------------
Syntax:
Output:
1 | Employee_Name | Salary|
2 -----------------------------
3 | Mark | 5500 |
4 | Anne | 6500 |
5 -----------------------------
1 | Employee_Name | Salary|
2 -----------------------------
3 | John | 2500 |
4 | Emma | 3500 |
5 | Mark | 5500 |
6 | Anne | 6500 |
7 -----------------------------
Syntax:
1 SELECT * FROM Employee_Details WHERE Employee_Name like 'E%';
Output:
1 | Employee_Name | Salary|
2 -----------------------------
3 | Emma | 3500 |
4 -----------------------------
1 sp_rename OldTableName,NewTableName
1 | Gender |
2 ------------
3 | M |
4 | F |
5 | NULL |
6 | m |
7 | f |
8 | g |
9 | H |
10 | i |
11 ------------
1 SELECT Gender,
2 case
7 else upper(Gender)
1 select case when null = null then 'True' else 'False' end as Result;
1 select case when null is null then 'Queries In SQL Server' else 'Queries In MySQL' end as Result;
1 | Name | Gender |
2 ------------------------
3 | John | M |
4 | Emma | F |
5 | Mark | M |
6 | Anne | F |
7 ------------------------
1 UPDATE TestTable SET Gender = CASE Gender WHEN 'F' THEN 'M' ELSE 'F' END
ORACLE:
MySQL:
1 SELECT col1 * (col2 + IFNULL(col3,0)) FROM Table1
SQL Server: