来10道mysql热门面试题以及答案
时间: 2023-11-26 10:03:45 浏览: 36
Sure, here are 10 popular MySQL interview questions and their answers:
1. What is MySQL?
Answer: MySQL is an open source relational database management system that uses SQL (Structured Query Language) to manage and manipulate data.
2. What is a primary key in MySQL?
Answer: A primary key is a unique identifier for a record in a table. It is used to ensure that each record can be uniquely identified and accessed.
3. What is a foreign key in MySQL?
Answer: A foreign key is a field in a table that refers to the primary key of another table. It is used to link the data between two tables and maintain referential integrity.
4. What is the difference between CHAR and VARCHAR data types in MySQL?
Answer: CHAR data type is fixed-length, while VARCHAR data type is variable-length. CHAR is used for storing strings that have a fixed length, while VARCHAR is used for storing strings that have a variable length.
5. What is the difference between INNER JOIN and OUTER JOIN in MySQL?
Answer: INNER JOIN returns only the matching rows from both tables, while OUTER JOIN returns all the rows from one table and the matching rows from the other table.
6. What is the difference between WHERE and HAVING clause in MySQL?
Answer: WHERE clause is used to filter rows before grouping them, while HAVING clause is used to filter rows after grouping them.
7. What is the difference between DELETE and TRUNCATE commands in MySQL?
Answer: DELETE command is used to delete specific rows from a table, while TRUNCATE command is used to delete all the rows from a table.
8. What is the difference between COUNT(*) and COUNT(column_name) in MySQL?
Answer: COUNT(*) returns the total number of rows in a table, while COUNT(column_name) returns the number of non-null values in a specific column.
9. What is the difference between UNION and UNION ALL in MySQL?
Answer: UNION removes duplicates from the result set, while UNION ALL does not remove duplicates and returns all the rows from both tables.
10. What is the difference between INDEX and UNIQUE INDEX in MySQL?
Answer: INDEX is used to speed up the query performance by creating an index on one or more columns, while UNIQUE INDEX ensures that the values in a column or a set of columns are unique.