MySQL Interview Questions And Answers for Freshers
MySQL Interview Questions And Answers for Freshers
1. What is MySQL and How does it differ from other relational databases?
MySQL is an open-source relational database management system (RDBMS) that is widely used
for managing structured data. It utilizes SQL (Structured Query Language)
for querying and managing data. MySQL is known for its reliability, scalability, and performance,
making it a popular choice for various applications
To create a database in MySQL, we can use the CREATE DATABASE statement followed by the name
we want to give to our database. For example:
• CHAR: Fixed-length character data type where the storage size is predefined. Trailing spaces
are padded to reach the defined length.
• VARCHAR: Variable-length character data type where the storage size depends on the actual
data length. No padding of spaces is done.
SQL MySQL
SQL itself is not a product and doesn’t have a MySQL is open-source and available under
license. It’s a standard language. the GNU General Public License (GPL).
mysql <batch-file>;
• Heap table
• merge table
• MyISAM table
• INNO DB table
• ISAM table
8. What are the differences between CHAR and VARCHAR data types in MySQL?
• Storage and retrieval have been different for CHAR and VARCHAR.
• CHAR datatype can hold a maximum of 255 characters while VARCHAR can store up to 4000
characters.
LENGTH is byte count whereas CHAR_LENGTH is character count. The numbers are the same for Latin
characters but different for Unicode and other encodings.
Syntax of CHAR_LENGTH:
Syntax of LENGTH:
‘_’ corresponds to only one character but ‘%’ corresponds to zero or more characters in
the LIKE statement.
• SET
• BLOB
• TEXT
• ENUM
• CHAR
• VARCHAR
• FLOAT stored floating point number with 8 place accuracy. The size of FLOAT is 4 bytes.
• DOUBLE also stored floating point numbers with 18 place accuracy. The size of DOUBLE is 8
bytes.
BLOB:
A BLOB is a large object in binary form that can hold a variable amount of data. Sorting and
comparing in BLOB values are case-sensitive.
• TINYBLOB
• BLOB
• MEDIUMBLOB
• LONGBLOB
TEXT:
Sorting and comparison are performed in case-insensitive for TEXT values. we can also say a TEXT is
case-insensitive BLOB.
• TINYTEXT
• TEXT
• MEDIUMTEXT
• LONGTEXT
15. Explain the difference between having and where clause in MySQL.
• WHERE statement is used to filter rows but HAVING statement is used to filter groups.
• GROUP BY is not used with WHERE. HAVING clause is used with GROUP BY.
REGEXP is a pattern match where the pattern is matched anywhere in the search value.
For more detail you refer to our MySQL | Regular expressions Article.
17. How can we add a column in MySQL?
A column is a series of table cells that store a value for table’s each row. we can add column by
using ALTER TABLE statement.
Syntax:
We can delete a table by using DROP TABLE statement. This statement deletes complete data of
table.
20. How are mysql_fetch_array() and mysql_fetch_object() different from each another?
mysql_fetch_array() Gets a result row as a related array or a regular array from database.
mysql_fetch_object gets a result row as an object from the database.
current year, month, and date with hours, minutes, and seconds is shown by using NOW() command
while CURRENT_DATE shows current year current month, and current date.
Syntax:
SELECT NOW();
SELECT CURRENT_DATE();
the DISTINCT keyword allows for the removal of all duplicate records and the retrieval of unique
records. The DISTINCT keyword is used with the SELECT statement.
Syntax:
FROM table_name;
Storage engines are also called table types. Data is stored in a file using multiple techniques.
Below are some techniques.
• Locking Level
• Indexing
• Storage mechanism
Syntax:
Syntax:
FROM Product
One-to-one: Elements with a one to one relationship can be included as columns in the table.
One-to-many: One to many or many to one relationships both are same. It will occur when one row
in a table is related to multiple rows in different table.
Many-to-many: Many rows in a table are related to many rows in different table is called many to
many relationship.
• DATE
• DATETIME
• TIMESTAMP
• YEAR
Syntax:
INSERT INTO table_name (column_name, column_date) VALUES (‘DATE: Manual Date’, ‘2023-5-
20’);
Joins are used to connect two or more tables. It returns only same values in all tables.
• Inner Join
• left Join
• Right Join
• Full Join
31. What is a primary key? How to drop the primary key in MySQL?
A primary key in MySQL is a single field or a group of fields that are used to uniquely identify each
record in a table. A primary key cannot be null or empty. ALTER TABLE statement is used to delete a
primary key from a table.
Syntax:
A heap table is usually used for temporary and fast temporary storage.
33. What is the main difference between the primary key and the candidate key?
The primary key uniquely identified each row of a table. only one primary key is available for a table.
• Candidate key that can be used for all foreign key references.
For mor detail you can see: Difference between Primary and Candidate Key
34. What is the difference between DELETE and TRUNCATE commands in MySQL?
DELETE Command is used to delete rows from the table depending on given the
condition. TRUNCATE command is used to DELETE all rows from the table. DELETE command is a
Data Manipulation Language command. TRUNCATE command is a Data Definition Language
command.
For More detail you can see : Difference between DELETE and TRUNCATE
A SQL storage database is called InnoDB database. The InnoDB offers ACID transactions, row-level
locking, and foreign key support. InnoDB is owned by Oracle Corporation.
36. What is the difference between UNION and UNION ALL in MySQL?
During combining the results of more than one SELECT statement, the UNION operator deletes
duplicate rows between the various SELECT statements. The UNION ALL also combines the result set
of more than one SELECT statement, but it does not delete duplicate rows.
In MySQL, When a row is added to or updated in a table, a data type “timestamp” automatically
records the time.
ENUM is a string object that can be used when creating tables to specify a set of predefined values.
MySQL config variable max_heap_table_size can be used to control the max size of heap.
Syntax:
SET max_heap_table_size = M
A database object that has no value is called view. Rows and columns exist in a view. A view is virtual
table. it is created by combining one or more tables. The difference of a view and a table is that views
are definition that build on other tables. If the underlying table changes, the View will also reflect
those same changes.
Syntax:
SELECT columns
FROM tables
[WHERE conditions];
41. Where MyISAM table will be stored and also give MyISAM formats of storage?
In MySQL, Blobs can be used to store images. All database images are first converted into blobs then
saved and then they will be added to the database, and finally, it will later be stored on the disk.
43. What are trigger and how many TRIGGERS are available in MySQL table?
A trigger is a procedural code in a database. Triggers are automatically triggered when specific events
occur on a particular table. During column updating triggers are invoked automatically.
• BEFORE INSERT
• AFTER INSERT
• BEFORE UPDATE
• AFTER UPDATE
• BEFORE DELETE
• AFTER DELETE
For more detail you can see: Different types of MySQL Triggers (with examples) – GeeksforGeeks
44. What are the different characteristics of MySQL MyISAM Static and MyISAM Dynamic?
• Width of all fields is fixed in MyISAM Static table whereas width of all fields is not fixed in
MyISAM Dynamic. In MyISAM Dynamic table width will be like TEXT, BOLD, etc.
A list of permissions known as an Access Control List is connected to an object. It is MySQL server
security model helps in troubleshooting issues like users being unable to connect. MySQL holds the
ACL’s cached in memory. ACL’s also called grant tables. MySQL verifies the authentication data and
permissions against the ACLs. It predetermined order whenever a user tries to log in or execute a
command.
46. What is Normalization and list the different types of normalization?
Normalization is used to avoid duplication and redundancy. it is a process of organizing data. There
are many normal forms of normalization. which are also called successive levels. The first three
regular forms are sufficient.
• First Normal Form (1NF): There are no repeating groups within rows.
• Second Normal form(2NF): Value of every supporting column depending on the whole
primary key.
• Third Normal Form(3NF): It depends only on the primary key and no other value of non-key
column.
• The SQL Server Management Studio is available for use. we can use this to browse to the
table where the index will be created, and then right-click on the Indexes node. We must
select the New Index option over here.
• We can identify the index indirectly by specifying the PRIMARY KEY and
the UNIQUE constraint in the CREATE TABLE or ALTER TABLE statement.
Cluster Index: An index type used to arrange data in a table is called a clustered index. The table’s
data are stored in a specific order based on the clustered index.
Non Cluster Index: A non-clustered index is also a type of index used to organize data in a table. The
table’s data are not stored in a specific order based on the non clustered index.
For more details, Check our latest article on Difference between Clustered and Non-clustered index.
We can use the regular expressions function (REGEXP_LIKE) to validate emails. Below is the example
of validate emails using a single query.
SELECT
FROM
Vehicle
For detail you can check our latest article on Regular expressions (Regexp).
• Or you can turn off secure-file-priv. This must be removed at the beginning and cannot be
disabled later.
Conclusion
In conclusion, preparing well for MySQL interview questions is crucial for data analysts, data
engineers, and business analysts. This guide provides important MySQL questions and answers to
help you get ready for your interviews.
By studying these, you can show that you are skilled and ready for roles that require strong MySQL
knowledge. This preparation will help you stand out in your field.