SQL

38 flashcardsby Mohamed
Study these flashcardsFree · spaced repetition · iPhone, Android, Mac & web

All cards

1
What is SQL?
Structured Query Language (SQL) is used to manipulate and manage data in relational databases.
2
What are the main uses of SQL?
SQL is used to query data, modify data structures, and manage relational database operations.
3
What types of data can be stored in a relational database?
Tables consisting of records and fields, using data types such as text, numbers, dates, and Boolean values.
4
What is a relational database?
A database structured to recognize relationships between stored items of information.
5
What are the key components of a relational database?
Tables, primary keys, foreign keys, composite keys, records, and fields.
6
What are the four main types of SQL commands?
DDL (Data Definition Language), DML (Data Manipulation Language), DCL (Data Control Language), and TCL (Transaction Control Language).
7
What does DDL stand for and what are its commands?
Data Definition Language; commands include CREATE, ALTER, DROP, and TRUNCATE.
8
What does DML stand for and what are its commands?
Data Manipulation Language; commands include SELECT, INSERT, UPDATE, and DELETE.
9
What does DCL stand for and what are its commands?
Data Control Language; commands include GRANT and REVOKE.
10
What does TCL stand for and what are its commands?
Transaction Control Language; commands include COMMIT, ROLLBACK, and SAVEPOINT.
11
What SQL command is used to retrieve data from a database?
SELECT.
12
How do you retrieve all columns from a table?
SELECT * FROM table_name;.
13
How do you retrieve specific columns from a table?
SELECT column1, column2 FROM table_name;.
14
What clause is used to filter query results?
WHERE.
15
How do you filter records with a specific condition?
SELECT * FROM table_name WHERE column_name = 'value';.
16
What operators can be used in the WHERE clause?
=, !=, <, >, <=, >=, AND, OR, LIKE, IN, BETWEEN.
17
What SQL keyword is used to sort data?
ORDER BY (e.g., SELECT * FROM table_name ORDER BY column_name ASC;).
18
What SQL command groups records with common values?
GROUP BY.
19
What SQL command filters grouped records?
HAVING.
20
How do you limit the number of rows returned by a query?
Using the LIMIT keyword (e.g., SELECT * FROM table_name LIMIT 10;).
21
How do you create a table in SQL?
CREATE TABLE table_name (column1 datatype, column2 datatype, ...);.
22
How do you specify a primary key when creating a table?
Use PRIMARY KEY (column_name) within the CREATE TABLE statement.
23
What is the purpose of a foreign key in SQL?
To create a relationship between two tables by referencing a primary key from another table.
24
How do you add a new column to an existing table?
ALTER TABLE table_name ADD column_name datatype;.
25
How do you remove a column from a table?
ALTER TABLE table_name DROP COLUMN column_name;.
26
How do you insert a new record into a table?
INSERT INTO table_name (column1, column2) VALUES ('value1', 'value2');.
27
How do you update existing records in a table?
UPDATE table_name SET column1 = 'new_value' WHERE column2 = 'condition';.
28
How do you delete specific records from a table?
DELETE FROM table_name WHERE column_name = 'value';.
29
What SQL command is used to link tables?
JOIN (e.g., INNER JOIN, LEFT JOIN, RIGHT JOIN, FULL OUTER JOIN).
30
How does an INNER JOIN work?
It returns only the rows that have matching values in both tables.
31
What is a LEFT JOIN?
It returns all records from the left table and matching records from the right table.
32
What is a RIGHT JOIN?
It returns all records from the right table and matching records from the left table.
33
What is a FULL OUTER JOIN?
It returns all records from both tables, with NULLs where there is no match.
34
What are SQL wildcards and how are they used?
Wildcards (% and _) are used with the LIKE operator for pattern matching (e.g., SELECT * FROM table WHERE column LIKE 'A%';).
35
How do you count the number of records in a table?
Using COUNT() (e.g., SELECT COUNT(*) FROM table_name;).
36
What SQL function is used to find the sum of values in a column?
SUM().
37
What SQL function is used to calculate an average?
AVG().
38
How do you use a CASE statement in SQL?
To perform conditional logic within a query (e.g., SELECT CASE WHEN column1 > 100 THEN 'High' ELSE 'Low' END FROM table_name;).
Study all 38 cards for free