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