Top 20 SQL Interview Questions

0
942
Top 20 SQL Interview Questions

Top 20 SQL Interview Questions

In this article we are going to discuss about top 20 SQL Interview Questions.

Q1. Which are the constraints in SQL?

Ans:-  There are 7 constraints in SQL like 

  • Not Null
  • Unique
  • Primary Key
  • Foreign Key
  • Check
  • Default 
  • Index 

Q2. Explain the Foreign key?

Ans:- Every Foreign key is a primary key to the previous table. With the help of a foreign key, we can take reference from the primary table.

For Example:-

Table A

Student_id (Primary Key)Student_nameStudent_phone
101sam123456
102Dark564789
103Mask89632

In Table A, the student_id is a primary key of the table now let’s see the other table.

            Table B

Department_idlocation_idCiyStudent_id(Foreign)
IT1001Pune102
Account1005Nagpur101

In Table B, the student_id is foreign key because it gives the reference of Table A 

With the help of the student_id column.

Q3. Which clause in SQL is used to data sorting?

Ans:- Order By Clause in SQL is used to sort the data in SQL (Hint) Always use Order By clause at the end of the query. Ascending Order is by default in order by, For descending we have to use desc keyword in order by.

Read our latest blog on Beginner’s Guide to SQL

Q4. If I want to convert the data type number to date at that time which function is used in SQL explicit or implicit?

Ans:-when we are converting a number to date datatype at the situation we have to explicit data type conversion in SQL.

Q5. Explain the flow of explicit data type conversion Number to Character?

Ans:- There are many situations when we used explicit data type conversion.

When number data type to the character datatype

Here original data type is number which converting to the character data type we have to use To_Char function with the help of To_Char function we can convert the data into character.

Q6. Explain the flow of explicit data type conversion Character to Number?

Ans:- There are many situations when we used explicit data type conversion. When Character data type to the Number datatype. Here original data type is Character which converting to the Number data type we have to use To_Num function with the help of To_Num function we can convert the data into character

Q7. Difference Between Where Clause and Having Clause?

Ans:- Where Clause is used with single row function whereas having clause is used with group function both are used to apply condition parameters on the data.

Q8. Types of joins in SQL?

Ans:- These are the types of join in SQL?

  • Natural Join
  • Inner Join 
  • Self-join
  • Left Outer Join
  • Right Outer Join
  • Full Outer Join
  • Cross Join

Q9. What is the use of cross join in SQL?

Ans:- Cross join will give you the cartesian product of the two tables.

Q10. Difference between CHAR and VARCHAR2?

Ans:-Both Char and Varchar2 are used for character datatype but varchar2 is used for String and variable length and  Char is used for strings of fixed length. 

For example, char(5) can only store 5 characters and will not be able to store a string of any other length whereas varchar2(5) can store any length i.e 4,3,2 in this variable.

Q11. Retrieve the 2nd highest salary?

Ans:- Select max(salary)

          From employees

          Group by salary where salary >select max(salary) from employees;

Q12. Difference between the left outer join and right outer join?

Ans:- Left Outer Join is used to retrieve common data from both the table and all the data from the left-hand side table whereas the right outer join can give all the data from the right side table and only common data from the left table.

Q13. Which command is used to check all the information on the table?

Ans:- Describe Command is used to retrieve information on the table.

Q14. What is the use of view in SQL?

Ans:- View is used as a virtual table in SQL  if you don’t want to show whole information to the user at the situation you can create the view of some particular data.

Q15. To complete the transaction in SQL which command is used?

Ans:- Commit keyword is used to complete the transaction in SQL.

Q16. Which commands are used in the transaction control language?

Ans:-  There are three commands of TCL in SQL.

  • Commit
  • Savepoint
  • Rollback

Q17. Which command is used to provide and take access in SQL?

Ans:- There is Grant is used to providing permission to access the data. And revoke is used to take access from the user.

Q18. What is an Index?

Ans:- An index refers to a performance tuning method of allowing faster retrieval of records from the table. An index creates an entry for each value and hence it will be faster to retrieve data.

Q19. When we used a subquery in SQL which query run first?

Ans:- Inner Query runs first to solve the query of the outer side.

Q20. How to insert the data in the predefined table?

Ans:- Using Insert Into Command we can insert the data into the table.

Syntax:- Insert Into table_name ()

These are the top 20 most important SQL Interview Questions for you next interview, All the Best!

PlayPlay

LEAVE A REPLY

Please enter your comment!
Please enter your name here