MySQL Questions and Answers

I. Multiple Choice Questions

1. The command used to modify the content of a table is:
a) ALTER TABLE
b) SELECT
c) UPDATE

Answer: c) UPDATE

Explanation: The UPDATE command is used to modify existing records in a table.

2. The command used to display the table structure is:
a) DISPLAY
b) STRUCTURE
c) DESCRIBE

Answer: c) DESCRIBE

Explanation: The DESCRIBE command (or DESC) is used to display the structure of a table, including column names, data types, and constraints.

3. A table name should begin with:
a) Number
b) Alphabet
c) Symbol

Answer: b) Alphabet

Explanation: Table names in MySQL should begin with a letter (alphabet). They can contain numbers and underscores but must start with a letter.

4. The command used to delete the database physically:
a) DELETE
b) ERASE
c) DROP

Answer: c) DROP

Explanation: The DROP command is used to delete a database or table completely from the system.

5. This wildcard character allows finding a match for any string of any length, including zero length:
a) *
b) %
c) #

Answer: b) %

Explanation: The % wildcard in SQL is used with the LIKE operator to match any string of zero or more characters.

6. This operator displays only those records that do not satisfy the specified condition:
a) AND
b) OR
c) NOT

Answer: c) NOT

Explanation: The NOT operator is used to negate a condition, displaying records that do not satisfy the specified condition.

II. Fill in the Blanks

1. MySQL is named after co-founder Michael Widenius's daughter, ______.

Answer: My

Explanation: MySQL is named after co-founder Michael Widenius's daughter, My.

2. The number of rows denotes the ______ of the table.

Answer: Cardinality

Explanation: Cardinality refers to the number of rows (records) in a table.

3. The number of ______ denotes the Degree of the table.

Answer: columns

Explanation: Degree refers to the number of columns (attributes) in a table.

4. ______ words are not allowed in a table name.

Answer: Reserved

Explanation: Reserved words (SQL keywords) are not allowed as table names in MySQL.

5. A MySQL statement is terminated by a ______.

Answer: semicolon (;)

Explanation: MySQL statements are typically terminated with a semicolon (;).

6. The underscore wildcard allows finding a match for any ______ character.

Answer: single

Explanation: The underscore (_) wildcard is used to match exactly one character in a pattern.

III. Answer the Following Questions

1. Who were the developers of MySQL?

Answer: MySQL was developed by Michael Widenius, David Axmark, and Allan Larsson.

2. Why is MySQL becoming so popular? Give two reasons.

Answer: MySQL is becoming popular because:

  1. It is open-source and free to use
  2. It offers high performance, reliability, and ease of use
  3. It works on multiple platforms and supports various programming languages
  4. It has strong security features
3. What is a constraint? Name any two constraints.

Answer: A constraint is a rule applied to data in a table to maintain data integrity.

Examples:

  • PRIMARY KEY - Uniquely identifies each record in a table
  • FOREIGN KEY - Ensures referential integrity between tables
  • NOT NULL - Ensures a column cannot have NULL values
  • UNIQUE - Ensures all values in a column are different
4. Give examples of DML commands?

Answer: DML (Data Manipulation Language) commands are used to manipulate data in the database.

Examples:

  • SELECT - Retrieves data from a database
  • INSERT - Adds new data to a database
  • UPDATE - Modifies existing data in a database
  • DELETE - Removes data from a database
5. What are the characteristics by which you can determine the data type of MySQL?

Answer: Characteristics to determine MySQL data types include:

  • The kind of values to be stored (numeric, text, date, etc.)
  • The range of values
  • The storage requirements
  • Whether the values are fixed or variable length
  • Precision requirements for numeric data
6. What is the query to display the table structure?

Answer: The query to display table structure is:

DESCRIBE table_name; or DESC table_name;

7. What is the query to display all the records in a table?

Answer: The query to display all records in a table is:

SELECT * FROM table_name;

8. List the Arithmetic Operators used in MySQL.

Answer: Arithmetic operators in MySQL include:

  • + (Addition)
  • - (Subtraction)
  • * (Multiplication)
  • / (Division)
  • % or MOD (Modulus)
  • DIV (Integer division)
9. List the Relational Operators used in MySQL.

Answer: Relational operators in MySQL include:

  • = (Equal to)
  • > (Greater than)
  • < (Less than)
  • >= (Greater than or equal to)
  • <= (Less than or equal to)
  • <> or != (Not equal to)
10. Differentiate between COUNT(*) and COUNT.

Answer:

  • COUNT(*) counts all rows in a table, including those with NULL values.
  • COUNT(column_name) counts only non-NULL values in the specified column.
11. What are the rules for naming a table in MySQL?

Answer: Rules for naming tables in MySQL:

  • Names can be up to 64 characters long
  • Names can contain letters, numbers, underscores, and $ characters
  • Names must begin with a letter
  • Names are case-sensitive depending on the operating system
  • Reserved words cannot be used as table names
  • Names should not contain spaces or special characters
12. Explain the five categories of SQL commands?

Answer: The five categories of SQL commands are:

  1. DDL (Data Definition Language) - Used to define and modify database structure (CREATE, ALTER, DROP, TRUNCATE)
  2. DML (Data Manipulation Language) - Used to manipulate data in the database (SELECT, INSERT, UPDATE, DELETE)
  3. DCL (Data Control Language) - Used to control access to data (GRANT, REVOKE)
  4. TCL (Transaction Control Language) - Used to manage transactions (COMMIT, ROLLBACK, SAVEPOINT)
  5. DQL (Data Query Language) - Used to query data from the database (SELECT)