1What is SQL and how easy is it to learn?
SQL is a nonprocedural language with a vocabulary of less than 100 words, making it relatively easy to learn.
2What are the two broad categories of SQL functions?
Data Definition Language (DDL) and Data Manipulation Language (DML).
3What is the purpose of DDL in SQL?
DDL includes commands to create database objects (tables, indexes, views) and define access rights to those objects.
4What is the purpose of DML in SQL?
DML includes commands to insert, update, delete, and retrieve data within database tables.
5What does the SQL CREATE command do?
It is used to create table structures.
6What does the SQL ALTER command do?
It is used to make changes in table structures, including adding, modifying, or dropping columns.
7What is the syntax to add a column using ALTER TABLE?
ALTER TABLE tablename ADD columnname;
8How do you modify a column using ALTER TABLE?
ALTER TABLE tablename MODIFY columnname datatype;
9How do you delete a column using ALTER TABLE?
ALTER TABLE tablename DROP columnname;
10How do you define a primary key using ALTER TABLE?
ALTER TABLE tablename ADD PRIMARY KEY(fieldname);
11How do you define a foreign key using ALTER TABLE?
Use FOREIGN KEY instead of PRIMARY KEY in the ALTER TABLE statement.
12What does the DROP TABLE command do?
It deletes a table from the database.
13What is a SQL view?
A virtual table created based on a SELECT query using CREATE VIEW.
14What is the purpose of the NOT NULL constraint?
It ensures that a column does not accept null values, required for Primary Keys.
15What is the purpose of the UNIQUE constraint?
It ensures all values in a column are unique, required for Primary Keys.
16What does the DEFAULT constraint do?
It assigns a value to an attribute when a new row is added.
17What does the CHECK constraint do?
It validates data when an attribute value is entered.
18What is the purpose of the INSERT command in SQL?
To enter data into a table.
19What is the syntax for inserting a single row?
INSERT INTO columnname VALUES (value1, value2, ..., valuen);
20What is the syntax for inserting multiple rows using a subquery?
INSERT INTO tablename SELECT columnlist FROM tablename;
21What is the purpose of the SELECT command?
To retrieve and list the contents of a table.
22How do you select all columns in a table?
Use the asterisk (*) wildcard in SELECT, e.g., SELECT * FROM tablename;
23How do you add conditional restrictions to a SELECT query?
By using the WHERE clause: SELECT columnlist FROM tablelist WHERE conditionlist;
24What is the purpose of the UPDATE command?
To modify existing data in a table.
25What is the syntax for the UPDATE command?
UPDATE tablename SET columnname = expression [, columnname = expression] [WHERE conditionlist];
26What does the DELETE command do?
Deletes one or more rows from a table.
27What happens if you omit the WHERE clause in a DELETE statement?
All rows in the table are deleted.
28What is the purpose of the COMMIT command?
To permanently save any changes made to the database.
29What is the purpose of the ROLLBACK command?
To restore the database to its previous state, only if COMMIT has not been used.
30How do you sort query results in SQL?
Using the ORDER BY clause in a SELECT statement, in ascending or descending order.
31What are aggregate functions in SQL?
Functions that perform arithmetic computations over a set of rows, e.g., COUNT, MIN, MAX, AVERAGE.
32What is the purpose of the GROUP BY clause?
To group data in queries for aggregation or to limit results to unique entries.
33Why are joins important in relational databases?
They allow combining data from more than one table based on common attributes.
34What is a natural join?
A join that matches only rows with equal values in specified columns.
35What is an alias in SQL?
An alternate name for a table used in the FROM clause, e.g., FROM tablename alias.
36Name the main types of SQL joins.
Inner Join, Left Join (Left Outer Join), Right Join (Right Outer Join), Full Join.
37What is a recursive join?
A join where a table is joined to itself.