3-MySQL Flashcards
1-Intro to MySQL 2-SQL Statements 3-Query Results 4-SQL Operators
What is the purpose of the CREATE DATABASE SQL command?
A) To delete an existing database
B) To update data in the database
C) To create a new database
D) To retrieve data from the database
C) To create a new database
Explanation: The CREATE DATABASE command in SQL is used to create a new database within a MySQL/MariaDB system.
How can you view the list of databases in MySQL?
A) LIST DATABASES
B) SHOW DATABASES
C) DISPLAY DATABASES
D) FIND DATABASES
B) SHOW DATABASES
Explanation: The SHOW DATABASES command is used in MySQL to display all the databases managed by the database server.
Which data type would you use to store a username in MySQL?
A) INT
B) DATE
C) VARCHAR
D) FLOAT
Which data type would you use to store a username in MySQL?
A) INT
B) DATE
C) VARCHAR
D) FLOAT
Explanation: The VARCHAR data type is appropriate for storing strings such as usernames, allowing for variable-length entries.
What is the standard MySQL/MariaDB port number?
A) 1521
B) 3306
C) 1433
D) 5432
B) 3306
Explanation: The default port for MySQL/MariaDB is 3306, although it can be configured to operate on a different port.
What keyword is used to automatically increment a column’s value in MySQL?
A) INCREMENT ALWAYS
B) AUTO_INCREMENT
C) INCREASE
D) AUTO_ADD
B) AUTO_INCREMENT
Explanation: The AUTO_INCREMENT keyword in MySQL is used to have a column automatically increase its value with each new record inserted.
Which command is used to view the structure of a table in MySQL?
A) VIEW TABLE
B) SHOW TABLE
C) DESCRIBE
D) EXPLAIN TABLE
C) DESCRIBE
Explanation: The DESCRIBE command is used to display the structure of a table, including its fields and their data types.
Quiz 7: What does SQL stand for?
A) Structured Query Language
B) Simple Query Language
C) Standard Query Language
D) Secure Query Language
A) Structured Query Language
Explanation: SQL stands for Structured Query Language, a standardized programming language used for managing relational databases.
How do you log in to a MySQL database from the command line?
A) mysql -u [username] -p[password]
B) mysql -user [username] -password [password]
C) connect mysql [username] [password]
D) login -u [username] -p [password]
A) mysql -u [username] -p[password]
Explanation: To log in to MySQL from the command line, you use the mysql -u [username] -p command, and then you are prompted to enter the password.
Which SQL command changes the active database?
A) CHANGE DATABASE
B) SWITCH DATABASE
C) SELECT DATABASE
D) USE
D) USE
Explanation: The USE command in SQL is used to switch the active database to the one specified in the command.
What does the NOT NULL constraint ensure in an SQL table?
A) The column must always have a numeric value
B) The column can never have a duplicate value
C) The column must always have some value and cannot be left blank
D) The column automatically increments its value
C) The column must always have some value and cannot be left blank
Explanation: The NOT NULL constraint in SQL ensures that a column cannot be left empty and must always have a value.
What does the INSERT statement do in SQL?
A) Deletes records from a table
B) Adds new records to a table
C) Modifies existing records in a table
D) Lists all records in a table
B) Adds new records to a table
Explanation: The INSERT statement is used to add new records to an existing table in a database.
What is the function of the SELECT statement in SQL?
A) To modify data in a table
B) To delete data from a table
C) To retrieve data from a table
D) To create a new table
C) To retrieve data from a table
Explanation: The SELECT statement is used to query and retrieve data from a database, allowing you to select one or more rows from one or more tables.
How do you insert multiple records into a table in a single query?
A) Using multiple INSERT statements
B) Using a JOIN clause
C) By separating values with a comma in the INSERT statement
D) By using the UPDATE statement
C) By separating values with a comma in the INSERT statement
Explanation: Multiple records can be inserted in one go by separating each record’s values with a comma within the INSERT statement.
What SQL statement would you use to remove a table from a database?
A) REMOVE TABLE
B) DELETE TABLE
C) DROP TABLE
D) ERASE TABLE
C) DROP TABLE
Explanation: The DROP TABLE statement is used to delete a table and all of its data from the database.
Which SQL command is used to modify the structure of a table?
A) CHANGE TABLE
B) MODIFY TABLE
C) ALTER TABLE
D) UPDATE TABLE
C) ALTER TABLE
Explanation: The ALTER TABLE command is used to change the structure of an existing table, such as adding, deleting, or modifying columns.
What clause is necessary in an UPDATE statement to specify which records should be modified?
A) SELECT
B) WHERE
C) WHEN
D) HAVING
B) WHERE
Explanation: The WHERE clause in an UPDATE statement specifies the conditions that must be met for the records to be updated.