6 SQL Flashcards

(53 cards)

1
Q

What is SQL?

A

SQL is the language used to talk to databases.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the two main types of SQL statements?

A
  • DDL - Data Definition Language
  • DML - Data Manipulation Language
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

In SQL, what is a table referred to as?

A

Relation

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

In SQL, what is a row referred to as?

A

Tuple

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

In SQL, what is a column referred to as?

A

Attribute

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What does an SQL schema include?

A
  • Schema name
  • User (account) who owns the schema (authorization identifier)
  • List of descriptions of what is inside (tables, views, etc)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How do you create an SQL schema named Company owned by user Fury?

A

CREATE SCHEMA Company AUTHORIZATION Fury;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is a catalog in SQL?

A

A named collection of schemas in an SQL environment.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How to create a new table called employee inside the SQL schema called company?

A

CREATE TABLE Company.EMPLOYEE(
* FName VARCHAR(15) NOT NULL,
* LName VARCHAR(15) NOT NULL,
* SSN CHAR(10) NOT NULL,
* NIE CHAR(10) NOT NULL,
* BDate DATE,
* Address VARCHAR(30),
* Salary DECIMAL,
* BossSSN CHAR(10),
* NumDept INT NOT NULL,
PRIMARY KEY (SSN),
UNIQUE (NIE),
FOREIGN KEY (NumDept) REFERENCES DEPARTMENT(DNumber),
FOREIGN KEY (BossSSN) REFERENCES EMPLOYEE(SSN)
);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What does the UNIQUE constraint do in SQL?

A

Defines an alternate key.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What does VARCHAR mean in SQL?

A

Adjusts to actual number of characters but max number is set in ().

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What does CHAR mean in SQL?

A

Fixed number of characters, will be that number even if they use less.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What does DECIMAL mean in SQL?

A

Stores numbers with fixed digits before and after the decimal.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What does DATE mean in SQL?

A

Stores calendar dates in the format YYYY-MM-DD.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What does INT mean in SQL?

A

Whole number, no decimals, commonly used for counting.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What does NOT NULL mean in SQL?

A

Column must have value, can’t be left empty.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

How do you create a custom domain in SQL?

A

CREATE DOMAIN SSN-TYPE AS CHAR(10);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

How can you reuse a custom domain in SQL?

A

SSN SSN-TYPE; instead of SSN CHAR(10).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What are SQL clauses?

A

Parts of an SQL query, e.g. SELECT and FROM.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What does the SELECT clause do in an SQL query?

A

Specifies the list of attribute (column) names to be retrieved.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What does the FROM clause do in an SQL query?

A

Specifies the list of relation (table) names necessary to process the query.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

What does the WHERE clause do in an SQL query?

A

Specifies a Boolean expression.

23
Q

What is prefixing in SQL?

A

Putting the table name before the column name, e.g. DEPARTMENT.Number.

24
Q

What are aliases in SQL?

A

Temporary names for columns or tables used to make output or query easier to read or write

25
What does 'SELECT *' do in SQL?
Selects all attributes
26
What happens when there is no WHERE clause in a SQL query?
Selects all rows (tuples)
27
What does 'SELECT DISTINCT Column' do?
Removes duplicates of that column
28
What is the cost of duplicate elimination in SQL?
Expensive (sort + eliminate)
29
Which SQL operations can be used between queries to remove duplicates?
UNION, DIFFERENCE and INTERSECTION
30
What is a nested query?
Queries performed within the WHERE clause of another query called the outer query
31
What does the SQL operator 'IN' do?
Checks if a value matches any value in a list
32
How does SQL handle multiple nested queries with the same column name?
Uses the one from the innermost query first then works its way outward
33
What is an example of a single block query in SQL?
SELECT E.FName, E.LName FROM EMPLOYEE E, DEPENDENT D WHERE D.ESSN = E.SSN and E.LName = D.Name
34
List some SQL operators.
* IN * = * < * > * ≤ * ≥ * <> (same as !=) * ANY (or SOME) * ALL
35
What does the SQL operator 'ANY' do?
Checks if there exists at least one value in the set that satisfies the condition
36
What are NULL values in SQL?
Missing, undefined, or not applicable
37
What are some built-in SQL aggregation functions?
* SUM (SUM) * AVERAGE (AVG) * MAXIMUM (MAX) * MINIMUM (MIN) * COUNT
38
How do you apply aggregate functions to subgroups of tuples?
Using GROUP BY
39
What does the HAVING condition do in SQL?
Restricts groups based on a condition
40
What is the purpose of the ORDER BY clause in SQL?
To order tuples of the result of a query by the value of 1 or more attributes
41
What are the types of Joins in SQL?
* Inner Join * Left (Outer) Join * Right (Outer) Join * Full (Outer) Join * Cross (Cartesian) Join * Self Join
42
What does an Inner Join do?
Retrieves records that have matching values in the join columns of both tables
43
What is a Full (Outer) Join?
Returns all rows from both tables, including unmatched rows, filling in with NULL where there is no match
44
What is a Cross (Cartesian) Join?
Returns product of the two tables, combining each row from the first table with every row from the second table
45
What SQL commands are used for data manipulation?
* INSERT INTO * UPDATE * DELETE FROM
46
What does DDL stand for?
Data Definition Language
47
What are the three main commands in DDL?
* CREATE * ALTER * DROP
48
What is a view in SQL?
A virtual table defined by a query that pulls data from real tables when used
49
What are the characteristics of a view?
* Looks like a table * Doesn’t store data itself * Can be reused
50
When can a view be updated?
* Made from just one table * Doesn’t use GROUP BY or aggregate functions * Includes the primary key of the base table
51
When can a view NOT be updated?
* Based on joins * Uses GROUP BY or aggregation functions * Doesn’t include a unique identifier
52
What is query modification in the context of views?
System rewrites my update to apply directly to the base table(s)
53
What is view materialization?
SQL engine creates physical temporary table from the view, keeping it updated