MySQL Interview Questions & Answers

MySQL Interview questions

MySQL Interview Questions

  1. Question1. What's Mysql ?

    Answer :

    MySQL (pronounced "my ess cue el") is an open source relational database management system (RDBMS) that uses Structured Query Language (SQL), the most popular language for adding, accessing, and processing data in a database. Because it is open source, anyone can download MySQL and tailor it to their needs in accordance with the general public license. MySQL is noted mainly for its speed, reliability, and flexibility.

  2. Question2. What Is Ddl, Dml And Dcl ?

    Answer :

    If you look at the large variety of SQL commands, they can be divided into three large subgroups. Data Definition Language deals with database schemas and descriptions of how the data should reside in the database, therefore language statements like CREATE TABLE or ALTER TABLE belong to DDL. DML deals with data manipulation, and therefore includes most common SQL statements such SELECT, INSERT, etc. Data Control Language includes commands such as GRANT, and mostly concerns with rights, permissions and other controls of the database system.

  3. Question3. How Do You Get The Number Of Rows Affected By Query?

    Answer :

    SELECT COUNT (user_id) FROM users would only return the number of user_id’s.

  4. Question4. If The Value In The Column Is Repeatable, How Do You Find Out The Unique Values?

    Answer :

    Use DISTINCT in the query, such as SELECT DISTINCT user_firstname FROM users; You can also ask for a number of distinct values by saying SELECT COUNT (DISTINCT user_firstname) FROM users;

  5. Question5. How Do You Return The A Hundred Books Starting From 25th?

    Answer :

    SELECT book_title FROM books LIMIT 25, 100. The first number in LIMIT is the offset, the second is the number.

  6. Question6. You Wrote A Search Engine That Should Retrieve 10 Results At A Time, But At The Same Time You'd Like To Know How Many Rows There're Total. How Do You Display That To The User?

    Answer :

    SELECT SQL_CALC_FOUND_ROWS page_title FROM web_pages LIMIT 1,10; SELECT FOUND_ROWS(); The second query (not that COUNT() is never used) will tell you how many results there’re total, so you can display a phrase "Found 13,450,600 results, displaying 1-10". Note that FOUND_ROWS does not pay attention to the LIMITs you specified and always returns the total number of rows affected by query.

  7. Question7. How Would You Write A Query To Select All Teams That Won Either 2, 4, 6 Or 8 Games?

    Answer :

    SELECT team_name FROM teams WHERE team_won IN (2, 4, 6, 8)

  8. Question8. How Would You Select All The Users, Whose Phone Number Is Null?

    Answer :

    SELECT user_name FROM users WHERE ISNULL(user_phonenumber);

  9. Question9. What Does This Query Mean: Select User_name, User_isp From Users Left Join Isps Using (user_id) ?

    Answer :

    It’s equivalent to saying SELECT user_name, user_isp FROM users LEFT JOIN isps WHERE users.user_id=isps.user_id

  10. Question10. How Do You Find Out Which Auto Increment Was Assigned On The Last Insert?

    Answer :

    SELECT LAST_INSERT_ID() will return the last value assigned by the auto_increment function. Note that you don’t have to specify the table name.

  11. Question11. What Does -i-am-a-dummy Flag To Do When Starting Mysql?

    Answer :

    Makes the MySQL engine refuse UPDATE and DELETE commands where the WHERE clause is not present.

  12. Question12. On Executing The Delete Statement I Keep Getting The Error About Foreign Key Constraint Failing. What Do I Do?

    Answer :

    What it means is that so of the data that you’re trying to delete is still alive in another table. Like if you have a table for universities and a table for students, which contains the ID of the university they go to, running a delete on a university table will fail if the students table still contains people enrolled at that university. Proper way to do it would be to delete the offending data first, and then delete the university in question. Quick way would involve running SET foreign_key_checks=0 before the DELETE command, and setting the parameter back to 1 after the DELETE is done. If your foreign key was formulated with ON DELETE CASCADE, the data in dependent tables will be removed automatically.

  13. Question13. When Would You Use Order By In Delete Statement?

    Answer :

    When you’re not deleting by row ID. Such as in DELETE FROM techpreparation_com_questions ORDER BY timestamp LIMIT 1.

  14. Question14. How Can You See All Indexes Defined For A Table?

    Answer :

    SHOW INDEX FROM techpreparation_questions;

  15. Question15. How Would You Change A Column From Varchar(10) To Varchar(50)?

    Answer :

    ALTER TABLE techpreparation_questions CHANGE techpreparation_content techpreparation_CONTENT VARCHAR(50).

  16. Question16. How Would You Delete A Column?

    Answer :

    ALTER TABLE techpreparation_answers DROP answer_user_id.

  17. Question17. How Would You Change A Table To Innodb?

    Answer :

    ALTER TABLE techpreparation_questions ENGINE innodb;

  18. Question18. When You Create A Table, And Then Run Show Create Table On It, You Occasionally Get Different Results Than What You Typed In. What Does Mysql Modify In Your Newly Created Tables?

    Answer :

    1. VARCHARs with length less than 4 become CHARs
    2. CHARs with length more than 3 become VARCHARs.
    3. NOT NULL gets added to the columns declared as PRIMARY KEYs
    4. Default values such as NULL are specified for each column

  19. Question19. How Do I Find Out All Databases Starting With 'tech' To Which I Have Access To?

    Answer :

    SHOW DATABASES LIKE ‘tech%’;

  20. Question20. How Do You Concatenate Strings In Mysql?

    Answer :

    CONCAT (string1, string2, string3)

