1. Trang chủ
  2. » Công Nghệ Thông Tin

Beginning Database Design- P24 potx

20 181 0
Tài liệu đã được kiểm tra trùng lặp

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 20
Dung lượng 525,81 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

MUSICIAN_ID INTEGER FOREIGN KEY REFERENCES MUSICIAN WITH NULL, DATE DATE NOT NULL, TEXT MEMO NOT NULL ; The Microsoft Access MEMOdatatype is used to represent very large strings.. Exerci

Trang 1

MUSICIAN_ID INTEGER FOREIGN KEY REFERENCES MUSICIAN WITH NULL, DATE DATE NOT NULL,

TEXT MEMO NOT NULL );

The Microsoft Access MEMOdatatype is used to represent very large strings.

Exercise 2 solution

CREATE TABLE INSTRUMENT (

INSTRUMENT_ID INTEGER PRIMARY KEY NOT NULL, SECTION_ID INTEGER FOREIGN KEY REFERENCES INSTRUMENT WITH NULL, INSTRUMENT CHAR VARYING(32) NOT NULL

);

CREATE TABLE MUSICIAN (

MUSICIAN_ID INTEGER PRIMARY KEY NOT NULL, MUSICIAN CHAR VARYING(32) NOT NULL, PHONE CHAR VARYING(32) NULL, EMAIL CHAR VARYING(32) NULL );

CREATE TABLE GENRE (

GENRE_ID INTEGER PRIMARY KEY NOT NULL, PARENT_ID INTEGER FOREIGN KEY REFERENCES GENRE WITH NULL, GENRE CHAR VARYING(32) NOT NULL

);

CREATE TABLE BAND (

BAND_ID INTEGER PRIMARY KEY NOT NULL, BAND CHAR VARYING(32) NOT NULL, FOUNDING_DATE DATE NOT NULL

);

CREATE TABLE ADVERTISEMENT (

ADVERTISEMENT_ID INTEGER PRIMARY KEY NOT NULL, DATE DATE NOT NULL,

TEXT MEMO NOT NULL );

CREATE TABLE DISCOGRAPHY (

DISCOGRAPHY_ID INTEGER PRIMARY KEY NOT NULL, CD_NAME CHAR VARYING(32) NOT NULL, RELEASE_DATE DATE NULL,

PRICE MONEY NULL );

CREATE TABLE MERCHANDISE (

433

Trang 2

MERCHANDISE_ID INTEGER PRIMARY KEY NOT NULL, TYPE CHAR VARYING(32) NOT NULL, PRICE MONEY NOT NULL

);

CREATE TABLE SHOW_VENUE

(

SHOW_ID INTEGER PRIMARY KEY NOT NULL, LOCATION CHAR VARYING(32) NOT NULL, ADDRESS_LINE_1 CHAR VARYING(32) NOT NULL, ADDRESS_LINE_2 CHAR VARYING(32) NULL, TOWN CHAR VARYING(32) NOT NULL, ZIP NUMBER(5) NULL,

POSTAL_CODE CHAR VARYING(32) NULL, COUNTRY CHAR VARYING(32) NULL, DIRECTIONS MEMO NULL,

PHONE CHAR VARYING(32) NULL SHOW_DATE DATE NOT NULL, SHOW_TIME CHAR VARYING(16) NOT NULL );

VENUE is changed to LOCATION

CREATE TABLE FACT

(

FACT_ID INTEGER NOT NULL, SHOW_ID INTEGER FOREIGN KEY REFERENCES SHOW WITH NULL, MUSICIAN_ID INTEGER FOREIGN KEY REFERENCES MUSICIAN WITH NULL, BAND_ID INTEGER FOREIGN KEY REFERENCES BAND WITH NULL, ADVERTISEMENT_ID INTEGER FOREIGN KEY REFERENCES ADVERTISEMENT

WITH NULL, DISCOGRAPHY_ID INTEGER FOREIGN KEY REFERENCES DISCOGRAPHY

WITH NULL, MERCHANDISE_ID INTEGER FOREIGN KEY REFERENCES MERCHANDISE

WITH NULL, GENRE_ID INTEGER FOREIGN KEY REFERENCES GENRE WITH NULL, INSTRUMENT_ID INTEGER FOREIGN KEY REFERENCES INSTRUMENT WITH NULL, CD_SALE_AMOUNT MONEY NULL,

MERCHANDISE_SALE_AMOUNT MONEY NULL, ADVERTISING_COST_AMOUNT MONEY NULL, SHOW_TICKET_SALES_AMOUNT_MONEY NULL );

434

