Top 50 Fresher MYSQL Interview questions – Part 3

MYSQL Interview questions

let’s continue:

Functions:

  1. What is the purpose of the COUNT() function?
    • The COUNT() function is used to count the number of rows returned by a query.
  2. Explain the SUM() function.
    • The SUM() function is used to calculate the sum of values in a column.
  3. Define the AVG() function.
    • The AVG() function is used to calculate the average value of a column.
  4. What does the MAX() function do?
    • The MAX() function returns the maximum value in a column.
  5. Describe the MIN() function.
    • The MIN() function returns the minimum value in a column.
  6. Explain the purpose of the CONCAT() function.
    • The CONCAT() function is used to concatenate two or more strings together.
  7. How do you use the SUBSTRING() function?
    • The SUBSTRING() function is used to extract a substring from a string. Example:sqlCopy codeSELECT SUBSTRING(column_name, start_index, length) FROM table_name;
  8. What does the NOW() function return?
    • The NOW() function returns the current date and time.
  9. Define the DATE_FORMAT() function.
    • The DATE_FORMAT() function is used to format date values based on a specified format. Example:sqlCopy codeSELECT DATE_FORMAT(date_column, '%Y-%m-%d') FROM table_name;

DDL and DML:

  1. What is the purpose of the CREATE TABLE statement?
    • The CREATE TABLE statement is used to create a new table in the database.
  2. How do you add a new column to an existing table?
    • You can add a new column to an existing table using the ALTER TABLE statement. Example:sqlCopy codeALTER TABLE table_name ADD column_name data_type;
  3. Explain the syntax for altering a table.
    • The ALTER TABLE statement is used to modify the structure of an existing table, such as adding, modifying, or dropping columns. Example:sqlCopy codeALTER TABLE table_name MODIFY column_name new_data_type;
  4. What is the purpose of the INSERT INTO statement?
    • The INSERT INTO statement is used to add new rows of data into a table. Example:sqlCopy codeINSERT INTO table_name (column1, column2) VALUES (value1, value2);
  5. Describe the UPDATE statement.
    • The UPDATE statement is used to modify existing records in a table. Example:sqlCopy codeUPDATE table_name SET column1 = value1, column2 = value2 WHERE condition;
  6. How do you delete records from a table using SQL?
    • You can delete records from a table using the DELETE statement. Example:sqlCopy codeDELETE FROM table_name WHERE condition;
  7. Explain the TRUNCATE TABLE statement.
    • The TRUNCATE TABLE statement is used to delete all records from a table, but it does not remove the table structure itself.
  8. What is the purpose of the DROP TABLE statement?
    • The DROP TABLE statement is used to delete an existing table along with all its data and structure.

Transactions and ACID Properties:

  1. Define a transaction.
    • A transaction is a sequence of one or more SQL statements that are executed as a single unit of work, ensuring data integrity and consistency.
  2. Explain the ACID properties.
    • ACID stands for Atomicity, Consistency, Isolation, and Durability, which are the four properties that guarantee the reliability of transactions in a database system.
  3. How do you start a transaction in MySQL?
    • You can start a transaction in MySQL using the START TRANSACTION statement.
  4. What is the purpose of the COMMIT statement?
    • The COMMIT statement is used to permanently save the changes made during a transaction to the database. It marks the successful completion of a transaction.

These questions and answers cover a wide range of MySQL concepts and should help fresher-level candidates prepare for their interviews.