SQL Flashcards

(75 cards)

1
Q

what is DDL?

A

Data Definition Language
done at the table level

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

what is DML?

A

Data Manipulation Language
done at the data level

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

what does CREATE do?

A

creates a table

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

what does ALTER do?

A

changes a table

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

what does DROP do?

A

deletes an entire table

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

what does INSERT do?

A

inserts data into a table

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

what does UPDATE do?

A

makes changes to tuples

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

what does DELETE do?

A

deletes tuples

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

what does SELECT do?

A

retrieves data from one or more tables

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

what does the NOT NULL constraint do?

A

No entries in that column can be null

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

what does the UNIQUE constraint do?

A

each entry in that specific column must have a unique value, can be NULL

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

what does the PRIMARY KEY do?

A

ensures that a column (or combination of two or more columns) have a unique identity which helps to find a particular record in a table more quickly and easily

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

what does a FOREIGN KEY do?

A

ensures the referential integrity of the data in one table to match values in another table
cannot be NULL

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

what does a CHECK do?

A

ensures that a value in a column meets a specific condition

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

what constraints make it so no entry in the column can be NULL?

A

PRIMARY KEY
FOREIGN KEY
NOT NULL

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

does a modification command in DML return a result?

A

NO

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

what happens if you do not specify a WHERE clause in your DELETE FROM statement?

A

it will delete EVERY entry from the table, but NOT the table. Basically, you will get an empty table.

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

what does an underline indicate in a database schema?

A

a PRIMARY KEY

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

what does SELECT * FROM table do?

A

prints the entire table

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

how do you rename attributes in a SELECT FROM WHERE statement?

A

SELECT name1 AS name2
FROM table
WHERE condition

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

what is the not equal to operator in SQL?

A

<>

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

how would you find the entries that begin with Bee?

A

attributeName LIKE ‘Bee%’

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

how would you find the entries that end with Bee?

A

attributeName LIKE ‘%Bee’

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

how do you compare a value with NULL?

A

columnName IS NULL
columnName IS NOT NULL

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
what is the result of comparing any value with NULL?
UNKNOWN
26
does NULL contribute to SUM, AVG, or COUNT (or any other aggregation?
NO
27
can NULL be the minimum or maximum of a column?
NO
28
what is the result of an aggregation if all of the values in the column are NULL?
NULL
29
what tuples result from R OUTER JOIN S
all tuples from R and S
30
what tuples result from R LEFT OUTER JOIN S
All tuples from R and the ones from S that have a match
31
what tuples result from R RIGHT OUTER JOIN S
All tuples from S and the ones from R that have a match
32
what tuples result from R FULL OUTER JOIN S
all tuples from R and S
33
when is the IN operator true?
if an only if the tuple is a member of the relation produced by the subquery
34
when is the ANY operator true?
if and only if x equals at least one tuple in the subquery
35
what is the condition to use the ANY operator?
the subquery must produce a table with ONLY one attribute
36
when is x <> ALL (subquery) true?
if and only if for every tuple t in the relation, x is not equal to t (<> is not equal operator)
37
by default, the ORDER BY sorts data in which order?
ascending
38
SQL is a ____-_____ level language
high-level
39
instead of telling SQL how to do something, you tell it what?
what to do
40
what is query optimization?
the database management system figures out the best way to execute the query
41
what are the two main components of SQL?
DDL and DML
42
what is a general example of creating a table?
CREATE TABLE tablename( column_name datatype, );
43
what are valid table and variable names in SQL?
any alphanumeric combination that doesn't start with a digit (CAN start with an underscore)
44
what special character can a table name start with in SQL?
an underscore _
45
what are the four categories of datatypes?
text, number, date, binary
46
what does this statement do in a table declaration? check (born > 1950)
it allows only people born after 1950 to be entered into the table
47
who came up with the idea of foreign keys?
Chris Date
48
what is SQL THE language for?
accessing databases
49
what is a generic example of adding a primary key constraint to an already created table?
ALTER TABLE table_name ADD CONSTRAINT MyPrimaryKey PRIMARY KEY(col1, col2)
50
what is a generic example of removing a constraint from a table?
ALTER TABLE table_name DROP CONSTRAINT MyPrimaryKey
51
what are the three kinds of data modifications in DML?
insert delete update
52
what is a generic example of inserting values into a table?
INSERT INTO table_name (list of columns) VALUES (list of values)
53
do you have to specify the column names when inserting data into a table?
YES!
54
what are the reasons for specifying attributes in INSERT?
1) we forgot the order of the attributes for the table 2) So that, if we don't have a value for a certain column in a tuple, SQL will put NULL in for that value
55
how do you insert many tuples into a table using a query?
INSERT INTO tableName ();
56
what is the generic syntax to change certain attributes in certain tuples of a table?
UPDATE table_name SET WHERE condition;
57
what is the generic syntax to delete certain tuples from a table?
DELETE FROM table_name WHERE condition;
58
what are the common cases for NULL values in a table?
1) Missing value: we know Joe's bar has some address, but don't know what it is 2) inapplicable: the values of attribute died for an alive person
59
what happens when you compare NULL with any value including itself using an operator (=, <>, etc.)
you get UNKNOWN
60
what are the three values SQL can produce when you compare something?
true false unknown
61
what kind of semantics does a SELECT-FROM-WHERE statement use?
bag semantics, which allow repeat data
62
where are aggregations applied when a GROUP BY statement is used?
inside each group
63
How do you distinguish attributes of the same name?
TableName.attributeName
64
65
what is the statement for a natural join in SQL?
R NATURAL JOIN S
66
what is the statement to perform a cross join in SQL?
R CROSS JOIN S
67
what is the definition of a sub query?
A parenthesized s SELECT FROM WHERE statement that can be used in the FROM or WHERE clauses in the outer SELECT FROM WHERE statement
68
If the sub query is guaranteed to produce one tuple, then the subquery can be used as what?
A value
69
What happens if you try to use a subquery as a value and it has more than one tuple or no tuples?
A runtime error occurs
70
When is the IN operator true?
If and only if the tuple is a member of the relation produced by the subquery
71
When is the IN operator true?
If and only if the tuple is a member of the relation produced by the subquery
72
When should you use IN?
When you don't know how many tuples your subquery will return
73
When is x=ANY true?
If and only if x equals at least one tuple in the subquery result
74
When is x <> ALL (subquery) true?
If and only if, for every tuple t in the subquery result, x is not equal to t.
75
If any aggregation is used, then each attribute in the SELECT clause must be either what?
Aggregated An attribute on the GROUP BY list