DDD Flashcards
What information should be included in an entity relationship diagram (ERD)?
- 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)
What is a surrogate key?
A single field used as a unique identifier which is not derived from the data in the table
Why is a surrogate key used?
Usually used to replace a compound primary key to improve performance of queries involving inner joins and make accessing historical data easier
What information needs to be included in a data dictionary?
- 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)
Which SQL operations are required?
- 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 …
What are the SQL wildcards?
- 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)
- all (e.g. SELECT * FROM Cars means select all fields in the cars table)
What does ANY do in a WHERE clause?
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
What does EXISTS do in a WHERE clause?
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
What does an entity occurrence diagram look like?
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 are many to many relationships implemented in a database system?
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
What is the difference between a strong and weak entity?
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
What is shown on a data dictionary?
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
What can be included in a query design?
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
When is HAVING used in a query?
Like WHERE but with aggregate functions, e.g. HAVING Count(*) > 3
How do you insert data into a table?
INSERT INTO tableName (col1, col2, …) VALUES (val1, val1, …);