let’s continue:
Functions:
- What is the purpose of the COUNT() function?
- The COUNT() function is used to count the number of rows returned by a query.
- Explain the SUM() function.
- The SUM() function is used to calculate the sum of values in a column.
- Define the AVG() function.
- The AVG() function is used to calculate the average value of a column.
- What does the MAX() function do?
- The MAX() function returns the maximum value in a column.
- Describe the MIN() function.
- The MIN() function returns the minimum value in a column.
- Explain the purpose of the CONCAT() function.
- The CONCAT() function is used to concatenate two or more strings together.
- How do you use the SUBSTRING() function?
- The SUBSTRING() function is used to extract a substring from a string. Example:sqlCopy code
SELECT SUBSTRING(column_name, start_index, length) FROM table_name;
- The SUBSTRING() function is used to extract a substring from a string. Example:sqlCopy code
- What does the NOW() function return?
- The NOW() function returns the current date and time.
- Define the DATE_FORMAT() function.
- The DATE_FORMAT() function is used to format date values based on a specified format. Example:sqlCopy code
SELECT DATE_FORMAT(date_column, '%Y-%m-%d') FROM table_name;
- The DATE_FORMAT() function is used to format date values based on a specified format. Example:sqlCopy code
DDL and DML:
- What is the purpose of the CREATE TABLE statement?
- The CREATE TABLE statement is used to create a new table in the database.
- 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 code
ALTER TABLE table_name ADD column_name data_type;
- You can add a new column to an existing table using the ALTER TABLE statement. Example:sqlCopy code
- 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 code
ALTER TABLE table_name MODIFY column_name new_data_type;
- The ALTER TABLE statement is used to modify the structure of an existing table, such as adding, modifying, or dropping columns. Example:sqlCopy code
- 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 code
INSERT INTO table_name (column1, column2) VALUES (value1, value2);
- The INSERT INTO statement is used to add new rows of data into a table. Example:sqlCopy code
- Describe the UPDATE statement.
- The UPDATE statement is used to modify existing records in a table. Example:sqlCopy code
UPDATE table_name SET column1 = value1, column2 = value2 WHERE condition;
- The UPDATE statement is used to modify existing records in a table. Example:sqlCopy code
- How do you delete records from a table using SQL?
- You can delete records from a table using the DELETE statement. Example:sqlCopy code
DELETE FROM table_name WHERE condition;
- You can delete records from a table using the DELETE statement. Example:sqlCopy code
- 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.
- 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:
- 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.
- 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.
- How do you start a transaction in MySQL?
- You can start a transaction in MySQL using the START TRANSACTION statement.
- 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.