MySQL Basics Flashcards

(46 cards)

1
Q

What is MySQL?

A

MySQL is an open-source relational database management system (RDBMS) that uses SQL to manage and manipulate data.

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

What does SQL stand for?

A

Structured Query Language.

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

What is a database?

A

A structured collection of data stored electronically and organized for easy access and management.

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

What is a table in MySQL?

A

A table is a collection of related data organized into rows and columns.

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

What is a primary key?

A

A unique identifier for each record in a table. Example: id INT PRIMARY KEY.

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

What is a foreign key?

A

A key used to link two tables together, referencing a primary key in another table.

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

What command is used to show all databases?

A

Use SHOW DATABASES;

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

How do you create a new database?

A

Use CREATE DATABASE db_name;

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

How do you delete a database?

A

Use DROP DATABASE db_name;

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

How do you select a database to use?

A

Use USE db_name;

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

How do you create a new table?

A

Use CREATE TABLE table_name (column1 datatype, column2 datatype, ...);

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

How do you view all tables in a database?

A

Use SHOW TABLES;

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

How do you see the structure of a table?

A

Use DESCRIBE table_name; or SHOW COLUMNS FROM table_name;

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

How do you insert data into a table?

A

Use INSERT INTO table_name (columns) VALUES (values);

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

How do you view all data from a table?

A

Use SELECT * FROM table_name;

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

How do you select specific columns?

A

Use SELECT column1, column2 FROM table_name;

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

How do you filter results in MySQL?

A

Use WHERE clause. Example: SELECT * FROM users WHERE age > 18;

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

How do you sort query results?

A

Use ORDER BY. Example: SELECT * FROM users ORDER BY name ASC;

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

How do you limit the number of results returned?

A

Use LIMIT. Example: SELECT * FROM users LIMIT 5;

20
Q

How do you update data in a table?

A

Use UPDATE table_name SET column=value WHERE condition;

21
Q

How do you delete data from a table?

A

Use DELETE FROM table_name WHERE condition;

22
Q

How do you prevent deleting all rows accidentally?

A

Always include a WHERE clause in DELETE statements.

23
Q

How do you find unique values in a column?

A

Use SELECT DISTINCT column_name FROM table_name;

24
Q

How do you rename a column or table?

A

Use ALTER TABLE table_name RENAME COLUMN old_name TO new_name; or RENAME TABLE old_name TO new_name;

25
How do you add a new column to a table?
Use `ALTER TABLE table_name ADD column_name datatype;`
26
How do you remove a column from a table?
Use `ALTER TABLE table_name DROP COLUMN column_name;`
27
How do you combine results from two or more tables?
Use `JOIN`. Example: `SELECT * FROM users JOIN orders ON users.id = orders.user_id;`
28
What are the main types of JOINs?
INNER JOIN, LEFT JOIN, RIGHT JOIN, FULL JOIN.
29
How do you count rows in a table?
Use `SELECT COUNT(*) FROM table_name;`
30
How do you get the maximum or minimum value from a column?
Use `MAX()` and `MIN()`. Example: `SELECT MAX(age) FROM users;`
31
How do you calculate the average of a column?
Use `AVG()`. Example: `SELECT AVG(price) FROM products;`
32
How do you sum values in a column?
Use `SUM()`. Example: `SELECT SUM(quantity) FROM sales;`
33
How do you group results in MySQL?
Use `GROUP BY`. Example: `SELECT city, COUNT(*) FROM users GROUP BY city;`
34
How do you filter grouped results?
Use `HAVING`. Example: `SELECT city, COUNT(*) FROM users GROUP BY city HAVING COUNT(*) > 5;`
35
How do you combine results from two queries?
Use `UNION`. Example: `SELECT name FROM employees UNION SELECT name FROM managers;`
36
How do you sort results randomly?
Use `ORDER BY RAND();`
37
How do you find the number of rows returned?
Use `ROW_COUNT()` after a query or `SELECT COUNT(*)`.
38
How do you check MySQL version?
Use `SELECT VERSION();` or `mysql --version` in terminal.
39
What command shows current database user?
Use `SELECT USER();`
40
What command exits MySQL?
Type `EXIT;` or `QUIT;`
41
What is a NULL value?
A value that represents missing or unknown data in a table.
42
How do you check for NULL values?
Use `IS NULL` or `IS NOT NULL`. Example: `SELECT * FROM users WHERE email IS NULL;`
43
How do you create an index?
Use `CREATE INDEX index_name ON table_name (column_name);`
44
Why use an index?
To speed up searches and queries on large datasets.
45
What is normalization?
The process of organizing data to reduce redundancy and improve efficiency.
46
What is a transaction in MySQL?
A set of SQL statements that execute as a single unit using `START TRANSACTION`, `COMMIT`, and `ROLLBACK`.