0% found this document useful (0 votes)
2 views

mysql_interview_questions_with_theory_answers

The document contains a comprehensive set of MySQL interview questions and answers, focusing on key concepts such as primary keys, foreign keys, and various SQL operations. It includes coding questions related to creating, updating, deleting, and querying tables, as well as explanations of SQL joins and normalization. Additionally, it provides links to reference tables for practice during mock interviews.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

mysql_interview_questions_with_theory_answers

The document contains a comprehensive set of MySQL interview questions and answers, focusing on key concepts such as primary keys, foreign keys, and various SQL operations. It includes coding questions related to creating, updating, deleting, and querying tables, as well as explanations of SQL joins and normalization. Additionally, it provides links to reference tables for practice during mock interviews.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

MySQL Interview Questions &

Answers

Palle Technologies
Updated on 22-oct-2022
all queries are based on below tables
table 1 - department table
unique key
dept_id (PK) dept_name (UK) dept_location
primary key
1 HR BTM

2 Development HSR

3 Training HSR

4 Sales Bommanahalli

5 Marketing Bommanahalli

6 MD HSR

7 Recruitment HSR

2
All queries are based on below tables
Primary key table 2 - employee table foreign key
emp_id emp_name city emp_salary manag d_id
(PK) er_id (FK)

1 Ramesh mumbai 22000 10 1

2 Suresh bangalore 25000 11 2

3 Mahesh chennai 21000 8 3

4 Lokesh chennai 35000 5 4

5 Veena delhi 32000 9 4

6 Sravanthi bangalore 18000 11 2

7 Divya mysore 15000 9 5

8 Jona chennai 30000 9 3

9 Steve chennai 40000 Null 6

10 Nithesh delhi 35000 9 1

11 Mohan kolkata 36000 9 2

-- --- --- --- --- ----


3
coding or query based questions
• dear students mock interviewers can ask any
questions based on the concepts being
covered as part of the course while taking
mock
• we request all students to prepare the all
concepts related queries or code properly
• most frequently asked queries or concepts are
listed in the next slide. please refer and prepare
accordingly.

4
• sql query for creating department table with
appropriate data types and primary key and
unique constraints
• sql query for creating employee table with
appropriate data types and primary key and
foreign key constraints

5
• question based on update query on the
employee table
• question based on delete query on the
employee table
• question based on insert query on the
employee table
• questions based on select statement with
where clause on employee table
• questions based on select statement with like
clause on employee table
• questions based on group by clause on
employee table
• questions based on having clause on
employee table
• questions based on inner joins on employee
and department table
• questions based on left outer joins on
department and employee table
• questions based on self join on employee
table
• questions based on sub queries
• questions based on co-related sub queries
and nth highest nth lowest values
1. what is primary key?
▪ primary key gives uniqueness to the tables rows
▪ only one primary key is allowed per table
▪ primary key will not allow null values and duplicate values
2. What is the difference between primary key and
unique key?
primary key unique key

only one primary key is allowed any number of unique keys are
per table. allowed per table

primary key will not allow unique constraint will not allow
duplicates values duplicate values

primary key will not allow null unique constraint will allow any
values number of null values

8
3. what is foreign key?
• using foreign key constraint we can link 2 or
more tables.
• using foreign key we can achieve referential
integrity

Syntax
Create table table_name
(
Col1 datatype ,
Col2 datatype,
foreign key(col1) references table_name(column_name)
)

9
5. what is the diff b/w char and varchar?
char is a fixed size data type & varchar is varying size data
type. wastage of memory will be more in char type.
6. what is normalization? and what are the
benefits?
normalization is used for eliminating the data
redundancy. normalization will eliminate the insert,
update anomalies.
7. is it possible to store null in a foreign key column?
Yes.

10
8. Is null allowed in primary key column?
no.
9. how many primary keys we can give for a
table?
only one.
10. how many unique keys allowed for a table?
any number.

11. How many foreign keys allowed per table?


we can create any number of foreign keys
per table.
12. what is the diff between drop and
delete?
drop delete
drop table will delete the a delete statement will
table (along with data and delete only data, but table
structure ) will be retained.
drop is a DDL statement delete is a DML statement
Drop is not a logged Delete is a logged
operation and hence not operation and hence it is
reversible reversible
eg: drop table employee; eg: delete from employee
where emp_id = 1;

12
13. what is the diff between delete
and truncate?
delete truncate
1. a delete statement will delete 1. a truncate statement will delete
only data, but table will be only data, but table will be
retained. retained. (just like delete)

2. delete is a DML statement 2. truncate is a DDL statement

3. we can give where clause in 3. we can’t give where clauses in


delete. Delete operation is slower. truncate. Truncate is faster that
delete.
4. we can roll back the delete 4. We can’t roll back the truncate
operation operation.

13
14. what is the purpose of joins in sql?
• joins are useful for getting data from 2 or more tables
into a result set.

15. what are the different types of joins supported in sql


server?
1.inner join
2.outer join
1)Left Outer Join
2)Right Outer Join

3.Self Join
4.Cross Join

14
16. what is inner join?
Inner join is used for getting matched data from
2 or more tables based on the condition.

17. what is LOJ?


In left outer join data from left table is
completely included into the result-set but only
matched data from right side table is included. In
place of right table data null’s are included
where there is no match.

9
18. What is ROJ?
In right outer join data from right table is completely
included into the result-set but only matched data
from left side table is included. In place of left table
data null’s are included where there is no match.

19. What is self join?


1.Joining a table to itself is called as self join.
2.we must use inner join keyword for self join.

16
20. what is cross join?
cross join will join each row present in a table
with all rows present in other table. in simple
words it will produce Cartesian product of all
rows present in both the tables.

21. what is the purpose of having clause?


using having clause we can filter the records
which are produced by group by clause.

17
22. what is the purpose of order by clause?
Ans : order by clause specifies that a SQL SELECT
statement returns rows with sorted order, by
the values of given column.

23. what is the purpose of group by clause?


Ans : using group by clause we can group data
based on one or more column.

18
28. write query for finding employee details
with first highest salary?
Ans : student should write query
29. write query for finding employee details
with second highest salary?
Ans : student should write query

19
Link for tables
• Student can use the following referenced
tables ( usually mock interviews we ask
questions based on the given tables )
• https://palle-sql-tables.s3.ap-south-
1.amazonaws.com/index.html

20

You might also like