SQL Flashcards
functions and tags
What does the SELECT statement do in SQL?
The SELECT statement retrieves data from a database.
What is the purpose of the WHERE clause?
The WHERE clause filters records that meet specified conditions.
How do you use the INSERT INTO statement?
The INSERT INTO statement is used to add new records to a table.
What does the UPDATE statement do?
The UPDATE statement modifies existing records in a table.
What is the function of the DELETE statement?
The DELETE statement removes existing records from a table.
Explain the JOIN clause.
The JOIN clause combines rows from two or more tables based on a related column.
What does the INNER JOIN do?
The INNER JOIN returns records that have matching values in both tables.
What is a LEFT JOIN?
The LEFT JOIN returns all records from the left table and matched records from the right table.
Describe the RIGHT JOIN
The RIGHT JOIN returns all records from the right table and matched records from the left table.
What is a FULL OUTER JOIN?
The FULL OUTER JOIN returns all records when there is a match in either left or right table
What is the purpose of the GROUP BY clause?
The GROUP BY clause groups rows that have the same values in specified columns.
How does the HAVING clause work?
The HAVING clause filters groups based on specified conditions
What does the ORDER BY clause do?
The ORDER BY clause sorts the result set in ascending or descending order.
Explain the use of the LIMIT clause.
The LIMIT clause restricts the number of rows returned by a query.
What does the DISTINCT keyword do?
The DISTINCT keyword removes duplicate records from the result set.
What is the function of the COUNT() function?
The COUNT() function returns the number of rows that match a specified criterion.
How is the SUM() function used?
The SUM() function calculates the total sum of a numeric column.
What does the AVG() function do?
The AVG() function calculates the average value of a numeric column.
Describe the MIN() function.
The MIN() function returns the smallest value in a specified column.
What is the purpose of the MAX() function?
What does the LIKE operator do?
The LIKE operator is used to search for a specified pattern in a column.
How is the IN operator used?
The IN operator allows specifying multiple values in a WHERE clause.
Explain the BETWEEN operator.
The BETWEEN operator selects values within a given range.
What does the IS NULL condition do?
The IS NULL condition tests for empty values.
Describe the UNION operator.
The UNION operator combines the result sets of two or more SELECT statements.
What is the function of the EXCEPT operator?
The EXCEPT operator returns distinct rows from the left query that are not in the right query.
How does the INTERSECT operator work?
The INTERSECT operator returns the common records from two SELECT statements.
Explain the CREATE TABLE statement.
The CREATE TABLE statement is used to create a new table in the database.
What does the DROP TABLE statement do?
The DROP TABLE statement deletes a table and its data from the database.
Describe the ALTER TABLE statement.
The ALTER TABLE statement modifies an existing table structure, such as adding or dropping columns.
What is a PRIMARY KEY?
A PRIMARY KEY uniquely identifies each record in a table.
Explain the FOREIGN KEY constraint.
A FOREIGN KEY is a key used to link two tables together.
What is the purpose of the INDEX statement?
The INDEX statement creates an index (search key) for faster retrieval of records
Describe the AUTO_INCREMENT attribute.
The AUTO_INCREMENT attribute automatically generates a unique number when a new record is inserted
What does the DEFAULT constraint do?
The DEFAULT constraint provides a default value for a column when no value is specified.
How is the CHECK constraint used?
The CHECK constraint limits the value range that can be placed in a column.
Explain the CASE statement.
The CASE statement allows for conditional logic within a SQL query.
What does the COALESCE function do?
The COALESCE function returns the first non-null value in a list.
Describe the NULLIF function.
The NULLIF function returns NULL if the two arguments are equal.
What is the purpose of the CAST function?
The CAST function converts a value from one data type to another.
How is the CONVERT function used?
The CONVERT function converts a value from one data type to another, similar to CAST.
Explain the TRUNCATE TABLE statement.
The TRUNCATE TABLE statement deletes all rows in a table without logging individual row deletions.
What does the RENAME statement do?
The RENAME statement changes the name of a table or a database object.
Describe the MERGE statement.
The MERGE statement performs INSERT, UPDATE, or DELETE operations on a target table based on the results of a join with a source table.
What is a VIEW in SQL?
A VIEW is a virtual table based on the result set of a SQL query.
Explain the CREATE VIEW statement.
The CREATE VIEW statement creates a view from a SQL query.
What does the DROP VIEW statement do?
The DROP VIEW statement deletes a view from the database.
Describe the ALTER VIEW statement.
The ALTER VIEW statement modifies an existing view.
What is the EXPLAIN statement used for?
The EXPLAIN statement provides information about how SQL statements are executed, useful for performance tuning.
How is the DESCRIBE statement used?
The DESCRIBE statement provides information about the structure of a table, such as column names and data types.