MYSQL basic Flashcards
What is SQL?
SQL (Structured Query Language) is a programming language used to manage and manipulate relational databases. It’s used to perform tasks such as querying data, updating records, and creating or modifying database structures.
What is a primary key?
A primary key is a unique identifier for each record in a table. It ensures that no two rows have the same key and does not allow NULL values.
What is the difference between DELETE and TRUNCATE?
DELETE removes specific rows based on a condition, can be rolled back, and triggers events. TRUNCATE removes all rows in a table, is faster, cannot be rolled back, and does not trigger events.
Explain the SELECT statement and its use.
The SELECT statement is used to query data from a database. It specifies the columns to retrieve and can include conditions for filtering the data.
What is a foreign key?
A foreign key is a field (or a set of fields) in one table that uniquely identifies a row of another table. It creates a relationship between two tables.(non primary of one table but primary key of another table)
How does a JOIN work in SQL and types of JOIN’s?
JOIN is used to combine rows from two or more tables based on a related column between them. Types include INNER JOIN, LEFT JOIN, RIGHT JOIN, and FULL JOIN.
Describe the difference between INNER JOIN and LEFT JOIN.
INNER JOIN returns only the rows where there is a match in both tables. LEFT JOIN returns all rows from the left table and matching rows from the right table; non-matching rows from the right table result in NULL.
What does the WHERE clause do?
The WHERE clause filters records to include only those that meet specific conditions. It is used in SELECT, UPDATE, and DELETE statements
How do you sort results in SQL?
Use the ORDER BY clause to sort results in ascending (ASC) or descending (DESC) order based on one or more columns.
What is GROUP BY used for?
The GROUP BY clause groups rows that have the same values in specified columns. It’s often used with aggregate functions like COUNT, SUM, AVG, etc.
What is the purpose of the HAVING clause?
HAVING filters records after aggregation (using functions like SUM or COUNT), while WHERE filters rows before aggregation.
Describe the UPDATE statement.
The UPDATE statement modifies existing records in a table based on specified conditions. eg
UPDATE students
SET email = ‘new_email@example.com’
WHERE student_id = 101;
What is a subquery?
A subquery is a query nested within another query. It can return data that the outer query will use.
What is a CHECK constraint?
A CHECK constraint limits the values that can be placed in a column by enforcing a condition that each row must meet. used during creation of table columns
Explain the UNIQUE constraint.
The UNIQUE constraint ensures that all values in a column are distinct from each other, preventing duplicate values.