SQL Databases Flashcards

1
Q

What does First Normal Form mean?

A

All data values in the data are atomic
There are no repeating columns

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

What does Second Normal Form mean?

A

Non-key attributes are fully dependent on the primary key.
(If a non-key attribute is dependent on some but not all of the columns in a composite primary key, the table violates 2NF.)

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

What does Third Normal Form mean?

A

Non-key attributes are non-transitively dependent on primary key

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

Define a table in a relational database

A

a set of data elements organized into columns and rows

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

Define a record in a relational database

A

a row of data in a table consisting of single value in each column in the table

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

Arrange the following SQL keywords in the 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
7
Q

What are the five supported data types in SQLite?

A

NULL
INTEGER
REAL
TEXT
BLOB

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

How are booleans represented in SQLite?

A

SQLite represents Booleans as integers
(0 = False, 1 = True)

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

When is a junction table required?

A

Junction tables are needed to represent many-to-many relationships in a relational database

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

Write SQL code to create a junction table to join the following two tables:

Student (studentID, class, …)
CCA (ccaID, teacher_in_charge, …)

Assume the first column is the PK and PKs are INTEGERs

A

CREATE TABLE StudentCCA (
studentID INTEGER,
ccaID INTEGER,
PRIMARY KEY (studentID, ccaID),
FOREIGN KEY (studentID) REFERENCES Student(studentID),
FOREIGN KEY (ccaID) REFERENCES CCA(ccaID)
)

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

How should quotes be used in SQL?

A

Double-quotes (“) for identifiers (table and column names)
Single-quotes (‘) for literals (strings, values to match in a WHERE clause, etc)

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

What is the syntax to create an SQL table?

A

CREATE TABLE (
Col1 TYPE,
Col2 TYPE,
…,
PRIMARY KEY (Col1)
)

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

The following SQL code raises an error. Why?

CREATE TABLE Student (
ID INTEGER,
Name TEXT,
Class TEXT,
PRIMARY KEY (ID),
);

A

Last line (PRIMARY KEY) should not have comma

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

The following SQL code raises an error. Why?

CREATE TABLE ‘Student’ (
‘ID’ INTEGER,
‘Name’ TEXT,
‘Class’ TEXT,
PRIMARY KEY (‘ID’)
);

A

Table and column names are identifiers and should be double-quoted (“), not single-quoted (‘)

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

what is data integrity?

A

the accuracy: data recorded should accurately reflect real world

consistency: data in one part of the system should not contradict another part

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

differences between SQL and NoSQL

A

structure:
-records in SQL but have all the same columns and all the columns must have the same data type with NoSQL does not

strict:
- constraints are difficult to change as SQL follows a strict data schema (less flexible)
while NoSQL does not have a schema, hence it will require,
- 1. more validation to be implemented to ensure..
- 2. there will be more duplicated or hard to normalise data since collections cannot be joined in a query (more careful and individual updates to prevent breaking of data integrity)

scale:
-as a SQL database grows in size it requires a more powerful machine to handle the database (scales horizontally) while NoSQL can scale vertically better as more machines can be added

17
Q
A
18
Q

why should data be normalised

A
  1. reduced data redundancy
  2. protects data integrity