You are on page 1of 212
THE MANGA GUIDE TO DATABASES MANA TAKAHASHI TRENP-PRO, CO., LTP. «EuuvsrRaree By: SHOKO AZUMA ¥ CONTENTS PREFACE ccc bcc ebb bebe e teense ee ix 1 WhRAT /5 A PATABASE? bccn. 1 Why Do We Need Databases? 00... beet eee 2 What's Up inthe Kingdom? ... 2020 ete 16 Data Is Duplicated... 2. eee eee eee 16 Data-Gan G6nfli@ties sc ena ae ese oe caw oe ea aie wa Sie BA SR WA GUE Os OE AE ROY BR DE BH 17 Data Is Difficult to Update... eect eens 18 A Database—That’s Our Solution. 0. 19 How to Use a Database .. 0. eee tenes 19 SUMMATY 20 bebe ee eee een 21 2 WAT /5 a RELATIONAL PaTABASE? on. 23 Database Terms «0... eee teen eet ees 24 Relational Databases ............. nee ebb eden e eee ees 34 Types of Data Models... eee ett eens 39 Data Extraction Operations: ws: sx cs 2m: oso we 2a em ee wate 2a Mee on Ge WE uw We BET GE RR We 39 SECOPERStIOTIS « eae ca ue eee FA eae EK ERE PU SURE 2 EEE gM Sa Um BE! EY Mae OR Beg Be DEY ae 39 Relational Operations 0.0... eet e eens 43 Questions 60. t bebe t ete ebb d bbb bb bbb bbb bbb enn es 45 The Relational Database Prevails! 0.0 ee J... AF SUMMATY 26 ee ene eee 48 ANSWOPS foms on ue ce eae ee ba Yow PE aoa rk GEN ees ee ee ee 48 3 LET'S DESIGN A PAaTABASE! 00 eee eee 49 The E-R Model. ebb bebe eee 50 Niotimializivig'al Table «ec x ver se cm as anime os cute om soy ou maw ae Gee ae GREW Ge aN aw Ha woe WR De 56 What Isttie EnR MGd6l?s ox vs ase ay wan wa arom iy be BE RR! AN He oT RET ON ON Ye BR Dee BH wee 74 How to Analyze the E-R Model... cc ett eens 74 Case 1: One-to-One Relationship... 0.2.0.0. eee 74 Case 2: One-to-Many Relationship ... 2.0.0.0... eee 75 Case 3: Many-to-Many Relationship ..... 2.200.000 00.0000 00 ccc ce eee 75 QUOStIONS eis x ay mee aes wesck Ss GUE vin UE tk WME SH GIR Bu WW AM Mic EH ke we AE OHS He RO HOY 76 Novrtiializitig a Table « vss 2% x wan aa pape ay ee 0% Sey US POIY BY sae BE eee BE ON A BE HEE SE wR EEG 78 Questions 0.0 ce te been bet e tebe enna 79 Steps for Designing a Database... eee 81 SUMMALY 0 bene need ecb beeen t bbe 81 AMSWETS 00 eee bbe bbe ee bb eve betes 82 4 LET'S LEARN ABOUT SQL! 85 MSU Dime 01: eye BE ew mp oe arse oes amie ack tsa HF sie win emi exe Kise au ON A UE doc ee AEN EE wR awe 86 Searching for Data Using a SELECT Statement..........................0-.00-0 2 93 Using Aggregate Functions... eevee ccc cee 98 Joining Tables. nev b bbb bee 101 Creating: Fables cas we ase assy sox we % ot Oa YA HOE Sle ace eames eqe mace exe ects ue ecu en ua en un ence un 103 SOL Overview. ccc 106 Searching for Data Using a SELECT Statement................... 0000-0 eee. 106 Creating Conditions... ebb cb eee 107 Comparison Operators oo. bbc c vec ec e 107 BSGICA! Grerabones o on wn 2 ca 22 wKOr wu HOT B% IBY BR Kic ma cca om ea o ce ace mam ec meme om emme 107 PACLERMS: «ax eevee sce drave ou SEN 2% CER OE Base ean aon wee eeein we qe w eon wn w uu een soney ey aomep cag vem 108 SHORPCDIER os wets 2 5% GE GEE ain wt & wen ect wen tox w voM go erate non ware Om Gut oH WHO Oe EY OY Bm 108 Questions 0 ebb bbe 109 Aggregate Functions. 0.0. 110 Aggregating Data by Grouping... 000 c cece cece eee. 110 CASTE! cn wa neon noe amon rk san SR RE HEN A Bi a aca ee exces me ~ me em emems ee eas ex qm om a 111 Searching 'for Datta. sess ex wos 95 je oa os 4 qe oct 4 wu um neue we anne vo moon wa auna wn tA uw Wav en 112 Using a Subquery. ccc bebe cece. dd2 Using a Correlated Subquery 20. e eee ee 113 Questions eee 114 Joining Tables nce 114 Creating BTADIG sox av auce aa ae 24 HR WEY OE BE Ek nee mo mee ue een 0 me om ume ee em wom eu we 115 Inserting, Updating, or Deleting Rows ...... 00.00 e ccc ee cee 116 Creating aVIEW. ecb bbe 117 Questions eo be 118 SUMMALY eee ce bbb bbb bby 119 ANSWETS eee ebb ebb 119 5 LET'S OPERATE A DataBase! 125 What Is a Transaction? cbc cece 126 What Is a Lock? oon b bocce 131 Database Security. bce eee 138 Speeding Things Up with Indexing... 0.0 c cece cece cee 143 Disaster Recovery...................... eee ee eee ebb ene, 148 Properties of Transactions 002.0. eevee cece. 153 Atomicity. cent bebe e ee 153 Consistency. eee o bbb 154 Isolation. ebb 155 Dery x cot sen w son oor rat #6 EH BY iow cor mseim om uaa oa um a un me com one om wo aunes ay mmeem 159 When Disaster Strikes 0c eve e ec 161 Types of Failures. ence cece 161 Checkpoints. cece ebb bbe yee 161 Questions bbc ccc 162 VI CONTENTS QUeStiIONS 0 eet ee eens bw A EE ae RE 164 Optimizing aQUGHys az wae on ew oe way me ae 7 Ow Sh Hoe BE ENEE SE GAS UR GUNA Se Ba Uo oe wa eo ON 7 164 Nested: LOOpic: ox wax xe wa @ ia OF SR BEE OG OR PON OF ON PU GES HA ORE SW A OS Be ne ee ee 165 Sort Merge 6 ebb bbb beet ete b beens 166 eS) ce 166 Optimizer. 6 eet teens 167 SUTAMIANY, soso on want wt oa aes a wee ot Gemee wo HEE a A) oa WANE WN ROY Ae FERN OW eeE @ OHE RL OWE em we 167 AWSWETS 2 eae un paw oe men Fa BS Glee ON GER GE CHOY oe Se oy Baw ae Ge wee PE Pe OM HORE ER Wa aN GR 167 6 PacaBasEes ARE EVERUWAERE/....0. eee ee 169 Databases in Use eet een es £75 Databases‘anid the Webi. ois es eee sa ens os cane pe Wee oe aw eu OS Me GS We BR SE Pd Ee eS we iv Distribtited Patabases! «ca» i seq ve se0 PS NEN UR Reo SS Be Oe PS BR BSS BR BE 183 Stored Procedures and Triggers... 2... cee 185 Databases on the Web... eee eens 194 Using Stored Procedures 0.0.0.6. eee 196 GIWESHOIS oc sues vet come ae ue 28 wee He GEE me OM TENE He GUY Ge ORE IE MERE Re Te ame ORE oe oe 196 What Is a Distributed Database? . 6... eee e eee A197 Horizontal Distribution » es say ee ge yee Hse EO OR OG RD OE RON ER WOR OR GREE a ee 197 Vertical Distribution ©... teen tenes 198 Partitioning Data... eee eee tees 198 Horizontal Partitioning... 0... eens 198 Vertical Partitioning ... 00.00. ee 199 Preventing Inconsistencies with a Two-Phase Commit ............0..0..020.0..0..00.. 199 QUESUIOTS 5 sa sex ss yeu oS PS ER ES EEE SH FOE SE WE A SU RR HO EE DR A eS 201 Database Replication... 00... ee tne ete teste tte n enn 201 Read-Only... beeen ebb b beet ened eee ees 201 Replication Enabled for All Servers... 200.0 eee ee 202 Further Application of Databases... 0. eee 202 AM Le cr wae ae oa © aw ow ie 4 SG AG RAEGY SR GEESE GH RAW GN Ha @ AY BH @ ate GA GORE BN Rue ae WoRne oa 202 Object-Oriented Databases... 0.0.0. cece beens 203 SUMMALY 2. eee b eee eee eee 205 ANISWETS 0 enn een deen ete eee eee 205 Closing Remarks. 22... eee eee tbe b tenets 205 APPENDIX FREQUENTLY YSED SQL STATEMENTS... en. 207 REFERENCES ett tenes 209 TOPE, ons ses ware cos coos oe ees we Gea Ge eae ot wa EO SE BA Sa a UE oH SE Ba ga oR GE 211 CONTENTS VII PREFACE Databases are a crucial part of nearly all computer-based business systems. Some read- ers of this book may be considering introducing databases into their routine work. Others may have to actually develop real database-based business systems. The database is the technology that supports these systems behind the scenes, and its true nature is difficult to understand. This book is designed so that readers will be able to learn the basics about databases through a manga story. At the end of each chapter, practice exercises are provided for con- firmation and expanding the knowledge you've obtained. Each chapter is designed so that Teaders can gain an understanding of database technology while confirming how much they understand the contents. The structure of this book ts as follows. Chapter 1 describes why we use databases. Why is a database necessary? What kind of difficulties will you have if you do not use a database? You will learn the background infor- Mation that using a database requires. Chapter 2 provides basic terminology. You'll learn about various database models and other terms relating to databases. Chapter 3 explains how to design a database, specifically, a relational database, the Most common kind. Chapter 4 covers SQL. a language used to manage relational databases. Using SQL allows you to easily manage your data. Chapter 5 explains the structure of the database system. Since a database is a system through which many people share data. you will learn how it can do so safely. Chapter 6 provides descriptions of database applications. You'll learn how Web-based and other types of database systems are used. This book was published thanks to the joint efforts of many people: Shoko Azuma for cartoons, TREND-PRO for production, and Ohmsha for planning, editing, and marketing. | extend my deep gratitude to all those concerned. | hope that this book is helpful to all readers. MANA TAKAHASHI aye oat A\ (ea shu TAA tT % En. Annet tt ai CATT TTT PRINCESS RURUNA! THE KINGDOM S OF KOD-— BUT, I JUST HAVE "THE COUNTRY Shes SO MUCH TO Do! OF FRUIT” : ( THIS YEAR'S HARVEST SHOULD BE BOUNTIFUL! YOU SHOULD BE PLEASED ABOUT THIS BUSY SEASON. I WISH I COULD HANDLE THINGS MUCH MORE EFFECTIVELY. YOU KNOW THAT OUR FRUIT RECORDS ARE MANAGED BY FILES CREATED BY... I'M SURE IT IS AN EXTREMELY EFFICIENT NOW, WORK, WORK!! THE MERCHANDISE DEPART- MENT, THE OVERSEAS BUSINESS DEPARTMENT, LA PEE DALA LA DEE PUM! AND THE EXPORT DEPARTMENT, DON'T YOU? I WONDER IF IT IS INEFFECTIVE TO MANAGE ALL THE DATA ON A DEPARTMENTAL BASIS. PRINCESS RURUNA!! IT WAS SUCH A HEAPACHE WHEN THE PRICE OF APPLES WENT UP THE OTHER > eR?! ae \ OH, IT’S YOU, CAIN. WHAT'S UP? I HAVE A PRESENT FROM THE IF MY PARENTS WERE STILL IN THE CASTLE, THIS WOULD NOT BE HAPPENING...! 1 | 1 "WE FOUND A BOOK ABOUT GROUNDBREAKING TECHNOLOGY INA FARAWAY LAN? WE VISITED. TS eet THE PERSON WHO GAVE US THIS BOOK TOLD US THAT THE BOOK DESCRIBES A SECRET TECHNOLOGY CALLED A PATABASE. WE HEAR THAT THE DATABASE IS A SYSTEM THAT ALLOWS EVERYONE TO SHARE, MANAGE, ANP USE DATA. BUT, HOW IT IS USED DEPENDS ON WHO READS THIS BOOK. THE PERSON GAVE THIS BOOK TO US BELIEVING THAT THE KINGDOM OF KOD WOULD USE IT INA PEACEFUL MANNER. OPEN THIS BOOK, ANP USE IT FOR | THE BETTERMENT \e OUR oe Dee IS THIS THE KEY FOR IT? AWIEEEL HY lll Z Hh Cf SS (elles) OH, PLEASE! YOU DON’T O22 KNOW ANYTHING ABOUT Es HOW STRESSED OUT 1 AM ro FEELING! 7 yA l fh} ii Uf ce { y. y ANN We \ a a f vs -y 2 8 | A GHOST IN THE K... K...KOD CASTLE. I’M CAINI-THE CLOSE AIDE OF PRINCESS RURUNA OF KOD. i! HOW RUDE! I'M TICO, BUT ONLY THE PEOPLE WHO OPENED THE BOOK CAN SEE ME, THIS BOOK HAS SUPERNATURAL POWERS TO HELP THE PEOPLE WHO OPENED IT USE THE KNOWLEDGE... SO... YOU'RE GOING TO HELP US? WHAT IS A DATABASE? 4 WELL, SHE SEEMS HARMLESS SO FAR... ENOUGH ABOUT ME! YOU TWO OPENED THE BOOK fe | TO LEARN ABOUT DATABASES... | Of OKAY THEN, “Zr BW! (ak Fy LET'S V\ TO CREATE A DATABASE... THIS IS A VERY ELEMENTARY QUESTION... Nc} ese BUT WHAT IS A ee OLE DATABASE? DON’T KNOW I AM MANAGING e VALUES ANP WHAT IT |S. NUMBERS CUSTOMERS, YOU ARE HANPLING RELATED TO AND SALES VARIOUS VALUES PRODUCTS, eee AND NUMBERS, Biles ON A | AREN'T YOU? DEPARTMENTAL 5, AN Hee ane OH, SO YOU'RE \ PROBLEMS... MANAGING DATA IN AN UNCOORDINATED FASHION, BY DEPARTMENT. THAT MEANS DATA IS DUPLICATED IN EACH DEPARTMENT, RIGHT? OVERSEAS BUSINESS DEPT. GOLD (@) IS THE CURRENCY UNIT USED IN THE KINGDOM OF KOD, KOLONE SAYS, (ee pays "IT 1S AN . = EFFICIENT © 4 p) a 7h fii *® ANP EACH DEPARTMENT HAS SEPARATE DATA. SOMETIMES IT CAN CREATE Aj _ PROBLEMS. hee e PNG JUST LIKE THAT CRISIS THE OTHER DAY! WHAT IS A DATABASE? 11 YES, WHEN THE PRICE OF APPLES WENT UP. I SENT A MESSAGE TO EACH DEPARTMENT TO CHANGE THE PRICE TO 1206, 1Z CHAPTER 1 RAISE THE PRICE TO 1Z06! THE PRICE OF APPLES, WHICH HAP BEEN 1006, WENT UP TO 1Z0G, AS I REMEMBER. ONE DEPARTMENT FORGOT TO CHANGE THE PRICE. I DIPN’T GET YOUR MESSAGE... | OVERSEAS : op BUSINESS Soe re APPLE 1006 PRICE REMAINS THE SAME! NOT ONLY THAT... ANOTHER DEPARTMENT CHANGED THE PRICE TO 3006 BY MISTAKE. APPLE: 1206 APPLE: 1006 APPLE: 3006 ah SOMETHING'S J WRONG! LLL MERCHANDISE OVERSEAS EXPORT DEPT. BUSINESS DEPT. DEPT, IT WAS PARTICULARLY HARP FOR CAIN! HE HAD TO RUN AROUND THE KINGDOM... THE DATA IN RESPECTIVE DEPARTMENTS CONFLICTS, DOESN'T IT? ANP CORRECT ALL THE ERRORS. THE PRICE OF WW, APPLES IS NOT CORRECT... FIX THE Price, | PLEASE! WHAT IS A DATABASE? 13 MY FATHER SAID, “LET'S START A FRUIT-PICKING TOUR SOMETIME IN THE FUTURE!” BUT I FEEL WE ARE FAK FROM READY. HE IS ‘i AA | , FREE AND wi LET'S START A NEW EASYGOING, | BUSINESS USING THE Wf : EXISTING SYSTEM. HA~HA-HA! 30...MY OFFICIAL EVEN IF WE DO START A NEW BUSINESS, IT SEEMS LIKE IT WILL BE DUTIES WILL NOT BE REDUCED IN IMPOSSIBLE TO USE THE THE SLIGHTEST! 4 DATA STORED IN THE 4 CURRENT SYSTEM, oe _ oo CALM 2 POWN, THE PATA j PLEASE! WOULD BE 2 JUMBLEP UP.. / YOU WILL BE TORMENTED BY DATA MANAGEMENT EVEN IF YOU PO YOUR BEST, WON'T YOUP WELL, IT SOUNDS LIKE YOU HAVE TO MAKE ENTRIES AND CONFIRMATIONS EACH TIME ANYTHING CHANGES, ANP IT SEEMS TO BE A TOUGH JOB. IF YOU START A NEW BUSINESS, YOU WILL HAVE TO CREATE NEW FILES FOR THE NEW DEPARTMENT. 2 es Ege | DOCUMENTS 14 CHAPTER 1 A SYSTEM IN WHICH DATA IS SHARED BY EVERYONE IS CALLED A PATABASE. IF YOU USED ONE, YOU WOULD NOT HAVE TO KEEP USELESS DATA. YOU MEAN WE CAN HAVE A MUCH MORE EFFICIENT SYSTEM THAN THE CURRENT ONE? IT SOUNDS LIKE IT IS WORTH STUDYING, DOESN'T ITP Ali: I DO NOT HAVE A I WILL TEACH YOU / REAL WORLD. PHYSICAL BODY, EVERYTHING. BUT | FOR ME AND SO I CAN'T USE YOU MUST DO YOUR (<7 \ MY COUNTRY... COMPUTERS IN THE BEST! A> BUT IN GRATITUPE FOR BRINGING ME OUT OF THE BOOK... Whavct’s LP I) THE KINGDOM? 1@ CHAPTER 1 The Kingdom of Kod currently uses a file-based system to manage its data. But it seems that the current system has a few problems. What are they, in particular? Let's look at the system in detail. The Kingdom currently has three departments: the Merchandise Department, the Overseas Business Department, and the Export Department. The Merchandise Department keeps track of all fruit produced in the country, the Overseas Business Department manages the foreign countries that are the Kingdom's business partners, and the Export Department keeps records of the amount of fruit the Kingdom exports. OVERSEAS BUSINESS DEPARTMENT MERCHANDISE DEPARTMENT EXPORT DEPARTMENT LO of DATA IS DUPLICATED Princess Ruruna isn't satisfied with the current system. But why not? Each department in the Kingdom manages data independently. For example. the Merchandise Department and the Export Department each create files to manage fruit data. Therefore, data is dupli- cated needlessly across the departments. Each department must enter the data, store the data, then print receipts for confirmation, all of which is a waste. In addition, data trapped in one particular department is never shared effectively with the other departments. PRINCESS Data is duplicated. RURUNA OVERSEAS BUSINESS DEPT. But that's not all. The system also creates prohlems when someone needs to change the data, For example, let's assurne that the price of apples. changes. To deal with this. Prin- cess Ruruna must notify every department individually that the price of apples has changed. Isn't that inconvenient? PRINCESS RURUNA The Princess must send a message to each department. OVERSEAS BUSINESS DEFT. MERCHANDISE DEPT. EXPORT DEPT. DATA CAN CONFLICT It may seem easy enough to notify each department that the price of apples has changed, but it can create a new set of problems. Let's say that Princess Ruruna does notify the three departments that the price of apples has changed. However, the Overseas. Business Depart- ment may forget to change the price, or the Export Department might change the price to 3006 instead of 120G. These kinds of errors result in conflicting data between departments, which causes the content of the file systems to differ from the conditions of the real world. What a pain! CHANGE THE PRICE OF APPLES FROM 100 TO 1206. PRINCESS RURUNA Unit. price WHAT IS A DATABASE? 17 18 CHAPTER 1 DATA IS DIFFICULT TO UPDATE The current system not only creates conflicting data, but it alsa makes it difficult to respond to changes in business. For example, let's say that the King wants to launch a new Tourism Department. When a tour guide conducts a tour of the orchards and discusses the King- dom’s fruit sales, the guide will want to use the most up-to-date sales figures. But, unfortunately, the current system does not necessarily allaw the departments to access each other's data, since the files are kept independently. Ta manage a new tourism business, Princess Ruruna will have to make copies of all the relevant files for the Tourism Department! 6 fe, TOURISM DEPARTMENT MERCHANDISE DEPARTMENT EXPORT PEPARTMENT New files must be created. FILE FOR MERCHANPISE DEPT. FILE FOR TOURISM DEPT. Product name 8005 1506 Strawberry This, in turn, increases the amount of duplicated data created when a new department starts. Considering these weaknesses, the current system is not efficient. It makes it difficult to start new projects and respond to environmental changes. A DacaBaséE—Tnact’s OUR SOLUTIONS Well, why is this system so Inefficient? The problems all stem from separate and indepen- dent data management. What should Ruruna and Cain do? That's right—they should create a database! They must unify the management of data for the entire Kingdom. | will show you how to do this in the next chapter. DATABASE MERCHANDISE GUSINESS DEPT. DEPT. uF ) aE.5) Uniform data management ensures that each department has the correct information, because each department sends a query to a single source of data. What an efficient system it is! It prevents data conflicts, and it also eliminates duplicated data, allowing for easy mtro- duction and integration of new departments. Data is accessible to everyone, HOW TO USE A DATABASE To introduce and operate a database, you must understand its unique challenges. First, the database will be used by many people, so you'll need a way for them to easily Input and extract data. It needs to be a method that is easy for everybody to use. PRINCESS RURUNA WHAT |S THE PRICE OF APPLES IN GP? WHAT WAS THE SALES VOLUME ON MARCH SP DATABASE MERCHANDISE vee DEPT. DEPT, ue LS) b The new system also presents some risks—for example, it may make it possible for users to steal or overwrite important information like salary data, which is confidential and should be protected by an access restriction. Or, for example, only the Export Depart- ment should have access to sales data, Setting up database security and permissions is important when designing a system. WHAT IS A DATABASE? 14 PRINCESS RURUNA I CAN'T ACCESS SALES DATABASE I CAN DATA. ACCESS SALES DATA. o OVERSEAS EXPORT DEPT. The new system can have other problems. too. The database can be used by many people at one time, Assure that sameone in the Overseas Business Department and some- one in the Export Department both try to change the name of a fruit at the same time—the former. fram Apple to AP. and the latter, fram Apple to APL. If they do this. what will happen to the product name? For a database that will be used by many people, this kind of problem must be considered, PRINCESS RURUNA VA aS ta MERCHANDISE ba\ eee. DEPT. DEPT. wy eo You also need to be careful not to lose any data. Furthermore, the system may go down or a hard disk could fail, causing data to be corrupted. The database must have mechanisms to recaver from these common kinds of failures, Wa We must prepare for failures. ZO CHAPTER | 2 What IS a RELATIONAL DataBase? | | | | tt ke joe b o A a RE a LHe ao DataBase TERMS . L & ) , ) RURUNA, MY 1X Se | . ty i L i TAKE THESE W XY Ni \]\ FLOWERS... j BOTH MY FATHER AND S =~ MOTHER ARE AWAY anny : NO, CAIN ie) FROM THE CASTLE, AA IS HERE SO IM VERY BUSY! | WITH ME. I THOUGHT YOU'D BE LONELY. THAT'S WHY I AM HERE, YOU CAN’T PRINCE MEAN YOUR AIDE IS MORE PEPENPABLE THAN A PRINCE! RAMINESS! TAH YOU PROMISED TO GO OUT ON HE IS SO ANNOYING. AW Flowers? lt }/ BUT RAMINESS IS ggg THE PRINCE OF a ae THE NEIGHBORING . 1 COUNTRY. YOU SHOULDN'T TREAT HIM SO LIGHTLY. IT’S NOT A GOOP GEE! HOW LONG MORNING AT ALL. HAVE YOU BEEN YOU ARE SO CAREFREE. eee a THERE? SINCE YOU TIME. ~ OPENED THE bo BOOK ALITTLE WHILE AGO. HELLO! GW BUT THAT'S OKAY. ANYWAY, RAMINESS LEFT. LET'S START TO DESIGN A DATABASE. YOU CAN'T DESIGN A ceo PATABASE WITHOUT FOUNDATION ANY KNOWLEPGE, iS IMPORTANT. FIRST OF ALL, LET'S LEAKN DATABASE TERMS. 26 CHAPTER 2 N...NO, y NOTHING... 5 WHAT DID YOU SAYP SHE WENT INTO I THE LAPTOP! a, THIS IS ONE OF THE FILES YOU ARE USING. 4 ONE PRODUCT IS ONE RECORD, RIGHT? THEN THE PRODUCT COPE, PROPUCT NAME, UNIT PRICE, ANP REMARKS ARE FIELDS, CORRECT? ANP EACH ITEM IN THE RECORD IS CALLED A FIELP. WHAT IS A RELATIONAL DATABASE? 27 EACH RECORD CONTAINS FIELDS OF THE SAME TYPE. | 06 _nwwsinpmenintiheen ned tee pee [we | [Eas SS | 1o4 hemon [2008 FOR EXAMPLE, FPROPUCT CODE IS A THREE-DIGIT THEN, NEXT, LET'S THINK ABOUT THE PRODUCT CODE IN ALITTLE MORE OO AND FROPUCT NAME IS TEN CHARACTERS OR LESS. 28 CHAPTER Z NO TWO AND THERE ARE NO PRODUCT " DUPLICATED RECORDS. CODES ARE 4) | if 50, IF YOU KNOW THE THE SAME. Kod, a) | PRODUCT CODE |S 101, (ee Sg aie ae i Ne » YOU CAN IDENTIFY IT AS MELON. BUT IN THE CASE OF UNIT PRICE... YOU WILL NOT KNOW WHETHER IT INDICATES LEMON OR KIWI. OH, I FOUNP THE SAME NUMBER. EVEN IF YOU KNOW A FRUIT'S PRICE IS ZOOG... WHAT IS A RELATIONAL DATABASE? 24 SO WE CAN IPENTIFY DATA WITH ITS PROBUCT CODE, BUT NOT WITH ITS UNIT PRICE. IS CALLED UNIQUE. UNIQUE? OTHER PEOPLE OFTEN SAY THAT ABOUT MY FATHER... IN THE DATABASE WORLD, SUCH A IT MEANS THE THEN, NEXT, LET'S ONE ANP ONLY. THINK ABOUT REMARKS, IT HAS A SPECIFIC MEANING, YOU KNOW. REMARKS ARE REMARKS, AREN'T SOME VALUES UNDER REMARKS HAVE NO ENTRIES, RIGHT? TAKE A LOOK FROM THE POINT OF VIEW OF A DATABASE. THIS DOES NOT IF THAT'S SO, YOU MEAN THAT A SPACE CAN'T IDENTIFY THE REMARKS IS ENTERED... PRODUCT EVEN IF REMARKS | YOU LOOK AT THE fF IT IS TRULY EMPTY. WITH BUR a THE ABSENCE OF A VALUE PROPUCT ; IS CALLEP A NULZ IN THE CODE aA DATABASE WORLD. RS CHESTNUT . ANULL 1S ACCEPTABLE FOR EHEC Ne REMARKS, BUT NOT FOR co PRODUCT CODE, WHICH 301 , Ae IDENTIFIES DATA. ‘ : bs, NULL? t : yA 4 EMPTY? PATABASE TERMS. PO YOU UNDERSTAND? WHAT IS A RELATIONAL DATABASE? 3° , Fle TAY BUT, IF YOU CONTINUE | Ae xe” ay USING THE CURRENT Le INDEPENDENT FILES, i THAT'S WHY I WANT TO THERE ARE ALL KINDS | CREATE A DATABASE. OF PROBLEMS YOU : CAN'T SOLVE. THIS 15 A HIERARCHICAL DATA MODEL, IN WHICH WHEN YOU SAY PATABASE, YOU MUST UNDERSTAND THAT THERE ’ Sen sear sand oe abe THERE |S A TREE-LIKE DATABASES. es RELATIONSHIP BETWEEN ~ Vee LIKE 3Z CHAPTER Z NEXT IS THE NETWORK DATA MOVPEL, IN WHICH PIECES OF DATA HAVE OVERLAPPING RELATIONSHIPS WITH EACH OTHER. MERAR CH CAL 2ATA MODEL ARE YOU NOT f I’M READY FOR ASTONIGHEP AT ANYTHING! ALL, CAIN? THEN, ARE WE GOING TO USE ONE OF THEM? AS A MATTER OF FACT, ANOTHER KIND IS MUCH EASIER TO USE THAN THESE SCARED, WEREN'T NO, NOT YOU? AT ALL. A RELATIONAL DATA MOPEL. WHAT IS A RELATIONAL PATABASE? 33 RELATIONAL DaATABasEs THE RELATIONAL DATA MODEL |S BASED ON A TWO-DIMENSIONAL TABLE. pata | DATA DATA pata | DATA BI SO Af aif LQ R aa fet ’ / f i i a a we BOWNY “ 9 OO oe OO" SOMETHING APPEARED AGAIN. | IN THE RELATIONAL DATA MODEL, A TABLE IS ALGO CALLED A RELATION. IT SEEMS THAT PATA SUCH AS PRODUCTS IS EASY TO TABULATE.... ONE PIECE OF DATA OR RECORD |S CALLED A AND EACH DATA ITEM OR FIELP IS CALLED A COLUMN. ANOTHER NEW WORD! 34 CHAPTER 2 IN APPITION, IMPORTANT A FIELD IS SOMETIMES GIVEN AN IMPORTANT ROLE IN THE DATABASE. YES. FOR EXAMPLE, THE PRODUCT CODE IN THE FILE YOU SAW A LITTLE WHILE AGO. THIS SPECIAL FIELD IS CALLED A KE”. WELL, I’M FAMILIAR WITH TABLES. THE FIELD SERVES AN IMPORTANT ROLE: TO IDENTIFY DATA. TT |S BASY TO UNPERSTANP IF YOU CAN PROCESS DATA { USING A ~ THIS COPE IS CALLED A PRIMARY KEY. THIS 1S ONE MERIT OF THE RELATIONAL DATA MODEL. EVEN PEOPLE WHO DO NOT KNOW MUCH ABOUT PATABASES CAN PROCESS DATA. I DIDN’T KNOW THERE WERE SO MANY TERMS. WHAT IS A RELATIONAL DATABASE? 35 AS I SUSPECTED, ER...MATH? THIS IS IN ADDITION, THE DIFFICULT... RELATIONAL DATA MODEL IS DESIGNED SO THAT YOU CAN PROCESS DATA WITH MATHEMATICAL OPERATIONS. FOR INSTANCE, LET'S LOOK BACK AT THE PROPUCT TABLE. YOU CAN EXTRACT THE AN OPERATION PRODUCT NAME? enh COLUMN LIKE THIS IS CALLED PROJECTION. 3G CHAPTER 2 PROPUCT NAME CHESTNUT PEACH KIWI 50 EXTRACTING THE PRODUCT NAME IS AN OPERATION? THERE ARE MANY OTHER OPERATIONS. IN FACT, THERE ARE aE CARTESIAN ANOTHER MERIT OF THE RELATIONAL PATA MODEL IS THAT YOU CAN PROCESS DATA BY... COMBINING THESE OPERATIONS. WHAT IS A RELATIONAL DATABASE? 37

You might also like