A Guided Tour Of The Mysql Source Code Bitkeeper The Major Directories The Flow The Open-source Directories The Internal And External Storage Engine Directories The "os Specific" Directories Odds And Ends A Chunk Of Code In /sql/sql_update.cc The Skeleton Of The Server Code Coding Guidelines C/c++ Configure Support For Plugins The Optimizer Code And Concepts Primary Optimizations Other Optimizations Important Algorithms And Structures The Item Class How Mysql Does Sorting (filesort) Bulk Insert How Mysql Does Caching How Mysql Uses The Join Buffer Cache How Mysql Handles Flush Tables Full-text Search Float And Double Data Types And Their Representation Threads Character/collation Sets Error Flags And Functions Functions In The Mysys Library File Formats Mysql .frm File Format How Mysql Performs Different Selects Steps Of Select Execution Select_result Class Simple Or Primary Select Structure Of Complex Select Non-subquery Union Execution Derived Table Execution Subqueries-item_subselect Single Select Engine Union Engine Special Engines Explain Execution How Mysql Transforms Subqueries Item_in_subselect::select_transformer Item_allany_subselect Item_singlerow_subselect Mysql Client/server Protocol Licensing Notice Logical Packets Elements The Packet Header Packet Types Handshake Initialization Packet Client Authentication Packet Password Functions Command Packet Types Of Result Packets Ok Packet Error Packet Result Set Header Packet Field Packet Eof Packet Row Data Packet Row Data Packet: Binary (tentative Description) Prepared Statement Initialization Packet (tentative Description) Ok For Prepared Statement Initialization Packet (tentative Description) Parameter Packet (tentative Description) Long Data Packet (tentative Description) Execute Packet (tentative Description) Compression Logical Packets Prepared Statements And Stored Routines Statement Re-execution Requirements Preparation Of A Prepared Statement Execution Of A Prepared Statement Execution Of A Stored Procedure Statement Replication Main Code Files The Binary Log Replication Threads How Replication Deals With... How A Slave Asks Its Master To Send Its Binary Log Network Packets In Detail Replication Event Format In Detail Plans Myisam Storage Engine Myisam Record Structure The .myi File Myisam Compressed Data File Layout Innodb Storage Engine Innodb Record Structure Innodb Page Structure Writing A Custom Storage Engine Mysql Introduction Mysql Overview Creating Storage Engine Source Files Creating The Handlerton Handling Handler Instantiation Defining Filename Extensions Creation Of A Table Opening A Table Implementing Basic Table Scanning Closing A Table Adding Support For Insert To A Storage Engine Adding Support For Update To A Storage Engine What Are The Methods Of Supporting Non-sequential Reading? Methods Of Non Sequential Reads Supporting Indexing Supporting Transactions Api Reference Error Messages Adding New Error Messages To Mysql Adding Storage Engine Error Messages Mysql Interview Questions Mysql Practice Tests