Trang 3

Sample Databases

This appendix contains what should the most sensible versions of some of the more complete ERD database model diagrams, as presented in this book This appendix is intended merely as a refer-ence of database model ERDs

Following is a summary of the ERDs included in this appendix

❑ Figure B-1 shows the book publication OLTP ERD

❑ Figure B-2 shows the book publication reviews data warehouse ERD

❑ Figure B-3 shows the book publication sales data warehouse ERD

❑ Figure B-4 shows the musicians, bands, and advertisements OLTP ERD

❑ Figure B-5 shows the musicians, bands, and advertisements data warehouse ERD

❑ Figure B-6 shows the online auction house OLTP ERD

❑ Figure B-7 shows the online auction house data warehouse ERD

Trang 4

Figure B-1: Book publication OLTP ERD.

Customer

customer_id

customer

address

phone

email

credit_card_type

credit_card#

credit_card_expiry

Publisher publisher_id name

Subject subject_id parent_id (FK) name

Review review_id publication_id (FK) review_date text

Sale sale_id ISBN (FK) shipper_id (FK) customer_id (FK) sale_price sale_date

Publication publication_id subject_id (FK) author_id (FK) title

Shipper

shipper_id

shipper

address

phone

email

Edition ISBN publisher_id (FK) publication_id (FK) print_date pages list_price format

Author author_id name

CoAuthor cuoauthor_id (FK) publication_id (FK)

Rank ISBN (FK) rank ingram_units

436

Trang 5

Figure B-2: Book publication reviews data warehouse ERD.

Review review_id customer_id (FK) publication_id (FK) author_id (FK) publisher_id (FK) review_date text

publisher

Publisher publisher_id

Author author_id author

Publication publication_id title

Customer customer_id customer address phone email credit_card_type credit_card#

credit_card_expiry

437

Trang 6

Figure B-3: Book publication sales data warehouse ERD.

Sale sale_id ISBN (FK) author_id (FK) shipper_id (FK) customer_id (FK) subject_id (FK) sale_price sale_date

author

Author author_id

Book ISBN publisher title edition#

print_date pages list_price format rank ingram_units

Customer customer_id customer address phone email credit_card_type credit_card# credit_card_expiry

Subject subject_id category subject

Shipper shipper_id shipper address phone email

438

Trang 7

Figure B-4: Musicians, bands, and advertisements OLTP ERD.

Musician musician_id instrument_id (FK) band_id (FK) musician phone email skills

Advertisement advertisement_id band_id (FK) musician_id (FK) date

text

Band band_id genre_id (FK) band founding_date

Venue venue_id location address_line_1 address_line_2 town

zip postal_code country directions phone

Merchandise merchandise_id band_id (FK) type price

Show show_id band_id (FK) venue_id (FK) date time

Genre genre_id parent_id (FK) genre

Instrument instrument_id section_id (FK) instrument

Discography discography_id band_id (FK) cd_name release_date price

439

Trang 8

Figure B-5: Musicians, bands, and advertisements data warehouse ERD.

Fact fact_id location_id (FK) time_id (FK) show_id (FK) musician_id (FK) band_id (FK) advertisement_id (FK) discography_id (FK) merchandise_id (FK) genre_id (FK) instrument_id (FK) cd_sale_amount merchandise_sale_amount advertising_cost_amount show_ticket_sales_amount

Genre

genre_id parent_id (FK) genre

Band

band_id band founding_date

Advertisement

advertisement_id date

text

Discography

discography_id cd_name release_date price

Show_Venue

show_id venue address_line_1 address_line_2 town zip postal_code country show_date show_time

Merchandise

merchandise_id type price

Time

time_id year#

quarter#

month#

Location

location_id region country state city

Instrument

instrument_id section_id (FK) instrument

Musician

musician_id musician phone email

440

Trang 9

Figure B-6: Online auction house OLTP ERD.

Listing

listing#

buyer_id (FK) seller_id (FK) category_id (FK) ticker (FK) description image start_date listing_days starting_price bid_increment reserve_price buy_now_price number_of_bids winning_price current_price

History

History_id seller_id (FK) buyer_id (FK) comment_date feedback_positive feedback_neutral feedback_negative

Seller

seller_id seller company company_url popularity_rating join_date address_line_1 address_line_2 town zip postal_code country return_policy international_shipping payment_method_personal_check payment_method_cashiers_check payment_method_paypal payment_method_western_union payment_method_USPS_postal_order payment_method_international_postal_order payment_method_wire_transfer

payment_method_cash payment_method_visa payment_method_mastercard payment_method_american_express

