Miscalleneous Commands Flashcards

(10 cards)

1
Q

What SQL command shows you all available databases on your server?

A

SHOW DATABASES; - Lists every database you have access to - Essential first step when connecting to a new server - Semicolon required

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

You see multiple databases listed. How do you specify which database you want to work with for your subsequent queries?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

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?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

You’ve just connected to a MySQL server. Walk through the logical sequence of these three miscellaneous commands to start working with data.

A
  1. 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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Why are SHOW DATABASES, USE, and SHOW KEYS considered ‘miscellaneous’ commands rather than data manipulation commands?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Identify what’s wrong with these commands: show databases, use mydatabase, show keys from users

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

You’re troubleshooting a foreign key constraint error. Which miscellaneous command would help you investigate the table’s key relationships?

A

SHOW * KEYS FROM table_name; - Reveals all foreign key constraints - Shows which columns reference other tables - Helps identify constraint names for potential drops/modifications

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What happens if you try to query a table without using the USE command first?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

When you run SHOW DATABASES;, what type of information does it return, and what might you see?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Create a mnemonic to remember the three miscellaneous commands and their purpose.

A

‘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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly