mysql banner

MySQL Multiple Choice Questions (MCQs) and Answers

Master MySQL with Practice MCQs. Explore our curated collection of Multiple Choice Questions. Ideal for placement and interview preparation, our questions range from basic to advanced, ensuring comprehensive coverage of MySQL concepts. Begin your placement preparation journey now!

Q61

Q61 What is a stored procedure in MySQL?

A

A collection of SQL queries executed as a single query

B

A user-defined function that stores data

C

A method to backup databases

D

A protocol for MySQL communication

Q62

Q62 What is the primary advantage of using stored procedures?

A

Increased security

B

Reduced network traffic and higher performance

C

Automatic data backup

D

Simplified syntax

Q63

Q63 In MySQL, how can you pass a parameter to a stored procedure?

A

By using the IN keyword

B

By declaring it outside the procedure

C

By using the OUT keyword

D

By using the DECLARE keyword

Q64

Q64 Which of the following is NOT a characteristic of functions in MySQL?

A

Can return only one value

B

Can be used in SQL expressions

C

Can perform updates on tables

D

Can be called from within SQL

Q65

Q65 What is the purpose of the OUT parameter in a stored procedure?

A

To send data into a procedure

B

To return data from the procedure to the caller

C

To declare variable types

D

To specify optional parameters

Q66

Q66 How do stored procedures contribute to database security?

A

By restricting direct access to data

B

By encrypting data automatically

C

By logging user actions

D

By validating user inputs

Q67

Q67 What differentiates a deterministic function from a non-deterministic function in MySQL?

A

Deterministic functions return the same result any time they are called with a specific set of input values

B

Deterministic functions perform better

C

Non-deterministic functions cannot be indexed

D

Non-deterministic functions are faster

Q68

Q68 What does this SQL command do:
CREATE FUNCTION GetCustomerLevel(p_credit DOUBLE) RETURNS VARCHAR(20) RETURN CASE WHEN p_credit > 50000 THEN 'Platinum' WHEN p_credit > 20000 THEN 'Gold' ELSE 'Silver' END;?

A

Creates a function that returns a customer's level based on credit

B

Deletes a function

C

Modifies an existing function

D

None of the above

Q69

Q69 How do you execute a stored procedure named 'CalculateDiscount' that takes two parameters in MySQL?

A

EXECUTE CalculateDiscount;

B

CALL CalculateDiscount(100, 20);

C

RUN CalculateDiscount(100, 20);

D

LAUNCH CalculateDiscount(100, 20);

Q70

Q70 What is the impact of declaring a variable with the same name as a column in a stored procedure?

A

It leads to an error due to name conflict

B

It hides the column for the duration of the procedure

C

It automatically updates the column

D

It has no effect

Q71

Q71 Identify the error in this stored procedure creation:
CREATE PROCEDURE UpdateUser() BEGIN UPDATE Users SET age = age + 1; END;

A

Missing parameters for user identification

B

Syntax is correct

C

Unnecessary semicolon at END

D

Should use a function instead

Q72

Q72 What is wrong with this SQL command?
CREATE PROCEDURE ResetLog() DELETE FROM LogEntries;

A

Incorrect procedure syntax

B

DELETE statement should include a WHERE clause

C

Should be a function

D

Syntax is correct

Q73

Q73 What is a trigger in MySQL?

A

A command to start a transaction

B

A predefined action executed in response to an event

C

A scheduled database backup

D

A user privilege setting

Q74

Q74 When does a BEFORE INSERT trigger execute?

A

After the data is inserted into the table

B

Before the data is inserted into the table

C

During the data insertion

D

After the transaction commits

Q75

Q75 Which of the following is NOT a valid event for a trigger in MySQL?

A

BEFORE UPDATE

B

AFTER DELETE

C

ON SELECT

D

AFTER INSERT

Q76

Q76 What is the limitation of a trigger in MySQL related to transaction control statements?

A

Triggers cannot execute SELECT statements

B

Triggers cannot include transaction control statements

C

Triggers can rollback transactions only

D

Triggers can commit transactions only

Q77

Q77 What does the following SQL trigger do?
CREATE TRIGGER CheckAge BEFORE INSERT ON Employees FOR EACH ROW BEGIN IF NEW.Age < 18 THEN SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'Employee too young'; END IF; END;

