SQL databases Flashcards

1
Q

What does Second Normal Form mean?

A

Non-key attributes are dependent on the primary key

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
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
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 organised by 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 a value from 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, …)
studentID and ccaID are the PKs of the tables.

Assume the PK of the junction table is a composite key 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 a primary key? State its properties.

A

A primary key is a candidate key that is most appropriate to become the main key for a table.

Uniquely identifies each record in a table
Should not change over time

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

What is a composite key? State its properties.

A

A composite key is a combination of two or more fields in a table that can be used to uniquely identify each record in a table

Uniqueness is only guaranteed when the fields are combined
When taken individually, the fields do not guarantee uniqueness

17
Q

What is a foreign key?

A

A foreign key is a field in one table that refers to the primary key in another table.

18
Q

When is a variable Y functionally dependent on a variable X?

A

Y is functionally dependent on X if for every valid instance of X, the value of X uniquely determines the value of Y.

i.e one-one relationship.

19
Q

What is data redundancy?

A

Data redundancy refers to the same data being stored more than once