Interview Question-Answers | Tutorial For Beginners


tech4allsa2z:This blog provides you tutorial and most common Interview questions for beginners related to the following technology like java, python.

Top 30 MySQL Interview Questions and Answers for Beginners

MySQL Interview Questions and Answers for Beginners

These beginner-level MySQL Interview questions are commonly asked in school, college, internship, and fresher interviews.

MySQL Interview Questions and Answers for Beginners


1. What is MySQL?

MySQL is an open-source Relational Database Management System (RDBMS) used to store, manage, and retrieve data.

Example:

CREATE DATABASE school;

 

This command creates a database named school.

2. What is a database?

A database is an organized collection of data that can be easily accessed, managed, and updated.

Example:

A school database may contain tables for students, teachers, and classes.

3. What is a table in MySQL?

A table is a collection of related data organized in rows and columns.

Example:

CREATE TABLE students (

    id INT,

    name VARCHAR(50),

    age INT

);

 

4. What is the difference between SQL and MySQL?

  • SQL is a language used to interact with databases.
  • MySQL is software that uses SQL.

Example:

SELECT * FROM students;

 

SQL query used inside MySQL.

5. What are rows and columns?

  • Rows store individual records.
  • Columns store specific information about those records.

Example:

                        id

                    name

                    age

                        1

                    Rahul

                      15

Here, Rahul's full information is one row.

6. What is a primary key?

A primary key is a column that uniquely identifies each row in a table.

Example:

CREATE TABLE employees (

    emp_id INT PRIMARY KEY,

    emp_name VARCHAR(50)

);

 

7. What is a foreign key?

A foreign key is a column used to create a relationship between two tables.

Example:

CREATE TABLE orders (

    order_id INT PRIMARY KEY,

    customer_id INT,

    FOREIGN KEY (customer_id) REFERENCES customers(customer_id)

);

 

8. What is the difference between CHAR and VARCHAR?

  • CHAR stores fixed-length data.
  • VARCHAR stores variable-length data.

Example:

name CHAR(10)

city VARCHAR(50)

 

9. What is the use of SELECT statement?

The SELECT statement is used to retrieve data from a table.

Example:

SELECT * FROM students;

 

10. What is the use of WHERE clause?

The WHERE clause is used to filter records.

Example:

SELECT * FROM students WHERE age > 15;

 

11. What is the difference between DELETE, DROP, and TRUNCATE?

  • DELETE removes selected rows.
  • DROP removes the entire table.
  • TRUNCATE removes all rows but keeps the table.

Example:

DELETE FROM students WHERE id = 1;

TRUNCATE TABLE students;

DROP TABLE students;

 

12. What is NULL in MySQL?

NULL means a column has no value.

Example:

INSERT INTO students (id, name, age) VALUES (1, 'Aman', NULL);

 

13. What is the difference between UNIQUE and PRIMARY KEY?

  • PRIMARY KEY does not allow NULL values and must be unique.
  • UNIQUE allows one NULL value but all other values must be unique.

Example:

email VARCHAR(100) UNIQUE

 

14. What is the use of ORDER BY?

ORDER BY is used to sort data.

Example:

SELECT * FROM students ORDER BY age ASC;

 

15. What is the use of GROUP BY?

GROUP BY is used to group rows with similar values.

Example:

SELECT department, COUNT(*)

FROM employees

GROUP BY department;

 

16. What is the COUNT() function?

COUNT() returns the number of rows.

Example:

SELECT COUNT(*) FROM students;

 

17. What is the use of INSERT statement?

INSERT is used to add new records.

Example:

INSERT INTO students (id, name, age)

VALUES (1, 'Rahul', 16);

 

18. What is the use of UPDATE statement?

UPDATE is used to modify existing records.

Example:

UPDATE students

SET age = 17

WHERE id = 1;

 

19. What is the use of JOIN in MySQL?

JOIN is used to combine data from multiple tables.

Example:

SELECT students.name, courses.course_name

FROM students

JOIN courses ON students.id = courses.student_id;

 

20. What is the difference between INNER JOIN and LEFT JOIN?

  • INNER JOIN returns matching rows from both tables.
  • LEFT JOIN returns all rows from the left table and matching rows from the right table.

Example:

SELECT *

FROM customers

LEFT JOIN orders

ON customers.id = orders.customer_id;

 

21. What is AUTO_INCREMENT?

AUTO_INCREMENT automatically increases the value of a column.

Example:

CREATE TABLE products (

    product_id INT AUTO_INCREMENT PRIMARY KEY,

    product_name VARCHAR(50)

);

 

22. What is a view in MySQL?

A view is a virtual table based on a query.

Example:

CREATE VIEW student_view AS

SELECT name, age FROM students;

 

23. What is normalization?

Normalization is the process of organizing data to reduce duplication.

Example:

Instead of storing customer details multiple times in an orders table, keep them in a separate customer table.

24. What is an index in MySQL?

An index improves the speed of data retrieval.

Example:

CREATE INDEX idx_name

ON students(name);

 

25. What is the difference between HAVING and WHERE?

  • WHERE filters rows before grouping.
  • HAVING filters groups after GROUP BY.

Example:

SELECT department, COUNT(*)

FROM employees

GROUP BY department

HAVING COUNT(*) > 5;

 

26. What is the use of LIMIT?

LIMIT is used to restrict the number of rows returned.

Example:

SELECT * FROM students LIMIT 5;

 

27. What is the difference between MyISAM and InnoDB?

  • MyISAM is faster for read operations.
  • InnoDB supports transactions and foreign keys.

28. What is a transaction in MySQL?

A transaction is a group of SQL statements executed together.

Example:

START TRANSACTION;

UPDATE accounts SET balance = balance - 100 WHERE id = 1;

UPDATE accounts SET balance = balance + 100 WHERE id = 2;

COMMIT;

 

29. What is COMMIT and ROLLBACK?

  • COMMIT saves changes permanently.
  • ROLLBACK cancels changes.

Example:

ROLLBACK;

 

30. Why is MySQL popular?

MySQL is popular because it is:

  • Free and open-source
  • Easy to learn
  • Fast and reliable
  • Supported by many web applications
  • Compatible with PHP, Python, and Java

Quick Tips for MySQL Interviews

  1. Learn basic SQL commands.
  2. Practice SELECT, INSERT, UPDATE, DELETE.
  3. Understand joins and keys.
  4. Remember database terminology.
  5. Practice writing queries by hand.
  6. Be ready to explain examples.

Post a Comment

0 Comments