interview-Questions-SQL.txt
interview-Questions-SQL.txt
Top 50 MySQL interview questions with answers that cover everything from the basics
of MySQL such as CRUD operations, features, and various mysql functions to advanced
MySQL Topics such as MySQL Constraints (i.e. primary keys, foreign keys, and check
constraints, etc.), MySQL Joins, Indexes, MySQL Security Performance Tuning and
more.
MySQL
SQL can be implemented in various RDBMS such as PostgreSQL, SQLite, Microsoft SQL
Server, and others.
MySQL is a specific implementation of an RDBMS that uses SQL for querying and
managing databases.
SQL itself is not a product and doesn’t have a license. It’s a standard language.
MySQL is open-source and available under 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.
Column length is fixed in CHAR but VARCHAR length is variable.
CHAR is faster than VARCHAR.
CHAR datatype can hold a maximum of 255 characters while VARCHAR can store up to
4000 characters.
9. What is Difference between CHAR_LENGTH and LENGTH?
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:
SET
BOLB
TEXT
ENUM
CHAR
VARCHAR
13. Explain the main difference between FLOAT and DOUBLE?
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.
14. Explain the differences between BOLB and TEXT.
BOLB:
A BOLB is a large object in binary form that can hold a variable amount of data.
Sorting and comparing in BLOB values are case-sensitive.
TINYBOLB
BOLB
MEDIUMBOLB
LONGBOLB
TEXT:
Sorting and comparison are performed in case-insensitive for TEXT values. we can
also say a TEXT is case-insensitive BOLB.
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.
16. Explain REGEXP.
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.
Syntax:
Syntax:
SELECT NOW();
SELECT CURRENT_DATE();
Syntax:
FROM table_name;
Locking Level
Indexing
Storage mechanism
Capabilities and functions
25. How to create a table in MySQL?
The CREAT TABLE command will be used to create a table in MySQL.
Syntax:
Syntax:
FROM Product
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:
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:
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
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.
Syntax:
SET max_heap_table_size = M
Syntax:
SELECT columns
FROM tables
[WHERE conditions];
41. Where MyISAM table will be stored and also give MyISAM formats of storage?
Every MyISAM table is stored on 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.
In case of corruption MyISAM static table is easy to store.
Advanced MySQL Interview Questions
45. What are Access Control Lists?
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.
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.
SELECT
FROM
Vehicle
For detail you can check our latest article on Regular expressions (Regexp).