MCQs for Class 15: Working with Databases - Part 1

Rashmi Mishra
0

 Multiple Choice Questions (MCQs)

Working with Databases - Part 1

  1. What is MySQL?
    • A) A programming language
    • B) A web server
    • C) A relational database management system
    • D) An operating system
      Answer: C
  2. Which PHP function is used to connect to a MySQL database?
    • A) mysqli_connect()
    • B) mysql_connect()
    • C) db_connect()
    • D) connect_db()
      Answer: A
  3. What SQL command is used to retrieve data from a database?
    • A) GET
    • B) SELECT
    • C) PULL
    • D) SHOW
      Answer: B
  4. Which of the following is a valid SQL statement to create a table?
    • A) CREATE TABLE users (id INT, name VARCHAR(50));
    • B) NEW TABLE users (id INT, name VARCHAR(50));
    • C) MAKE TABLE users (id INT, name VARCHAR(50));
    • D) TABLE CREATE users (id INT, name VARCHAR(50));
      Answer: A
  5. What does SQL stand for?
    • A) Structured Query Language
    • B) Simple Query Language
    • C) Standard Query Language
    • D) Syntax Query Language
      Answer: A
  6. Which operator is used in SQL to search for a specified pattern in a column?
    • A) LIKE
    • B) FIND
    • C) MATCH
    • D) SEARCH
      Answer: A
  7. Which PHP function is used to execute a query on a MySQL database?
    • A) mysql_query()
    • B) mysqli_query()
    • C) execute_query()
    • D) db_query()
      Answer: B
  8. What SQL command is used to update existing records in a table?
    • A) MODIFY
    • B) CHANGE
    • C) UPDATE
    • D) SET
      Answer: C
  9. Which SQL clause is used to filter records?
    • A) WHERE
    • B) FILTER
    • C) HAVING
    • D) SELECT
      Answer: A
  10. What is the default port number for MySQL?
    • A) 3306
    • B) 8080
    • C) 5432
    • D) 1521
      Answer: A
  11. Which SQL statement is used to delete data from a database?
    • A) DELETE
    • B) REMOVE
    • C) DROP
    • D) TRUNCATE
      Answer: A
  12. What keyword is used to create a new record in a database table?
    • A) ADD
    • B) INSERT
    • C) NEW
    • D) CREATE
      Answer: B
  13. Which function fetches a result row as an associative array in PHP?
    • A) fetch_array()
    • B) mysqli_fetch_assoc()
    • C) fetch_assoc()
    • D) fetch_row()
      Answer: B
  14. What does the acronym "CRUD" stand for in database operations?
    • A) Create, Read, Update, Delete
    • B) Create, Replace, Update, Delete
    • C) Create, Read, Upload, Delete
    • D) Create, Read, Undo, Delete
      Answer: A
  15. Which SQL function is used to count the number of rows in a table?
    • A) COUNT()
    • B) SUM()
    • C) TOTAL()
    • D) ADD()
      Answer: A
  16. In SQL, what does the GROUP BY clause do?
    • A) Groups rows that have the same values in specified columns into summary rows
    • B) Sorts the results of a query
    • C) Limits the number of rows returned
    • D) Filters the results of a query
      Answer: A
  17. What is a primary key in a database?
    • A) A column that can have null values
    • B) A unique identifier for a record in a table
    • C) A column that allows duplicate values
    • D) A special column that stores images
      Answer: B
  18. Which SQL command is used to create an index on a table?
    • A) CREATE INDEX
    • B) ADD INDEX
    • C) MAKE INDEX
    • D) BUILD INDEX
      Answer: A
  19. Which of the following SQL statements will return all columns from the "employees" table?
    • A) SELECT * FROM employees;
    • B) GET ALL FROM employees;
    • C) SELECT ALL FROM employees;
    • D) SELECT employees;
      Answer: A
  20. What PHP function closes the connection to a MySQL database?
    • A) mysqli_close()
    • B) close_connection()
    • C) db_close()
    • D) disconnect()
      Answer: A
  21. Which SQL statement is used to add a new column to an existing table?
    • A) ALTER TABLE table_name ADD column_name datatype;
    • B) UPDATE TABLE table_name ADD column_name datatype;
    • C) MODIFY TABLE table_name ADD column_name datatype;
    • D) CREATE TABLE table_name ADD column_name datatype;
      Answer: A
  22. What will be the result of the SQL statement SELECT DISTINCT department FROM employees;?
    • A) Returns all departments including duplicates
    • B) Returns unique department names
    • C) Returns the total number of departments
    • D) Returns the first department only
      Answer: B
  23. What does the LIMIT clause do in SQL?
    • A) Restricts the number of rows returned by a query
    • B) Sorts the results
    • C) Filters the results
    • D) Groups the results
      Answer: A
  24. In SQL, what is the purpose of the HAVING clause?
    • A) To filter records after aggregation
    • B) To filter records before aggregation
    • C) To sort records
    • D) To create a new table
      Answer: A
  25. Which of the following data types is not valid in MySQL?
    • A) INT
    • B) VARCHAR
    • C) BOOLEAN
    • D) OBJECT
      Answer: D
  26. Which function in PHP is used to escape special characters in a string for use in an SQL statement?
    • A) mysqli_real_escape_string()
    • B) escape_string()
    • C) addslashes()
    • D) sanitize()
      Answer: A
  27. Which SQL command is used to remove a table from a database?
    • A) DROP TABLE
    • B) DELETE TABLE
    • C) REMOVE TABLE
    • D) TRUNCATE TABLE
      Answer: A
  28. What will the SQL query SELECT * FROM employees WHERE salary IS NOT NULL; return?
    • A) All employees with a salary
    • B) All employees with a null salary
    • C) Employees with a salary of zero
    • D) All employees
      Answer: A
  29. Which of the following statements is used to create a database in MySQL?
    • A) CREATE DATABASE my_database;
    • B) NEW DATABASE my_database;
    • C) ADD DATABASE my_database;
    • D) DATABASE CREATE my_database;
      Answer: A
  30. What is the purpose of the JOIN clause in SQL?
    • A) To combine rows from two or more tables based on a related column
    • B) To filter results
    • C) To sort results
    • D) To group results
      Answer: A
  31. Which type of join returns all records from the left table and matched records from the right table?
    • A) INNER JOIN
    • B) LEFT JOIN
    • C) RIGHT JOIN
    • D) FULL JOIN
      Answer: B
  32. What keyword is used to define a foreign key in SQL?
    • A) FOREIGN
    • B) REFERENCES
    • C) KEY
    • D) LINK
      Answer: B
  33. Which function retrieves the last inserted ID in MySQL?
    • A) mysqli_last_insert_id()
    • B) last_insert_id()
    • C) get_last_id()
    • D) retrieve_id()
      Answer: A
  34. Which of the following statements will correctly count the number of records in a table?
    • A) SELECT COUNT(*) FROM employees;
    • B) SELECT NUM(*) FROM employees;
    • C) COUNT(*) IN employees;
    • D) SELECT TOTAL(*) FROM employees;
      Answer: A
  35. What will the query SELECT * FROM employees WHERE department = 'HR' AND salary > 50000; return?
    • A) Employees in HR with a salary greater than 50000
    • B) All employees in HR
    • C) All employees with a salary greater than 50000
    • D) No results
      Answer: A
  36. What is the purpose of the ORDER BY clause in SQL?
    • A) To sort the results
    • B) To group the results
    • C) To filter the results
    • D) To limit the results
      Answer: A
  37. Which PHP function is used to get the number of rows returned by a query?
    • A) mysqli_num_rows()
    • B) count_rows()
    • C) row_count()
    • D) get_rows()
      Answer: A
  38. What does the acronym "SQL" refer to in database management?
    • A) Structured Query Language
    • B) Simple Query Language
    • C) Standard Query Language
    • D) System Query Language
      Answer: A
  39. Which command is used to change the structure of an existing table?
    • A) ALTER TABLE
    • B) MODIFY TABLE
    • C) UPDATE TABLE
    • D) CHANGE TABLE
      Answer: A
  40. What is the purpose of the TRUNCATE command in SQL?
    • A) To delete all rows in a table without logging individual row deletions
    • B) To remove a table
    • C) To drop a database
    • D) To update records
      Answer: A
  41. Which SQL clause is used to group rows that have the same values?
    • A) GROUP BY
    • B) ORDER BY
    • C) JOIN
    • D) HAVING
      Answer: A
  42. Which MySQL function would you use to concatenate two strings?
    • A) CONCAT()
    • B) JOIN()
    • C) ADD()
    • D) MERGE()
      Answer: A
  43. What will the following SQL statement do: SELECT name FROM employees WHERE name LIKE 'A%';?
    • A) Return names that start with 'A'
    • B) Return all names
    • C) Return names that end with 'A'
    • D) Return names that contain 'A'
      Answer: A
  44. Which command is used to change data in a table?
    • A) UPDATE
    • B) MODIFY
    • C) CHANGE
    • D) ALTER
      Answer: A
  45. In MySQL, which keyword is used to specify a constraint?
    • A) CONSTRAINT
    • B) LIMIT
    • C) KEY
    • D) UNIQUE
      Answer: A
  46. What does the NULL value represent in a database?
    • A) A non-existent value
    • B) A value of zero
    • C) A string of length zero
    • D) A unique identifier
      Answer: A
  47. Which of the following is a valid way to insert multiple records in a single SQL statement?
    • A) INSERT INTO employees (name) VALUES ('John'), ('Jane');
    • B) INSERT INTO employees (name) ADD ('John'), ('Jane');
    • C) INSERT INTO employees (name) NEW ('John'), ('Jane');
    • D) INSERT MULTIPLE INTO employees (name) VALUES ('John'), ('Jane');
      Answer: A
  48. Which MySQL command is used to view all databases?
    • A) SHOW DATABASES;
    • B) LIST DATABASES;
    • C) VIEW DATABASES;
    • D) DISPLAY DATABASES;
      Answer: A
  49. What is the purpose of the DEFAULT keyword in SQL?
    • A) To specify a default value for a column
    • B) To define a primary key
    • C) To set constraints
    • D) To create indexes
      Answer: A
  50. What does the DISTINCT keyword do in an SQL query?
    • A) Returns unique values
    • B) Returns all values including duplicates
    • C) Filters results
    • D) Sorts results
      Answer: A
  51. Which of the following SQL statements is correct?
    • A) SELECT id, name FROM employees;
    • B) GET id, name FROM employees;
    • C) FETCH id, name FROM employees;
    • D) SHOW id, name FROM employees;
      Answer: A
  52. What is the correct syntax to delete a table in SQL?
    • A) DROP TABLE table_name;
    • B) DELETE TABLE table_name;
    • C) REMOVE TABLE table_name;
    • D) TRUNCATE TABLE table_name;
      Answer: A
  53. Which SQL function returns the highest value in a column?
    • A) MAX()
    • B) HIGHEST()
    • C) TOP()
    • D) BEST()
      Answer: A
  54. What is the purpose of the FOREIGN KEY constraint?
    • A) To maintain referential integrity between two tables
    • B) To enforce uniqueness of a column
    • C) To set a default value for a column
    • D) To define an index
      Answer: A
  55. Which command would you use to rename a table?
    • A) RENAME TABLE old_name TO new_name;
    • B) CHANGE TABLE old_name TO new_name;
    • C) ALTER TABLE old_name NAME new_name;
    • D) UPDATE TABLE old_name SET NAME new_name;
      Answer: A
  56. What does the SQL command TRUNCATE TABLE employees; do?
    • A) Removes all records from the employees table without logging individual deletions
    • B) Deletes the employees table
    • C) Updates all records in the employees table
    • D) Creates a new employees table
      Answer: A
  57. Which clause is used to filter records after grouping in SQL?
    • A) HAVING
    • B) WHERE
    • C) FILTER
    • D) GROUP BY
      Answer: A
  58. What will be the result of the SQL query SELECT * FROM employees ORDER BY salary DESC;?
    • A) Returns employees sorted by salary in descending order
    • B) Returns employees sorted by salary in ascending order
    • C) Returns employees without sorting
    • D) Returns an error
      Answer: A
  59. What is a composite key?
    • A) A key that consists of two or more columns
    • B) A key that is generated automatically
    • C) A key that is created by the user
    • D) A unique key that allows null values
      Answer: A
  60. Which of the following functions retrieves data from a result set in PHP?
    • A) mysqli_fetch_array()
    • B) fetch_data()
    • C) get_data()
    • D) retrieve_array()
      Answer: A
  61. What does the SQL command INSERT INTO employees (name, salary) VALUES ('Alice', 60000); do?
    • A) Adds a new employee with the name 'Alice' and salary 60000
    • B) Updates the salary of 'Alice' to 60000
    • C) Deletes the employee named 'Alice'
    • D) Creates a new employees table
      Answer: A
  62. Which of the following SQL commands is used to change a column's datatype?
    • A) ALTER TABLE table_name MODIFY column_name new_datatype;
    • B) CHANGE TABLE table_name ALTER column_name new_datatype;
    • C) MODIFY TABLE table_name CHANGE column_name new_datatype;
    • D) UPDATE TABLE table_name SET column_name new_datatype;
      Answer: A
  63. What does the AND operator do in SQL?
    • A) Combines two conditions and returns true if both are true
    • B) Combines two conditions and returns true if either is true
    • C) Returns all records
    • D) Filters results based on a single condition
      Answer: A
  64. What is the output of the following SQL query: SELECT UPPER(name) FROM employees;?
    • A) Returns names in uppercase
    • B) Returns names in lowercase
    • C) Returns the first name only
    • D) Returns an error
      Answer: A
  65. Which MySQL command is used to add constraints to a column?
    • A) ALTER TABLE table_name ADD CONSTRAINT constraint_name;
    • B) MODIFY TABLE table_name ADD CONSTRAINT constraint_name;
    • C) ADD CONSTRAINT table_name column_name;
    • D) CREATE CONSTRAINT table_name column_name;
      Answer: A
  66. What is a transaction in SQL?
    • A) A set of SQL commands executed as a single unit of work
    • B) A method to sort data
    • C) A command to create a new table
    • D) A command to delete records
      Answer: A
  67. What does the SQL command SELECT name FROM employees WHERE salary BETWEEN 50000 AND 80000; do?
    • A) Retrieves names of employees with a salary between 50000 and 80000
    • B) Retrieves names of employees with a salary below 50000
    • C) Retrieves names of employees with a salary above 80000
    • D) Retrieves all employee names
      Answer: A
  68. Which of the following is a valid SQL comment?
    • A) -- This is a comment
    • B) // This is a comment
    • C) /* This is a comment */
    • D) Both A and C
      Answer: D
  69. Which SQL function is used to find the number of rows that match a specified criterion?
    • A) COUNT()
    • B) TOTAL()
    • C) SUM()
    • D) MAX()
      Answer: A
  70. What will the following SQL query return: SELECT AVG(salary) FROM employees;?
    • A) The average salary of employees
    • B) The total salary of employees
    • C) The highest salary of employees
    • D) The lowest salary of employees
      Answer: A
  71. What is a primary key?
    • A) A unique identifier for a record in a table
    • B) A key that allows duplicate values
    • C) A key that can contain null values
    • D) A foreign key in another table
      Answer: A
  72. What does the AS keyword do in SQL?
    • A) Renames a column or table
    • B) Defines a primary key
    • C) Specifies a foreign key
    • D) Creates a new table
      Answer: A
  73. Which of the following SQL commands is used to create a new table?
    • A) CREATE TABLE table_name (column1 datatype, column2 datatype);
    • B) NEW TABLE table_name (column1 datatype, column2 datatype);
    • C) ADD TABLE table_name (column1 datatype, column2 datatype);
    • D) MAKE TABLE table_name (column1 datatype, column2 datatype);
      Answer: A
  74. Which SQL command is used to remove a database?
    • A) DROP DATABASE database_name;
    • B) DELETE DATABASE database_name;
    • C) REMOVE DATABASE database_name;
    • D) CLEAR DATABASE database_name;
      Answer: A
  75. What does the SQL command SELECT * FROM employees WHERE name IS NULL; do?
    • A) Retrieves records where the name is null
    • B) Retrieves records where the name is not null
    • C) Retrieves all records
    • D) Retrieves records with a blank name
      Answer: A
  76. Which SQL clause is used to sort the results of a query?
    • A) ORDER BY
    • B) SORT BY
    • C) GROUP BY
    • D) FILTER BY
      Answer: A
  77. What is the purpose of the JOIN clause in SQL?
    • A) To combine rows from two or more tables based on a related column
    • B) To delete rows from a table
    • C) To update rows in a table
    • D) To group rows in a table
      Answer: A
  78. What will the following SQL statement do: SELECT name FROM employees WHERE salary IS NOT NULL;?
    • A) Retrieve names of employees with a salary
    • B) Retrieve names of employees without a salary
    • C) Retrieve all employee names
    • D) Retrieve names of employees with a null salary
      Answer: A
  79. What does the IN operator do in SQL?
    • A) Checks if a value matches any value in a list
    • B) Checks if a value is equal to another value
    • C) Checks if a value is not in a list
    • D) Compares two values
      Answer: A
  80. Which of the following is used to create an index on a table column?
    • A) CREATE INDEX index_name ON table_name (column_name);
    • B) ADD INDEX index_name ON table_name (column_name);
    • C) NEW INDEX index_name ON table_name (column_name);
    • D) MAKE INDEX index_name ON table_name (column_name);
      Answer: A
  81. What is the correct syntax to create a view in SQL?
    • A) CREATE VIEW view_name AS SELECT column1, column2 FROM table_name;
    • B) NEW VIEW view_name AS SELECT column1, column2 FROM table_name;
    • C) CREATE VIEW view_name SELECT column1, column2 FROM table_name;
    • D) MAKE VIEW view_name AS SELECT column1, column2 FROM table_name;
      Answer: A
  82. Which SQL command is used to modify existing data in a table?
    • A) UPDATE
    • B) CHANGE
    • C) EDIT
    • D) MODIFY
      Answer: A
  83. What does the OR operator do in SQL?
    • A) Combines two conditions and returns true if either is true
    • B) Combines two conditions and returns true if both are true
    • C) Filters results based on a single condition
    • D) Returns all records
      Answer: A
  84. What does the LIKE operator do in SQL?
    • A) Searches for a specified pattern in a column
    • B) Checks if a column is null
    • C) Checks for exact matches
    • D) Filters based on a condition
      Answer: A
  85. Which SQL keyword is used to limit the number of records returned?
    • A) LIMIT
    • B) TOP
    • C) MAX
    • D) RESTRICT
      Answer: A
  86. Which of the following commands would you use to check the structure of a table?
    • A) DESCRIBE table_name;
    • B) SHOW table_name;
    • C) LIST table_name;
    • D) VIEW table_name;
      Answer: A
  87. Which SQL command is used to remove a column from a table?
    • A) ALTER TABLE table_name DROP column_name;
    • B) DELETE COLUMN column_name FROM table_name;
    • C) REMOVE column_name FROM table_name;
    • D) DROP column_name FROM table_name;
      Answer: A
  88. What will the SQL statement SELECT name, COUNT(*) FROM employees GROUP BY name; return?
    • A) The count of records for each employee name
    • B) All employee names
    • C) The total count of employees
    • D) An error
      Answer: A
  89. What is the purpose of the UNION operator in SQL?
    • A) Combines the results of two or more SELECT statements
    • B) Filters records
    • C) Sorts results
    • D) Joins tables
      Answer: A
  90. What does the EXISTS keyword do in SQL?
    • A) Checks for the existence of any record in a subquery
    • B) Deletes records from a table
    • C) Updates records in a table
    • D) Creates a new table
      Answer: A
  91. Which command is used to create a temporary table?
    • A) CREATE TEMPORARY TABLE table_name;
    • B) NEW TEMPORARY TABLE table_name;
    • C) TEMP TABLE table_name;
    • D) MAKE TEMPORARY TABLE table_name;
      Answer: A
  92. What does the CASE statement do in SQL?
    • A) Allows conditional logic in a query
    • B) Joins two tables
    • C) Filters records
    • D) Sorts results
      Answer: A
  93. What is the result of executing SELECT * FROM employees LIMIT 5;?
    • A) Retrieves the first 5 records from the employees table
    • B) Retrieves all records from the employees table
    • C) Retrieves 5 records randomly
    • D) Returns an error
      Answer: A
  94. Which of the following is a valid way to perform a left join?
    • A) SELECT * FROM table1 LEFT JOIN table2 ON table1.id = table2.id;
    • B) SELECT * FROM table1 RIGHT JOIN table2 ON table1.id = table2.id;
    • C) SELECT * FROM table1 JOIN table2;
    • D) SELECT * FROM table1 INNER JOIN table2;
      Answer: A
  95. What does the SQL command SELECT COUNT(DISTINCT column_name) FROM table_name; do?
    • A) Counts the number of unique values in a column
    • B) Counts all values in a column
    • C) Counts only null values in a column
    • D) Counts all records in the table
      Answer: A
  96. What is the correct way to comment a single line in SQL?
    • A) -- This is a comment
    • B) // This is a comment
    • C) /* This is a comment */
    • D) ** This is a comment
      Answer: A
  97. Which SQL statement is used to retrieve unique records?
    • A) SELECT DISTINCT
    • B) SELECT UNIQUE
    • C) SELECT DIFFERENT
    • D) SELECT SEPARATE
      Answer: A
  98. What will the SQL command SELECT product_name FROM products ORDER BY price DESC; do?
    • A) Retrieves product names sorted by price in descending order
    • B) Retrieves product names sorted by price in ascending order
    • C) Retrieves all product names
    • D) Retrieves product names without sorting
      Answer: A
  99. What is the purpose of the TRUNCATE command?
    • A) Deletes all records from a table without logging individual row deletions
    • B) Deletes specific records from a table
    • C) Removes the table structure
    • D) Renames a table
      Answer: A
  100. Which of the following commands is used to remove all records from a table without removing the table itself? - A) TRUNCATE table_name; - B) DELETE FROM table_name; - C) DROP table_name; - D) REMOVE table_name;
    Answer: A


Post a Comment

0Comments

Post a Comment (0)