Buyer

buyer_id buyer popularity_rating join_date address_line_1 address_line_2 town zip postal_code country

Currency

ticker currency exchange_rate decimals

Category_Hierarchy

category_id parent_id (FK) category

Bid

listing# (FK) buyer_id (FK) bid_price proxy_bid bid_date

441

Trang 10

Figure B-7: Online auction house data warehouse ERD.

Bidder

bidder_id bidder popularity_rating feedback_positives feedback_neutrals feedback_negative

Category_Hierarchy

category_id parent_id (FK) category

Seller

seller_id seller company company_url popularity_rating feedback_positives feedback_neutrals feedback_negatives

Location

location_id region country state city currency_ticker currency exchange_rate decimals

Time

time_id year quarter month

Listing_Bids

bid_id buyer_id (FK) bidder_id (FK) seller_id (FK) time_id (FK) location_id (FK) category_id (FK) listing#

listing_start_date listing_days listing_starting_price listing_bid_increment listing_reserve_price listing_buy_now_price listing_number_of_bids listing_winning_price bid_price

442

Trang 11

Index

Trang 13

Index

SYMBOLS AND NUMERICS

* (asterisk) performance issues, 200 SELECTqueries, 127, 128 () (parentheses), 134

; (semicolon), 127 1NF (1st Normal Form) denormalization, 161 described, 82–88, 403 tables, 284, 286–287 2NF (2nd Normal Form) denormalization, 160, 161–162 described, 403

functional dependencies, 89–96 tables, 284–285

3NF (3rd Normal Form) data warehouses, 169 denormalization, 157–159 described, 96–103, 403 tables, 284, 285–286, 287–288 4NF (4th Normal Form)

denormalization, 155–156 described, 107, 111–116 tables, 292–294 5NF (5th Normal Form) denormalization, 156 described, 107, 116–121, 404 tables, 294–295

A

abstracted class, 165 abstraction, 28–30, 404 access

frequency, separating fields by, 164 views, restricting, 210–211 Access (Microsoft)

datatypes, 331 field-setting options, 358, 359 active data

described, 404 and inactive data, separating, 163 adding table values, validation check, 48 addition, 133, 322

ad-hoc queries database design support, 18 described, 404

aggregated query, 126, 135–137, 404 algorithm

described, 404 table, hashing, 68 aliases

short, improving SQL performance with, 201 table names, substituting in SELECT query, 128–130

ALTER TABLEcommand, 145 alternate indexing

described, 65, 404 foreign keys, 345, 348–352 optimizing performance, 209 post-development database, tuning, 198

Trang 14

American National Standards Institute (ANSI)

datatypes, 330

defined, 404

analysis

company objectives, 226–228

considerations at root of, 222–223

data warehouse model

business rules, discovering, 248–252

company operations, establishing, 244–248

sample, 252–253

static and transactional information,

separating, 243–244

described, 404

existing system, 222

generic and standardized models, 225

normalization and data integrity, 224

OLTP database model

business rules, discovering, 232–234

categories and business rules, 234–237

company operations, establishing, 229–232

tables, adding, 240–241

performance, 224–225

project management

budgeting, 255–256

planning and timelines, 253–255

putting into practice, 225–226

queries, improving through normalization, 224

requirements activity, 221

as step in database design, 219–220

ANDlogical operator

described, 132

performance, 204

anomalies

described, 404

DKNF, 121

normalization, 74–76

ANSI (American National Standards Institute)

datatypes, 330

defined, 404

application

caching, 211–212

complexity handled by object database model, 13

database model, 5–6

defined, 3, 404

dependence, minimizing to accommodate

changes, 19

as latest evolution of database modeling, 3 OLTP database model changes, 323 rewriting, 260

standard database model, 225 approval, design issues, 260–261 arithmetical precedence, 133 ascending order, indexing, 68, 404 asterisk (*)

performance issues, 200 SELECTqueries, 127, 128 attribute, 40–42, 165, 404

auction house See online auction house sample

auto counters described, 404 OLTP table, 385 performance tuning, 206 table records, 275 tables, 393

B

backtracking, OLTP database model tables, 295–302 Backus-Naur form, 127, 404 basic query, 126

batch operations, 173 BCNF (Boyce-Codd Normal Form) denormalization, 154–155 described, 107, 108–111, 405 tables, 290–292

BETWEENrange scans, 131, 404 binary objects

described, 46–47, 404 specialized datatypes, 331 binary tree (BTree) indexes, 66–67, 385, 391, 405 bitmap index, 66–68, 392, 404

