Schema design is an important part of application development. What are the design goal? What does it include? And what are the pros and cons of each design?
7. ID Low_temp_date Low_temp_C
1 29-DEC-1968 -18
2 22-JAN-1962 7.5
3 1-JAN-9999 -9999
City
Vancouver
Mumbai
Tel Aviv
create table lowest_temp
(id varchar2(10),
city varchar2(100),
low_temp_date varchar2(11),
low_temp_C varchar2(10)
);
8. create table events
(id NUMBER,
year VARCHAR2(10),
month VARCHAR2(10),
day VARCHAR2(10)
);
ID MONTH DAY
1 2020-01 2020-01-01
YEAR
2020
9. Index type:
◦ B*Tree
◦ Bitmap
◦ Composite - order is important
◦ Function Based Index
How many?
Autonomous DB
10. EMPID DEPT CITY
1 IT NY
2 IT SF
3 Sales SF
NAME
Karen
John
Susan
STATE
NY
CA
CA
NAME
IT
Sales
DEPT_ID
10
20
CITY_ID CITY
100 NY
200 SF
STATE
NY
CA
10
10
20
100
200
200
11. 1992 Grover City, CA => Grover Beach, CA
1. UPDATE emp
SET city='Grover Beach'
Where city='Grover City'
AND state='CA';
2. UPDATE cities
SET city='Grover Beach'
Where city='Grover City'
AND state='CA';
12. Enforce data type and values
Enforce parent-child relations
Uniqueness
Not null
Triggers - for more complex scenarios
13. OLTP DWH
Saving space Avoid duplicates Allow duplicates
Compress
Data integrity More important Less important
Normalization Normalize De-normalize
Contention Avoid Irrelevant
Performance Instant response Reports
14. Software for "Books and More"
Books - author, title, date, number of pages, price
Magazines - publication, title, date, frequency, price
Audio - musician, title, date, number of tracks, price
How would you model this information?
How many tables will you need?
18. Simple
Good performance
Access only a relevant product
Changing structure of one product doesn't affect others
Less null columns
Adding another product
Querying all products
Search for an item with unknown type
20. Classical and straight forward RDBMS design
Simple to summarize common properties
Search for an item with unknown type
Queries require more joins
Adding another product
22. Amazing flexibility
Adding another product
Entire structure can be changed on the fly
Enforcing constraints
Complex with different datatypes
Have you tried querying it?
23. A specific author:
SELECT * FROM items
WHERE type='book'
AND id IN (SELECT id FROM props
WHERE
prop_name='author' AND
prop_value='Stephen King')
24. A specific author OR number of pages:
SELECT * FROM items
WHERE type='book'
AND id IN (SELECT id FROM props
WHERE (prop_name,prop_value) IN
(('author','Stephen King'),
('num_pages',7000))
25. A specific author AND number of pages:
SELECT * FROM items
WHERE type='book'
AND id IN (SELECT id FROM props
WHERE (prop_name,prop_value) IN
(('author','Stephen King'),
('number_of_pages',7000))
GROUP BY id HAVING count(*)=2)
27. Easy for developers to handle
Extremely flexible
Not really RDBMS
Cannot enforce anything (by definition)
28. A specific author AND number of pages:
SELECT * FROM all_items
WHERE type='book'
AND other_info.author='Stephen King'
AND other_info.num_pages=7000