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.
How would you view all the columns for all records in a table named employees?
A) SELECT * FROM employees
B) SHOW * FROM employees
C) LIST * FROM employees
D) DISPLAY * FROM employees
A) SELECT * FROM employees
Explanation: The SELECT * FROM table_name syntax is used to select all columns from all records in the specified table.
What is the default behavior when inserting passwords directly into a database table without hashing?
A) The passwords are automatically encrypted by SQL.
B) It’s considered a best practice for security.
C) The passwords are stored in cleartext, which is a bad practice.
D) The passwords are compressed for storage efficiency.
C) The passwords are stored in cleartext, which is a bad practice.
Explanation: Storing passwords in cleartext (unencrypted) is considered a bad practice because it exposes sensitive information to potential security risks.
What SQL command is used to add a new column to an existing table?
A) ADD COLUMN in CREATE TABLE
B) INSERT COLUMN
C) ALTER TABLE ADD
D) UPDATE TABLE ADD COLUMN
C) ALTER TABLE ADD
Explanation: To add a new column to an existing table, you would use the ALTER TABLE command followed by ADD.
If you want to change the data type of a column in a table, which SQL command would you use?
A) CHANGE COLUMN
B) ALTER TABLE MODIFY
C) UPDATE TABLE
D) MODIFY DATA TYPE
B) ALTER TABLE MODIFY
Explanation: The ALTER TABLE MODIFY command is used to change the data type of a column in an existing table.
What is the purpose of the ORDER BY clause in SQL?
A) To delete records in a specified order
B) To update records in a specified order
C) To select records in a specified order
D) To limit the number of records returned
C) To select records in a specified order
Explanation: The ORDER BY clause in SQL is used to sort the results of a query in either ascending or descending order based on one or more columns.
How do you sort query results in descending order by a column named age?
A) SELECT * FROM people ORDER BY age ASC
B) SELECT * FROM people ORDER BY age DESC
C) SELECT * FROM people SORT BY age
D) SELECT * FROM people LIMIT age DESC
B) SELECT * FROM people ORDER BY age DESC
Explanation: To sort the results in descending order by the age column, you would use the ORDER BY age DESC clause in your SELECT statement.
What SQL clause is used to limit the number of records returned by a query?
A) LIMIT
B) WHERE
C) RESTRICT
D) TOP
A) LIMIT
Explanation: The LIMIT clause is used in SQL to specify the maximum number of records the query should return.
How can you retrieve only the first 5 records from a table called employees?
A) SELECT * FROM employees LIMIT 5
B) SELECT * FROM employees WHERE count=5
C) SELECT TOP 5 * FROM employees
D) SELECT * FROM employees FETCH FIRST 5 ROWS ONLY
A) SELECT * FROM employees LIMIT 5
Explanation: To retrieve only the first 5 records from the employees table, use SELECT * FROM employees LIMIT 5.