final Flashcards

1
Q

SQL DDL

A

sequel data definition language: define relations, integrity constraints, domains,

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

types in SQL

A

char(n) fixed len string
varchar(n) variabe len string
int integer
float(n) n digit float

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

create table example

A

create tableinstructor(ID char(5),name varchar(20),salary numeric(8,2))

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

integrity constraints

A

ensure certain logical things do not happen, ie not null, primary key, foreign key

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

integrity constraints example

A

create tableinstructor(ID char(5),name varchar(20) not null,dept_namevarchar(20),salary numeric(8,2),primary key (ID),foreign key (dept_name) referencesdepartment)

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

not null

A

can be a constraint: used in create to ensure not null

can be a test: ie select all * where x is not null

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

insert example

A

insert into instructor values (‘10211’, ‘Smith’, ’Bio’, 66000);

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

delete example

A

delete from r where conditions

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

drop table

A

drop table r

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

alter example

A

Alter table – add/remove attributes●Structure:
alter table r add A D
alter table r drop A

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

basic query

A

select x
from y
where z

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

search for a substring

A

select name
from instructor
where name like ‘%dar%’;

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

more substring

A

intro% (intro followed by anything)
%mid%
‘___’ 3 characters
‘___%’ 3 or more chars

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

list people alphabetically

A

select distinct name
from instructor
order by name asc/desc

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

between exmp

A

… where att between 100 and 200

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

union

A

combine 2 relations
select …
union
select …

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

intersect

A

combine things in common

see union

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

except

A

remove items in common

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

aggregate functions

A

select x count(y)
from z
group by x

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

conditions with aggro func

A
select ...
group by x
having  count(y) > a
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

nested subqueries

A

queries where a select-from-where exists in another query

used for membership, comparisons, cardinality

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

NS for membership

A

select from

where att in (select from where)

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

rename

A

x as y

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

some

A

search thru a NS for any member
select from
where x > some NS

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

all

A

some but for all in the set returned by a query

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

unique

A

returns tuples from an NS where there are no duplicates

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

delete

A

delete tuples from relation
delete
from r
where …

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

update

A

change values of atts on a where cond
update instructor
set att = att + 4
where att > x

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

update in one statement

A
update r
set att = case
when att > 
then att = x
else att = y
end
30
Q

join

A

takes 2 relations and if atts with the same name hold the same value then that relation gets its atts appended and returned
course on r.att = s.att

31
Q

views

A
basically macros for expressions
create view v as
select
from
where
32
Q

check

A

added to creates,
create(…
check (x in (“x”,”y”)));

33
Q

create type

A

same utility as classes

create type binary as numberic(1,0)

34
Q

domain

A
assert things like not null
or 
create domain x 
constraint 
check(value in (domain))
35
Q

create index

A

create index on r(att)

36
Q

large object types

A

blobs and clobs, binary or character, returns pointers

37
Q

functions

A

doubt it

38
Q

triggers

A
given an event, can insert, delete, or update
create trigger setnull_trigger 
before update of takes
referencing new row as nrow
for each row
when (nrow.grade = ‘ ‘)
begin atomic          
set nrow.grade = null;         
end;
go back to this maybe
39
Q

types of NoSQL dbs

A

key value
graph database
document oriented
column family

40
Q

sharding

A

distribute a database accross many machines, as opposed to a single server

41
Q

replica sets

A

other machines ensure redundancy

42
Q

master slave replication

A

operations on a master server automatically correspond to slaves, scalable redundancy, quicker to access a nearby slave

43
Q

noSQL vs risk based data management system

A

loose schema definition, distributed, less organization, support

44
Q

beneits noSQL

A
elastic scaling: easily distributed
big data: high data volumes
DBA spec: designed to automate DBA out
flexible model: not very strict with schema
economics: scalable is cheaper
45
Q

drawbacks noSQL

A

minimal support

46
Q

mongoDB

A

use hashing to relate to JSON objects

47
Q

mongoDB why use it

A

is simple, flexible, small, lightweight, complete, very useful

48
Q

MDB hierarchy of objects

A

databases > collections > documents

49
Q

mongoDB is for

A

small transactions light on joins

50
Q

mongoDB data definition

A

none given, no nulls bc nothing expected

51
Q

index

A

small pointer telling you where to go in the database to find something

52
Q

kinds of indices

A

ordered: stored in sorted order
hash: use a hash function

53
Q

indexing serves to

A

speed up operations

54
Q

dense index

A

record appears for every search-key value

55
Q

sparse index

A

index records for only some search-key values

56
Q

sparse indexes

A

slower, but with less work + overhead, entry points for “blocks”

57
Q

secondary indices

A

index points to another index, which points to entry, must be dense

58
Q

nodes composed of

A

key search values, and pointers to children

59
Q

find record with KS value V

A

C is root
while C is not a leaf
move from K0…Kn until V <= K
if V > all K, then follow the last pointer
else, if V = Ki, then move to Pi+1, else Pi

(now we are at a leaf)
find i such that V = Ki
follow Pi to record
if the find fails, no record exists

60
Q

insert record into B+ tree

A
find leaf where SK val would appear
if SK val is present
add record to the file
add a pointer to the bucket
else
add record to the file
add a pointer to the bucket
if there's room, insert SK value into node
if no room, split the node
61
Q

splitting nodes

A

take the ceiling(n/2) nodes and put em in the first, rest go in the second
insert the lowest kp into the parent, split that too if needed
can propogate upwards

62
Q

remove nodes

A

find node, remove from bucket if present
if the node now has too few eles, merge
take our node and add its members to the left node
delete the pointer to our old node, merge up if needed

63
Q

issues with B+ indexing

A

if a record moves, all pointers have to be updated

64
Q

efficient entry

A

bulk entry: adding several entries to a B+ tree at once
sorted entry: sort items and entrer them n in sorted order
bottom up: sort, then add them layer by layer with prefab parts

65
Q

B- tree

A

no duplicates

66
Q

B- comp with B+

A

very minor speed advantages, hader to maintain

67
Q

hashing

A

we obtain SK value via hash function

ie numchars mod 10 returns one of 10 buckets

68
Q

overflow bucket

A

when a bucket fills you add a pointer to another bucket at the end

69
Q

problems with static hashing

A
  • too many buckets
  • space allocated but can fail to be filled
  • periodic reorganization requires new hash function
70
Q

dynamic hashign

A

grows and shrinks in size

71
Q

delete from extendable hash

A

locate KV and remove it
remove bucket if empty
coalesce buckets if possible

72
Q

benefits of extendable hash

A

doesn’t degrade performance as file grows, bucket addressing, overhead can become problematic