DDD Flashcards

1
Q

What information should be included in an entity relationship diagram (ERD)?

A
  • Entity names
  • Entity types (strong - normal line and normal box, weak - dashed line and double box)
  • Attributes (PK - underlined, FK - starred)
  • Relationship participation (mandatory - line, optional - circle)
  • Relationship name (add a word/sentence)
  • Cardinality (any side with many needs crow’s feet)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is a surrogate key?

A

A single field used as a unique identifier which is not derived from the data in the table

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

Why is a surrogate key used?

A

Usually used to replace a compound primary key to improve performance of queries involving inner joins and make accessing historical data easier

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

What information needs to be included in a data dictionary?

A
  • Entity name
  • Attribute name
  • Primary or foreign key
  • Attribute type (can be varchar, integer, float, date, time)
  • Attribute size (for varchar)
  • Validation (can be presence, range, restricted choice, or field length)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Which SQL operations are required?

A
  • CREATE (for database or for table with primary and foreign keys specified, not null, check, and autoincrement)
  • DROP (any tables and then database)
  • SELECT (fields FROM tables WHERE condition GROUP BY field HAVING aggregate function condition
  • INSERT (INTO table (fields) VALUES (values))
  • UPDATE …
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are the SQL wildcards?

A
    • all (e.g. SELECT * FROM Cars means select all fields in the cars table)
      % - zero or more characters
      _ - 1 character (e.g. WHERE field LIKE ‘%a_’ would choose anything with a as the second last letter)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What does ANY do in a WHERE clause?

A

Applies a condition to everything in brackets, e.g. WHERE field < ANY(a, b, c) would return true if the field was smaller than any of a, b, and c

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

What does EXISTS do in a WHERE clause?

A

Returns true if something (usually the table returned from a sub-query) exists, e.g. WHERE EXISTS (SELECT * FROM Cars WHERE Manufacturer = ‘Tesla’) would return true if there are any Teslas in Cars

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

What does an entity occurrence diagram look like?

A

Ellipses labelled with the names of the entity (table) they represent, each containing their primary keys and straight solid lines connecting the entities to show the primary and foreign key relationships and their optionality and cardinality

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

How are many to many relationships implemented in a database system?

A

They can’t be directly implemented so a linking entity is needed which at a minimum would contain a compound key of the primary keys of the two entities being connected, resolving the many to many relationship through two many to one relationships

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

What is the difference between a strong and weak entity?

A

A strong entity does not rely on another entity for identification - it has a unique primary key of its own attributes; a weak entity depends on another entity to exist - it must make use of the primary key of another entity to form a unique identifier

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

What is shown on a data dictionary?

A

Entity name (e.g. Entity: Resort), column heading (Attribute name, Key, Type, Size, Required, Validation), then for each attribute name the columns are filled in: Key can be blank, PK, FK, or PK/FK, type can be integer, varchar (if there is no size column then do e.g. varchar(20)) required is yes or no for the presence check, field length validation is Length </=/> x (for varchar inputs), restricted choice validation is Restricted choice: a, b, c, range validation is Range: >= x and <= y, Auto increment would also be in the validation column

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

What can be included in a query design?

A

Field(s)/calculation(s), Table(s) query(-ies), Search criteria which can include an inner query with its own Field(s)/calculation(s), Table(s), Search criteria, then Grouping, Having, and Sort Order

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

When is HAVING used in a query?

A

Like WHERE but with aggregate functions, e.g. HAVING Count(*) > 3

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

How do you insert data into a table?

A

INSERT INTO tableName (col1, col2, …) VALUES (val1, val1, …);

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

How do you change the data in a table?

A

UPDATE tableName SET col1 = val1, col2 = val2, … WHERE condition;

17
Q

How do you remove a record from a table?

A

DELETE FROM tableName WHERE condition;

18
Q

How do you create a database?

A

CREATE DATABASE databaseName;

19
Q

How do you create a table?

A

CREATE TABLE tableName (
fieldName1 INT AUTO_INCREMENT,
fieldName2 VARCHAR(20) NOT NULL,← for presence check
fieldName3 BOOL,
fieldName4 FLOAT,
fieldName5 DATE, ← YYYY-MM-DD

PRIMARY KEY(fieldNameA, fieldNameB), ← for multiple field primary key
FOREIGN KEY(fieldName) REFERENCES tableName(field),
CHECK(fieldName condition) ← could be </=/>, BETWEEN,
)

20
Q

How do you delete a table?

A

DROP TABLE tableName;

21
Q

How do you delete a database?

A

Make sure all tables are dropped and then
DROP DATABASE databaseName;

22
Q

What is the structure of a SELECT query?

A

SELECT list of field names
FROM list of table names
WHERE condition
GROUP BY list of field names
HAVING condition
ORDER BY list of field names

23
Q

How is BETWEEN used in a SELECT query?

A

WHERE fieldname BETWEEN val1 AND val2