A

Prevents insertion of employees under 18

B

Updates age of new employees

C

Deletes records of young employees

D

Calculates average age of employees

Q78

Q78 What action is performed by this SQL statement?
CREATE TRIGGER UpdateLog AFTER UPDATE ON Documents FOR EACH ROW BEGIN INSERT INTO ChangeLog (DocID, ChangedOn) VALUES (OLD.DocID, NOW()); END;

A

Logs changes to documents

B

Deletes old document records

C

Creates a backup of documents

D

None of the above

Q79

Q79 How does this trigger function?
CREATE TRIGGER SyncAudit BEFORE UPDATE ON Accounts FOR EACH ROW BEGIN UPDATE Audit SET Balance = NEW.Balance WHERE AccountID = OLD.AccountID; END;

A

Synchronizes balances in the Audit table when Accounts are updated

B

Creates a new account

C

Deletes old audit records

D

None of the above

Q80

Q80 Identify the mistake in this trigger definition:
CREATE TRIGGER AuditInsert AFTER INSERT INTO AuditRecords FOR EACH ROW BEGIN INSERT INTO AuditLog VALUES (NEW.RecordID, NOW()); END;

A

Syntax error in the INSERT statement

B

Incorrect trigger event specification

C

Missing END keyword

D

All are correct

Q81

Q81 What's wrong with this trigger?
CREATE TRIGGER ValidateCredit BEFORE INSERT ON Orders FOR EACH ROW BEGIN IF NEW.Credit > 10000 THEN SET NEW.Credit = 10000; END IF; END;

A

It modifies data during a BEFORE trigger which is not allowed

B

It should use the AFTER keyword

C

The IF condition is incorrectly formulated

D

Syntax is correct

Q82

Q82 What is a view in MySQL?

A

A physical table in the database

B

A saved SQL query that can be treated as a table

C

A user interface for databases

D

A tool for database design

Q83

Q83 Which statement is true about updatable views in MySQL?

A

All views are updatable

B

Only views created with the WITH CHECK OPTION are updatable

C

Views based on multiple tables cannot be updated

D

Views cannot be updated

Q84

Q84 How do you restrict access to specific rows of a table through a view?

A

Using the WITH RESTRICT clause

B

By setting permissions on the base table

C

Using a WHERE clause in the view definition

D

Views cannot restrict row access

Q85

Q85 What does the following SQL command do?
CREATE VIEW ActiveUsers AS SELECT * FROM Users WHERE Status = 'Active';

A

Creates a new table ActiveUsers with data from Users

B

Deletes inactive users from Users

C

Creates a view showing only active users from Users

D

Updates the status of all users in Users

Q86

Q86 What does this command do?
CREATE OR REPLACE VIEW CustomerInfo AS SELECT Name, Email FROM Customers WHERE Active = 1;

A

Replaces an existing view or creates a new one displaying certain customer info

B

Deletes the old CustomerInfo view and creates a new one

C

Alters the Customers table structure

D

None of the above

Q87

Q87 What is the purpose of the SQL command SHOW FULL TABLES WHERE Table_type = 'VIEW';?

A

To list all tables in the database

B

To display only the views in the database

C

To modify the type of tables to views

D

To delete views from the database

Q88

Q88 How does the INFORMATION_SCHEMA.VIEWS table help users?

A

It shows the SQL statements for all views in the database

B

It displays metadata about each view in the database

C

It changes the definitions of views

D

It creates new views

Q89

Q89 Identify the error in this view creation:
CREATE VIEW TotalOrders AS SELECT COUNT(*) FROM Orders;

A

Missing alias for COUNT(*)

B

Syntax is correct

C

Should use SUM instead of COUNT

D

View cannot contain aggregate functions

Q90

Q90 What's wrong with this SQL command?
CREATE VIEW CustomerContacts AS SELECT CustomerID, ContactName, ContactEmail FROM Customers WHERE ContactEmail LIKE '%@%';

A

The WHERE clause is invalid for a view

B

The LIKE operator is used incorrectly

C

There is no error

D

The view includes too many columns

ad verticalad vertical
ad