What is MySQL?
MySQL is an open-source relational database management system (RDBMS) that uses SQL to manage and manipulate data.
What does SQL stand for?
Structured Query Language.
What is a database?
A structured collection of data stored electronically and organized for easy access and management.
What is a table in MySQL?
A table is a collection of related data organized into rows and columns.
What is a primary key?
A unique identifier for each record in a table. Example: id INT PRIMARY KEY.
What is a foreign key?
A key used to link two tables together, referencing a primary key in another table.
What command is used to show all databases?
Use SHOW DATABASES;
How do you create a new database?
Use CREATE DATABASE db_name;
How do you delete a database?
Use DROP DATABASE db_name;
How do you select a database to use?
Use USE db_name;
How do you create a new table?
Use CREATE TABLE table_name (column1 datatype, column2 datatype, ...);
How do you view all tables in a database?
Use SHOW TABLES;
How do you see the structure of a table?
Use DESCRIBE table_name; or SHOW COLUMNS FROM table_name;
How do you insert data into a table?
Use INSERT INTO table_name (columns) VALUES (values);
How do you view all data from a table?
Use SELECT * FROM table_name;
How do you select specific columns?
Use SELECT column1, column2 FROM table_name;
How do you filter results in MySQL?
Use WHERE clause. Example: SELECT * FROM users WHERE age > 18;
How do you sort query results?
Use ORDER BY. Example: SELECT * FROM users ORDER BY name ASC;
How do you limit the number of results returned?
Use LIMIT. Example: SELECT * FROM users LIMIT 5;
How do you update data in a table?
Use UPDATE table_name SET column=value WHERE condition;
How do you delete data from a table?
Use DELETE FROM table_name WHERE condition;
How do you prevent deleting all rows accidentally?
Always include a WHERE clause in DELETE statements.
How do you find unique values in a column?
Use SELECT DISTINCT column_name FROM table_name;
How do you rename a column or table?
Use ALTER TABLE table_name RENAME COLUMN old_name TO new_name; or RENAME TABLE old_name TO new_name;