black box code, 19, 166, 405 blocks of commands, 145 book publication sample database data warehouse

overall ERD, 437 sales ERD, 438 metadata, changing, 145–146 object versus relational database models, 166 OLTP ERD, 436

446

Trang 15

queries basic, 125, 127–129 composite, 143–144 filtering, 130–132 join, 137–141 nested, 141–143 precedence rules, utilizing, 134 sorting, 135

summary, creating, 136 raw data, 39

records, 40 tables delete anomaly, 76 denormalizing, 153, 163–164 ERD, 50

fields, 38 identifying, non-identifying, and dependent relationships, 58

insert anomaly, 75 many-to-many relationship, 54–55 1NF, 83–86

one-to-many relationship, 51, 52–53 one-to-one NULL tables, 105–107 one-to-one relationship, 51–52 primary key, 59

scripts creating, 60–61 2NF, 90–94

vertical structure, 41 zero-to-one relationship, 56–57 transactions, 145

bookstore See online bookstore sample

Boolean logic datatypes Access, 331 data warehouse, 336 OLTP, 368

EXISTSkeyword, 142 WHEREclause filtering, 132 boxes (computer systems), 396

Boyce-Codd Normal Form See BCNF

branch block, BTree index, 391 BTree (binary tree) indexes, 66–67, 385, 391, 405 budget/budgeting

accuracy, 254 described, 405 management, 255–256 project, overall, 223

buffering data into fast access memory See cache

building blocks, database modeling clusters, 70

constraints and validation, 47–48 datatypes, simple

numbers, 44–46 strings, 42–43 indexes alternate indexing, 65 Bitmap, 66–68 BTree, 66 building, 68–69 described, 64–65 foreign key indexing, 65–66 information, data and data integrity, 37 keys

described, 58 foreign, 60–61 primary, 59 unique, 59–60 normalization benefits, 49 described, 35, 48 potential hazards, 49 partitioning and parallel processing, 70 referential integrity, 63–64

sequences and auto counters, 70 tables

fields, 37–38 fields, columns and attributes, 40–42 records, 38–40

relationships, representing in ERDs, 49–58 views, 36, 69

business company objectives, 226–228 standard database model, 225 business processes

data warehouse modeling, 183 described, 405

explaining, 219–220 operations, 222 requirements analysis, 221 business rules

analysis data warehouse model, 248–252 described, 222

OLTP database model, 232–234

447

Trang 16

business rules (continued)

code, storing in database

described, 358–360

event triggers, 363

external procedures, 364

macro, 364

stored function, 362

stored procedure, 360–362

described, 354–355, 405

encoding

data warehouse database model, 374

OLTP database model, 373–374

field level

data warehouse database model,

370–373, 377–379

described, 364

OLTP database model, 364–370, 374–377

fields, explicitly declared, 357–358

normalization, normal forms,

and relations, 355–356

OLTP database model analysis

described, 232–233

one-to-many, 233–234

tables, online auction house sample, 262–265

relationship types, classifying, 356–357

table and relation level, 364

workplace database modeling, 24–27

C

C programming language, 47

cache

application, 211

defined, 405

OLTP databases, 212

calculations, complex, 354

candidate keys

BCNF

denormalization, 154–155

described, 81, 107, 108–111, 405

tables, 290–292

generally, 77–78, 405

Cartesian product, 138, 205

cascade

defined, 405

records, 64

update anomaly, 76

cascade delete described, 75–76, 405 referential integrity check, 269 categories

business rules, 234–237 company operations, 229–230 denormalizing, 298–299 functional, 14

hierarchy, 241, 245, 262 layers, 285–286 Central Processing Unit (CPU), 405 changes

INSERT, UPDATE, and DELETE commands, 144 removing latest unsaved (ROLLBACK command), 144–145

storing permanently (COMMIT command), 144–145 validation check, 48

changes, temporarily storing See transactions

check constraints, 357–358, 405 child tables

cascading records to, 64 foreign keys, 60, 64 hierarchical database model, 8 many-to-many relationships, network database model, 8–9

with optional parent tables, 273 class

defined, 165, 405 methods, encapsulating processing, 354 object versus, 165

relationships between, 166

classified ads for musicians See online

musicians sample client-server database model described, 15, 405–406 performance tuning, 195–196 scale, OLTP versus, 15 clumsy or inelegant solution, 222 clustering, computer, 400–401 clusters

denormalization, 162 described, 70, 406 indexes and, 393 performance tuning, 198 tables, 385

Codd, Dr E.F (inventor of relational database), 11

448

Ngày đăng: 03/07/2014, 01:20