Miscalleneous Commands Flashcards
(10 cards)
What SQL command shows you all available databases on your server?
SHOW DATABASES; - Lists every database you have access to - Essential first step when connecting to a new server - Semicolon required
You see multiple databases listed. How do you specify which database you want to work with for your subsequent queries?
USE database_name; - Switches your session context to the specified database - All following table operations will apply to this database - Must be done before querying tables in that database
You’re working with a table but need to understand its key structure (primary keys, foreign keys, indexes). What command reveals all keys in a table?
SHOW * KEYS FROM table_name; - Alternative syntax: SHOW KEYS FROM table_name; - Displays primary keys, foreign keys, and indexes - Shows key names, column names, and key types
You’ve just connected to a MySQL server. Walk through the logical sequence of these three miscellaneous commands to start working with data.
- SHOW DATABASES; - See what databases exist 2. USE database_name; - Select the database you need 3. SHOW * KEYS FROM table_name; - Examine table structure/keys before querying
Why are SHOW DATABASES, USE, and SHOW KEYS considered ‘miscellaneous’ commands rather than data manipulation commands?
They don’t modify data (not INSERT, UPDATE, DELETE) - They don’t retrieve data records (not SELECT) - They’re administrative/informational commands - Used for database navigation and schema exploration
Identify what’s wrong with these commands: show databases, use mydatabase, show keys from users
Nothing is wrong! - SQL commands are case-insensitive - show databases = SHOW DATABASES - However, semicolons are required for statement termination - Best practice: Use uppercase for SQL keywords, but not mandatory
You’re troubleshooting a foreign key constraint error. Which miscellaneous command would help you investigate the table’s key relationships?
SHOW * KEYS FROM table_name; - Reveals all foreign key constraints - Shows which columns reference other tables - Helps identify constraint names for potential drops/modifications
What happens if you try to query a table without using the USE command first?
Two possibilities: 1. Error: ‘No database selected’ if no default database 2. Must qualify: Use database_name.table_name syntax 3. USE command sets the default database context for cleaner queries
When you run SHOW DATABASES;, what type of information does it return, and what might you see?
Returns a result set with: - Database names you have permission to access - System databases (like information_schema, mysql, performance_schema) - Your custom application databases - Format: Single column table with database names
Create a mnemonic to remember the three miscellaneous commands and their purpose.
‘See, Use, Know’ - See: SHOW DATABASES - See what’s available - Use: USE database_name - Use the one you want - Know: SHOW KEYS - Know the table structure