Danh mục

Beginning Database Design- P21

Số trang: 20      Loại file: pdf      Dung lượng: 593.11 KB      Lượt xem: 11      Lượt tải: 0    
Jamona

Xem trước 2 trang đầu tiên của tài liệu này:

Thông tin tài liệu:

Beginning Database Design- P21:This book focuses on the relational database model from a beginning perspective. The title is, therefore,Beginning Database Design. A database is a repository for data. In other words, you can store lots of informationin a database. A relational database is a special type of database using structures called tables.Tables are linked together using what are called relationships. You can build tables with relationshipsbetween those tables, not only to organize your data, but also to allow later retrieval of information fromthe database....
Nội dung trích xuất từ tài liệu:
Beginning Database Design- P21 Business Rules and Field Settings LISTING_NUMBER_OF_BIDS INTEGER FORMAT “999” NULL, LISTING_WINNING_PRICE MONEY NULL, LISTING_BID_INCREMENT MONEY NULL, BID_PRICE MONEY NULL ); The LISTING_NUMBER_OF_BIDS is output formatted as for number of bids in the OLTP database model LISTING table.Encoding Business Rules As with the previous section covering individual field business rules, this section covers the case study online auction house database models, but this time attempting to encode a few things into a pseudo database programming language. The intention here is to demonstrate what can be done. It is a matter for some debate among computer professionals as to whether business rules should be written into stored procedures. Some think implementing business rules in stored procedures is good for some rea- sons. Others consider that applications handle this type of complexity more effectively and efficiently.Encoding Business Rules for the OLTP Database Model You already know the difference between a stored procedure, a stored function, and an event-based trig- ger. What can be done to the OLTP database model for this case study, to utilize some type of database stored coding? The BID table is a good candidate for some basic stored functions: CREATE TABLE BID ( LISTING# CHAR(10) NOT NULL, BUYER_ID INTEGER FOREIGN KEY REFERENCES BUYER NOT NULL, BID_PRICE MONEY CHECK(VERIFY_BID(LISTING#, BID_PRICE)) NOT NULL, PROXY_BID MONEY CHECK(PROXY_BID > BID_PRICE AND VERIFY_BID(LISTING#, PROXY_BID)) NULL, BID_DATE DATE FORMAT “DD MON, YEAR” NOT NULL, CONSTRAINT PRIMARY KEY (LISTING#, BUYER_ID) ); The preceding script has a CHECK constraint on the BID_PRICE and PROXY_BID fields. Both of these CHECK constraints execute a function. A bid price is entered by a bidder. That bid price must exceed the starting and current prices, both of which are stored in the listing table. This can be encoded using a stored function as follows: CREATE FUNCTION VERIFY_BID(LISTNUM CHAR(10), BID MONEY DEFAULT NULL) RETURN BOOLEAN DECLARE START_PRICE MONEY; 373Chapter 12 CURR_PRICE MONEY; BEGIN REMARK --- Throw out bids that are incorrectly passed in IF LISTING# IS NULL OR BID IS NULL OR BID Business Rules and Field Settings Venue venue_id Instrument instrument_id Show location Genre show_id address_line_1 section_id (FK) genre_id address_line_2 instrument band_id (FK) parent_id (FK) town venue_id (FK) genre date zip time postal_code country directions phone Musician musician_id Band instrument_id (FK) band_id Merchandise band_id (FK) merchandise_id genre_id (FK) musician band band_id (FK) phone founding_date type email price skills Advertisement advertisement_id band_id (FK) musician_id (FK) date Discography text discography_id band_id (FK) cd_name release_date price Figure 12-8: Musicians, bands, online advertisements OLTP database model.How It Works There are no appropriate CHECK constraints and no appropriate stored encoding. This script contains appropriate changes: CREATE TABLE INSTRUMENT ( INSTRUMENT_ID INTEGER PRIMARY KEY NOT NULL, ...

Tài liệu được xem nhiều:

Tài liệu cùng danh mục:

Tài liệu mới: