Databases Flashcards
What is a database?
Database is a collection of data stored in organised or logical manner.
Databases usually have 4 basic functions of Create, Retrieve, Update, Delete
State the hierarchy of SQL and MongoDB
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
What is a primary key?
PK is a field in the database that acts as a unique identifier for each record
Foreign key
FK is a field which references to the PK in another table
What is a composite key?
CK is a combination of two or more fields in a table that can uniquely identify each record in the table
Minimal code to insert document into MongoDB
import pymongo
client= pymongo.MongoClient() *caps M and C
db = client[“db name”]
collection = db[“collection_name”]
coll.insert_one(“doc”)
What does First Normal Form mean?
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…)
What does Second Normal Form mean?
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
What does Third Normal Form mean?
3NF is achieved if:
- Non key attributes are non transitively dependent on PK
Arrange the following SQL keywords in correct syntax order
ON
SELECT
WHERE
JOIN
ORDER BY
GROUP BY
FROM
SELECT
FROM
JOIN
ON
WHERE
GROUP BY
ORDER BY