final Flashcards

(72 cards)

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
all
some but for all in the set returned by a query
26
unique
returns tuples from an NS where there are no duplicates
27
delete
delete tuples from relation delete from r where ...
28
update
change values of atts on a where cond update instructor set att = att + 4 where att > x
29
update in one statement
``` update r set att = case when att > then att = x else att = y end ```
30
join
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
views
``` basically macros for expressions create view v as select from where ```
32
check
added to creates, create(... check (x in ("x","y")));
33
create type
same utility as classes | create type binary as numberic(1,0)
34
domain
``` assert things like not null or create domain x constraint check(value in (domain)) ```
35
create index
create index on r(att)
36
large object types
blobs and clobs, binary or character, returns pointers
37
functions
doubt it
38
triggers
``` 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
types of NoSQL dbs
key value graph database document oriented column family
40
sharding
distribute a database accross many machines, as opposed to a single server
41
replica sets
other machines ensure redundancy
42
master slave replication
operations on a master server automatically correspond to slaves, scalable redundancy, quicker to access a nearby slave
43
noSQL vs risk based data management system
loose schema definition, distributed, less organization, support
44
beneits noSQL
``` 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
drawbacks noSQL
minimal support
46
mongoDB
use hashing to relate to JSON objects
47
mongoDB why use it
is simple, flexible, small, lightweight, complete, very useful
48
MDB hierarchy of objects
databases > collections > documents
49
mongoDB is for
small transactions light on joins
50
mongoDB data definition
none given, no nulls bc nothing expected
51
index
small pointer telling you where to go in the database to find something
52
kinds of indices
ordered: stored in sorted order hash: use a hash function
53
indexing serves to
speed up operations
54
dense index
record appears for every search-key value
55
sparse index
index records for only some search-key values
56
sparse indexes
slower, but with less work + overhead, entry points for "blocks"
57
secondary indices
index points to another index, which points to entry, must be dense
58
nodes composed of
key search values, and pointers to children
59
find record with KS value V
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
insert record into B+ tree
``` 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
splitting nodes
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
remove nodes
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
issues with B+ indexing
if a record moves, all pointers have to be updated
64
efficient entry
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
B- tree
no duplicates
66
B- comp with B+
very minor speed advantages, hader to maintain
67
hashing
we obtain SK value via hash function | ie numchars mod 10 returns one of 10 buckets
68
overflow bucket
when a bucket fills you add a pointer to another bucket at the end
69
problems with static hashing
- too many buckets - space allocated but can fail to be filled - periodic reorganization requires new hash function
70
dynamic hashign
grows and shrinks in size
71
delete from extendable hash
locate KV and remove it remove bucket if empty coalesce buckets if possible
72
benefits of extendable hash
doesn't degrade performance as file grows, bucket addressing, overhead can become problematic