You are on page 1of 6

INTERNAL MODEL

Maps conceptual model to DBMS


Represents database seen by DBMS
Require match conceptual model characteriscs
and constraints to selected implementaon
model
INTERNAL SCHEMA
Depicts representaon of internal model, using
database constructs
DATA DICTIONARY
Detailed accounng of all tables within user-created database
Contains all aribute names and characteriscs for each table
Contains metadatadata about data
PARTIAL DEPENDANCE
Dependency based on only part of composite primary key (1NF)
ATTRIBUTES
Composite aribute: not composite key. Aribute
further subdivided to yield addional aributes
Simple aribute: aribute cannot be subdivided
Single-valued aribute: have only one value
Mulvalued aribute: have many values
Derived aribute: aribute value calculated
(derived) from other aributes
DATABASE TABLE NORMALIZATION
First Normal Form (1NF) = Table format, no repeang groups and PK dened
Second Normal Form (2NF) = Table 1NF, no paral dependencies (no aribute dependent on poron of primary
key)
Third Normal Form (3NF) = Table 2NF, no transive dependencies
Boyce-Codd Normal Form (BCNF) = Table 3NF, every determinant in table candidate key
Fourth Normal Form (4NF) = Table 3NF, no independent mulvalued dependencies
RELATIONAL SCHEMA
Textual representaon of database table, each table described by name, list
aributes in parenthesis
LECTURER (EMP_NUM, LECTURER_OFFICE, LECTURER_EXTENSION,
LECTURER_HIGH)DEGREE)
KEYS
Primary Key (PK) = aribute (or combinaon) uniquely idenes row (not null)
Composite key = composed more that one aribute
Superkey = uniquely idenfy each row, funconally determines rows aributes
Candidate key = Superkey without redundancies (not contain subset aributes, itself superkey)
Secondary key = aribute (or combinaon aributes) used strictly for data retreival
Foreign key = aribute (or combinaon aributes) in one table whose value match primary key in another table,
or be null
Surrogate key = Arcial PK simplifying assignment PK to table, numeric, automac generated, hidden from user
FUNCTIONAL DEPENDENCY
Aribute B funconally dependent on A if A
determines B
Aribute B funconally dependent in A if each
value in column A determines one and one one
value in column B
DESIGN CASES
Implemenng 1:1 Relaonship
Foreign key work with primary key
Primary key one side (parent) on many sides (dependent enty) of foreign key
Maintaining history over me and must keep history
Create 1:* relaonship
FAN Traps
Relaonship improperly idened, inconsistent with real world
One enty in two 1:* relaonships to other enes, produsing associaon among other enes
not expressed in model
Redundant Relaonship
Mulple relaonship paths between related enes
Remain consistent across model
PRIMARY KEY CHARACTERISTICS
Unique value
Cannot contain null value
No change over me (stable), permanent,
unchangeable
Minimalfewest aributes
Factlessno hidden informaon, cannot be
composed
Numeric
ERM = Enty Relaonship Model
ERD = Enty Relaonship diagram
UML = Unied Modelling Language
PARTIAL AND TOTAL COMPLETENESS
Paral Completeness = every supertype occurrenece is member of subtype, may be supertype occurrences not
members of subtype
Total Completeness = every supertype occurrence must be member of at leat one subtype
ERM COMPONENTS in CRAWs FOOT MODEL
Enty = person, place, thing store mulple instances
||
| DESK |
||
| * desk_id |
| desk_colour |`
| desk_size |
||
||

Cardinality = indicate rules around relaonship
->0 zero or more
->| one or more
|| one and only one
|0 zero or one

Weak enty = existence-dependent, primary key parally or totally derived from parent
enty.
Condions met before enty classied as weak enty:
1) Enty existence-dependent on parent enty
2) Enty inherit part of primary key from parent
|-| | |
| EMPLOYEE | | DEPARTMENT |
|-| | |
| EMP_NUM {PK} | has > | DEP_NUM {PK} |
| EMP_NAME |--| EMP_NUM {PK}{FK} |
| EMP_DOB |1..1 0..* | DEP_NAM |
|-| | DEP_DOB |
|-| ||
||

Strong enty relaonship = PK of related enty contains PK component of parent enty
|-| | |
| COURSE | | CLASS |
|-| | |
| CRS_CODE {PK} | generates | CRS_CODE {PK} {FK} |
| DEPT_CODE |--| CLASS_SECTION{PK} |
| SRS_DESCRIPTION |1..1 0..* | CLASS_TIME |
| CRS_CREDITS | | ROOM_CODE |
|-| ||
|-| ||
COURSE (SRS_CODE, DEPT_CODE, CRS_DESCRIPTION, CRS_CREDITS)
CLASS (CRS_CODE, CLASS_SECTION, CLASS_TIME, ROOM_CODE)
CARDINALITY RELATIONSHIP
1:1 STUDENT -||-lls -||- SEAT
1:M INSTRUCTOR -||--teaches--|<- COURSE
M:M STUDENT ->-|takes|<- COURSE
0:N ->-0-<-
Create Database Schema
CREATE SCHEMA AUTHORIZATION {creator};
CREATE SCHEMA AUTHORIZATION JONES;
Create Table Structure
CREATE TABLE tablename (
column1 datatype [constarint] [,
Column2 datatype [constraint] [,
PRIMARY KEY (column1 [, column2]) ] [.
FOREIGN KEY (column1 [, column2])
REFERENCES tablename ] [,
CONSTRAINT constraint ] );
CREATE TABLE VENDOR (
V_CODE INTEGER NOT NULL UNIQUE,
V_NAME VARCHAR(35) NOT NULL,
V_CONTACT VARCHAR(15) NOT NULL,
PRIMARY KEY (V_CODE) );
Adding Table Rows
INSERT INTO tablename VALUES (value1, value2, , valueN );
INSERT INTO VENDOR VALUES (21225, Bryson, Inc, Smithson );
Saving Table Changes
COMMIT;
Restore Table Contents
ROLLBACK;
If not yet used, COMMIT to restore changes
Lisng Table Rows
SELECT Columnlist FROM tablename
* (asterisk) as wildchard list all aributes
SELECT * FROM PRODUCT;
SELECT P_CODE, P_DESCRIPTION, P_PRICE FROM PRODUCT;
SELECT P_DESCRIPTION, P_INDATE, P_PRICE FROM PRODUCT WHERE V_CODE = 21344;
SELECT P_DESCRIPTION, P_QOH,_PMIN FROM PRODUCT WHERE P_PRICE <= 10;
SELECT P_DESCRIPTION, P_INDATE, P_PRICE FROM PRODUCT
WHERE V_CODE = 21344 OR V_CODE = 24288;
SELECT * FROM PRODUCT WHERE NOT (V_CODE = 21344);
SELECT * FROM PRODUCT WHERE P_PRICE BETWEEN 50.00 AND 100.00;
SELECT P_CODE, P_DESCRIPTION, V_CODE FROM PRODUCT WHERE V_CODE IS NULL;
SELECT V_NAME, V_CONTACT, V+PHONE FROM VENDOR WHERE V_CONTACT LIKE Smith%;
% any and all following
_ one character
DELETING Table Rows
DELETE FROM tablename [WHERE condionlist];
DELETE FROM PRODUCT WHERE P_CODE = BRT-3;
DELETE FROM PRODUCT WHERE P_MIN = 5;
Deleing all rows:
DELETE FROM PRODUCT;
Updang Table Rows (modify data)
UPDATE tablename SET columnname = expression
[, columnnameexpression]
[ WHERE condion];
UPDATE PRODUCT SET P_INDATE = 18-JAN
WHERE P_CODE = 13-Q.P2;
Logical Operators: AND, OR, NOT
SELECT P_DESCRIPT, P_INDATE, P_PRICE, V_CODE FROM PRODUCT
WHERE V_CODE = 21344 OR V_CODE = 24288;
SELECT P_DESCRIPT, P_INDATE, P_PRICE, V_CODE FROM PRODUCT
WHERE P_PRICE < 50 and P_INDATE > 15-JAN;
SELECT P_DESCRIPT, P_INDATE, P_PRICE, V_CODE FROM PRODUCT
WHERE (P_PRICE < 50 AND P_INDATE > 15-JAN)
OR V_CODE = 24288;
SELECT * FROM PRODUCT
WHERE NOT (V_CODE = 21344);
Special Operators
Between:
SELECT * FROM PRODUCT
WHERE P_PRICE BETWEEN 50.00 and 100.00;
Is Null:
SELECT P_CODE, P_DESCRIPT, V_CODE FROM PRODUCT
WHERE V_CODE IS NULL;
Like (%, _ ):
SELECT V_NAME, V_CONTACT, V_AREACODE, V+PHONE FROM VENDOR
WHERE V_CONTACT LIKE Smith%;
In:
SELECT * FROM PRODUCT
WHERE V_CODE IN (21344, 24288); //same as OR
Exists:
SELECT * FROM VENDOR
WHERE EXISTS (SELECT * FROM PRODUCT WHERE P_QOH < P_MIN * 2 ) ;
Changing Column Characteriscs
Change column Data Type:
ALTER TABLE PTODUCT MODIFY (V_CODE CHAR (5) );
Changing Column Data Characterisc:
ALTER TABLE PRODUCT MODIFY (P_PRICE DECIMAN (2,2) );
Adding Column:
ALTER TABLE PRODUCT ADD (P_SALECODE CHAR (1) );
Dropping Column:
ALTER TABLE VENDOR DROP COLUMN V_ORDER;
Copying Parts of Table
INSERT INTO PART (PART_CODE, PART_DESCRIP, PART_PRICE, VODE)
SELECT P_CODE, P_DESCRIPT, P_PRICE, V_CODE FROM PRODUCT;
Ordering Lisng
SELECT P_CODE, P_DESCRIPT, P_INDATE, P_PRICE FROM PRODUCT ORDER BY P_PRICE;

You might also like