Miscaleneous commands Flashcards
What command displays all currently existing databases in MySQL?
SHOW DATABASES;
What is the purpose of the SHOW DATABASES command?
To list all databases available in the MySQL server.
What command selects a specific database to work with?
USE database_name;
Why is the USE command important?
It tells MySQL which database to run queries against.
What command displays all keys in a table?
SHOW * KEYS FROM table_name;
What is the purpose of SHOW * KEYS FROM table_name?
To display information about the indexes (keys) in a table.
Which command lists all databases?
SHOW DATABASES;
Which command selects the database to use?
USE database_name;
Which command displays keys in a table?
SHOW * KEYS FROM table_name;
If you want to check which databases exist before creating a new one, what should you do?
Use the SHOW DATABASES command.
If you are working in the wrong database, how do you switch to the correct one?
Use the USE command with the correct database name.
If you need to review the indexes in a table for optimization, which command do you use?
SHOW * KEYS FROM table_name;
Spot the mistake: ‘SHOW DATABASE database_name;’
Correct syntax is: SHOW DATABASES;
Spot the mistake: ‘USE database name;’
No space allowed. Correct syntax is: USE database_name;
Explain the importance of using the correct database with the USE command.
It ensures that all your queries are executed in the intended database, preventing accidental changes elsewhere.
Describe when you would use SHOW * KEYS FROM table_name.
When you want to see the indexes and keys defined on a table, which can help with query optimization.
What happens if you run queries without selecting a database first?
MySQL will return an error saying ‘No database selected.’
Why is it good practice to check existing databases before creating a new one?
To avoid naming conflicts and unnecessary duplication.