sql Flashcards

1
Q

how do i create a table

A

CREATE TABLE tableName (attributes);

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

how do i show foreign keys

A

FOREIGN KEY (fk) REFERENCES fkTable (fk)

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

how do you insert into a table

A

INSERT INTO relation (attributes)
VALUES (all values to be inserted)

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

how do you delete from a table

A

DELETE name
FROM relation
WHERE condition

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

how do you select from a table

A

SELECT name
FROM relation
WHERE condition

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

*

A

all

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

DISTINCT

A

when selecting distinct indicates that it should not return any duplicates

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

what is the cross product of a relation list

A

when you combine each row in one table with each row in the other
basically the cartesian product

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

what are the steps in the conceptual evaluation strategy

A

compute the cross product
discard the tuples that dont satisfy the condition
display the attributes in the attribute list
if DISTINCT eliminate the duplicate rows

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

when do you HAVE create a variable/copy of the table (e.g. s.id instead of student.id)

A

when you are joining the table with itself as there each id will be duplicated and you need to know which one youre talking about

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

in which two ways can you name fields in result

A

AS and =

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

LIKE

A

used for string matching

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

_

A

any one character

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

%

A

o or more characters

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

UNION

A

used for the union of any two union-compatible sets
basically used instead of AND but have to have 2 queries instead of 1

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

EXCEPT

A

minuses the 2 select statements

17
Q

INTERSECT

A

getting the intersection of 2 sets

18
Q

IN

A

returns true if the first value is in the set returned in the query
e.g. SELECT S.sname
FROM Sailors S
WHERE S.sid IN
(SELECT R.sid (ONLY ONE Colum)
FROM Reserves R
WHERE R.bid=103)

19
Q

EXISTS

A

returns true if the set is not empty

20
Q

NOT EXISTS

A

returns true if the set is empty

21
Q

UNIQUE

A

returns true if the set doesn’t have any duplicates

22
Q

ANY

A

returns true is any tuples obey the comparison

23
Q

ALL

A

returns true if all tuples obey the comparison

24
Q

how does division work in sql

A

combines EXISTS and EXCPET
where EXISTS is the outer set where you’re trying to find your info and EXCEPT is the specific information you wanted

25
Q

COUNT

A

counts the number of things in you query

26
Q

COUNT/SUM/AVG ([DISTINCT] A)

A

counts/sums/averages the different entities in your query

27
Q

MAX/MIN

A

get the max/min value in your query

28
Q

GROUP BY

A

arranges identical data into groups

29
Q

HAVING

A

filters groups based on conditions after GROUP BY
(like WHERE but for GROUP BY)