DATABASED Flashcards
Define attribute
A property of an entity equivalent to a field in a table
Define entity
Any item in the system about which data is stored
Define primary key
An attribute that uniquely identifies each record in a table
Define composite key
A primary key that involves more than one attribute
Define foreign key
A primary key in another table to create a relationship
What are the properties of a first normal form?
- No repeating attributes or groups of attributes
- all attributes must be atomic (cannot consist of two data item e.g. first name and surname
- this would make it difficult to order by surname
What are the properties of a second normal form?
- In first normal form
- With no partial dependencies
- (this only occurs if primary key is a composite key)
- the value of the non-key attribute can be determined by a subset of the primary key but not the entire key
What are the properties of a third normal form?
- Second normal form
- No non-key dependencies
SQL syntax for retrieving data
SELECT attribute FROM table
SQL syntax for relational database
SELECT attributes FROM tables
JOIN table2
ON table1.primarykey = table2.foreignkey
SQL syntax to order results
SELECT attribute FROM table
WHERE attribute2 = 10
ORDER BY attribute ASC
SQL syntax to create a new table
CREATE TABLE Customers
(
CustomerID CHAR(4) NOT NULL,
FirstName VARCHAR(20) NOT NULL,
Surname VARCHAR (50) NOT NULL,
PricePaid CURRENCY
Height FLOAT (5, 2)
PRIMARY KEY (CustomerID)
#float with 5 digits and max of two after decimal
)
SQL syntax to add attribute
ALTER TABLE Customers
ADD Age INT
SQL syntax to delete attribute
ALTER TABLE Customers
DROP Height
SQL syntax to alter data type of attribute
ALTER TABLE Customers
MODIFY COLUMN Surname VARCHAR(40) NOT NULL