1. What is MySQL? In which language MySQL is written?
MySQL is an Oracle-backed open source RDBMS, based on Structured Query Language (SQL). It is often accessed using PHP to create powerful and dynamic server-side applications. It is pretty easy to master in compare to Oracle Database, or Microsoft SQL Server.
MySQL is written in C, C++.
2. Why should we use MySQL?Top Reasons to Use MySQL:
- The MySQL database server is very fast, reliable and easy to use.
- It is open source and thus is free to use for developers and a small fee for enterprises.
- It offers a solid data security layer that protects sensitive data from intruders.
- It is scalable and can handle huge amount of data.
- It is compatible with virtually every operating system.
- It is very friendly to PHP, the most appreciated language for web development.
- It has large and extensive community support that can help you manage your database.
3. What are the different tables present in Mysql?
There are mainly five types of tables present in MySQL.
- It is the default database engine used in MySQL and is based on the sequential access method.
- It is the table that is used for fast data access, but the data will be lost if the table or the system crashes.
- Merge table type is added to treat multiple MyISAM tables as a single table so it removes the size limitation from MyISAM tables.
- It is the table that supports transactions using the COMMIT and ROLLBACK commands.
- ISAM had been deprecated and removed from version 5.x. All of its functionality is replaced by MyISAM.
4. In Which Order MySQL executes Queries?
Each part of the SQL SELECT statement is executed sequentially, it's important to understand the order of execution as it can save us from unwanted results, and help us create queries that execute faster.
The order of SQL SELECT statement is as follows:
1. FROM and JOINs
- Selects and joins your tables to base data.
- Filters the base data
3. GROUP BY
- Aggregates the base data
- Filters the aggregated data
- Returns the final data
6. ORDER BY
- Sorts the final data
- Limits the returned data to a row count
5. What are MySQL Joins and explain different types of MySQL Joins?
Joins help retrieving data from two or more database tables using some interconnected common fields or keys among the selected tables. There are mainly three types joins present in MySQL.
a. Inner Join
: It fetches the list of rows from specified tables that satisfy the given condition. It is the default join type.
SELECT column_name(s) FROM table1 INNER JOIN table2 ON table1.column_name = table2.column_name;
b. Left Join
: It returns all rows from the left table even if there is no match in the right table.
SELECT column_name(s) FROM table1 LEFT JOIN table2 ON table1.column_name = table2.column_name;
c. Right Join
: It returns all rows from the right table even if there is no match in the left table.
SELECT column_name(s) FROM table1 RIGHT JOIN table2 ON table1.column_name = table2.column_name;
6. How can you increase the performance of MySQL SELECT query?Following are some techniques of query optimization:
- Use indexes. You can significantly increase performance by using indexes.
- Dont use "*" while you are using SELECT command. Also avoid unnecessary columns in SELECT clause.
- DISTINCT and UNION need to be used solely if it is necessary.
- You can use short table aliases while writing queries. A short alias is parsed more quickly than a long table name or alias.
- Avoid the usage of the wildcard (%) at the start of a LIKE pattern. MySQL doesn't use an index for such a query./li>
7. How many TRIGGERS are allowed in MySql table?
MySQL supports triggers that are invoked automatically in response to the INSERT, UPDATE or DELETE event occurring in a table.
SIX triggers are allowed in MySql table. They are as follows:
- It is invoked before an insert, or before an insert statement is executed.
- It gets invoked after an insert is implemented.
- It is invoked before the update is implemented.
- It is invoked after an updation occurs.
- It is invoked before a delete occurs, or before deletion statement is implemented.
- It is invoked after a delete occurs, or after a delete operation is implemented.
8. What are the different set operations available in MySQL?The various set operations available in MySQL are as follows:
– Combines the results from multiple SELECT queries and returns all the distinct rows. UNION doesn’t work with a column that has Text Data Type
– Returns all the rows from all the tables which meet the conditions of your specifics query. It allows duplicate values.
– Returns all the distinct rows selected by the first query but does not select the rows selected by the second query.
– Returns the intersection of both queries. If a record exists in both data sets, it will be included in the INTERSECT results.
9. How can you test for NULL values in a database?
A field with a NULL value is a field with no value. The conditions involving NULL are special. You cannot use = NULL or != NULL to look for NULL values in columns. To compare the fields with NULL values, you have to use the IS NULL and IS NOT NULL operator.
Syntax of IS NULL:
SELECT column_names FROM table_name WHERE column_name IS NULL;
Syntax of IS Not NULL:
SELECT column_names FROM table_name WHERE column_name IS NOT NULL;
10. Can you elaborate on BLOB and TEXT in MySQL?BLOB
stands for Binary Large Objects. It can be used to store binary data that means we can store pictures, videos, sounds etc.
The following are the four types of BLOB
is non-binary, character based string data type and is used for storing large number of strings. Normally a blog or news article would constitute to a TEXT field.
The following are the four types of TEXT
11. What is the difference between TRUNCATE and DELETE in MySQL?DELETE
operation deletes the data of a table but we can perform Commit and Rollback to retrieve data. 'Where' condition can be used along with a delete statement.
is used to delete the data of a table permanently. You can't perform Commit and Rollback statement with TRUNCATE. Also, 'Where' condition can't be used along with TRUNCATE statement.
12. What is the difference between CHAR and VARCHAR?
Both CHAR and VARCHAR data types are used to store string data in the field of the table.
The differences between these data types are mentioned below:
stores the data or values in fixed length format. If the size of the string is smaller than the specified length, it is padded with space characters with space characters to match the specified length. On the other hand, VARCHAR
stores values in variable lengths. Values are not padded with any characters. But 1 or 2 extra bytes are added to store the length of the data.
is used to store small data whereas VARCHAR
is used to store large data.
works faster than VARCHAR