Databases Flashcards

1
Q

What is a database?

A

Database is a collection of data stored in organised or logical manner.
Databases usually have 4 basic functions of Create, Retrieve, Update, Delete

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

State the hierarchy of SQL and MongoDB

A

SQL:
Table: collection of records of a particular subject
Records: Complete set of data of one item/subject
Field: Set of values arranged in the table with the same data type

MongoDB
Collection: Collection contains documents
Documents: Each document contains many key-value pairs
Key-value pairs: Key to the data and the data

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

What is a primary key?

A

PK is a field in the database that acts as a unique identifier for each record

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

Foreign key

A

FK is a field which references to the PK in another table

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

What is a composite key?

A

CK is a combination of two or more fields in a table that can uniquely identify each record in the table

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

Minimal code to insert document into MongoDB

A

import pymongo
client= pymongo.MongoClient() *caps M and C
db = client[“db name”]
collection = db[“collection_name”]
coll.insert_one(“doc”)

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

What does First Normal Form mean?

A

FNF is achieved if :
- all data values in each field is atomic (singular)
EG: X TIC:MrNg,MsFernandez

  • There are no repeating columns
    EG: X Student(name, cca1, cca2…)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What does Second Normal Form mean?

A

2NF is achieved if:
- Non key attributes are full dependent on the primary key

EG: X Student(student_id, name, class, TIC)
WRONG because TIC is dependent on student_id THROUGH class attribute, thus not fully dependable and thus violates 2NF

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

What does Third Normal Form mean?

A

3NF is achieved if:
- Non key attributes are non transitively dependent on PK

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

Arrange the following SQL keywords in correct syntax order
ON
SELECT
WHERE
JOIN
ORDER BY
GROUP BY
FROM

A

SELECT
FROM
JOIN
ON
WHERE
GROUP BY
ORDER BY

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