×
Push yourself because, no one else is going to do it for you.
--Your friends at LectureNotes
Close

Note for Database Management System - DBMS By Panda Surya

  • Database Management System - DBMS
  • Note
  • 7 Views
  • Uploaded 11 months ago
0 User(s)
Download PDFOrder Printed Copy

Share it with your friends

Leave your Comments

Text from page-2

These problems can be decreased by normalizing our data – in other words, dividing the information into multiple tables with the goal of having “a place for everything, and everything in its place.” Each piece of information should appear just once, simplifying data maintenance and decreasing the storage space required. PATRONS TABLE First Name Bob Alicia Zayn Last Name Smith Petersohn Murray Address 123 Main St. 136 Oak St. 248 Pine Dr. Phone 555-1212 555-1234 555-1248 CHECKOUT TABLE Book Title Don Quixote Three Men in a Boat Things Fall Apart Anna Karenina Heidi The Old Man and the Sea Due Date 7-14-09 7-16-09 8-15-09 8-15-09 8-17-09 9-10-09 Now that the data are arranged efficiently, we need a way to show which records in the PATRONS table correspond to which records in the CHECKOUT table – in other words, who checked out which book. Instead of repeating everything we know about a patron whenever he checks out a book, we will instead give each library patron an ID, and repeat only the ID whenever we want to associate that person with a record in a different table. PATRONS TABLE Patron ID 1 2 3 First Name Bob Alicia Zayn Last Name Smith Petersohn Murray Address 123 Main St. 136 Oak St. 248 Pine Dr. Phone 555-1212 555-1234 555-1248 CHECKOUT TABLE Patron ID 1 2 1 1 3 1 Book Title Don Quixote Three Men in a Boat Things Fall Apart Anna Karenina Heidi The Old Man and the Sea 2 Due Date 7-14-09 7-16-09 8-15-09 8-15-09 8-17-09 9-10-09

Text from page-3

Now the PATRONS and CHECKOUT tables can be related (how relationships are formally declared in various database software is beyond the scope of this paper). At this point, we need some new terms to talk about our related tables. The primary key is a field whose values are unique in this table, and so can be used as identifiers for the records (multi-field or composite primary keys are beyond the scope of this paper, and are unlikely in an ArcGIS geodatabase). In table PATRONS, the Patron ID field is the primary key and so its values must remain unique. For example, the value “2” can appear only on one record - Alicia’s - and Alicia can have only one Patron ID - “2.” Is the Patron ID field in table CHECKOUT the primary key? We can see that it contains duplicate values, so the answer is No. If Patron ID were the primary key for CHECKOUT, each person would only be permitted to check out one book, and afterward would be forbidden to check out any more books, ever. So if Patron ID is not the primary key for table CHECKOUT, which field is? We can’t make Book Title the primary key, or we’d have a similar problem – each book could only be checked out once, and afterward no one would be permitted to check it out ever again. We can’t make Due Date the primary key, or else only one book could be due each day. Since none of the existing fields works as a primary key, we will add a new field to hold an identifier for each record. We could name this field Checkout ID, or we could follow ESRI’s convention of giving all primary key fields exactly the same name: ObjectID. PATRONS TABLE ObjectID 1 2 3 First Name Bob Alicia Zayn Last Name Smith Petersohn Murray Address 123 Main St. 136 Oak St. 248 Pine Dr. Phone 555-1212 555-1234 555-1248 CHECKOUT TABLE ObjectID 1 2 3 4 5 6 Patron ObjectID 1 2 1 1 3 1 3 Book Title Don Quixote Three Men in a Boat Things Fall Apart Anna Karenina Heidi The Old Man and the Sea Due Date 7-14-09 7-16-09 8-15-09 8-15-09 8-17-09 9-10-09

Text from page-4

Naming every primary key field “ObjectID” does make it easy to tell at a glance which field uniquely identifies the records in this table. We can also use this naming convention to provide hints about which fields are related. For example, Patron ObjectID in CHECKOUT is related to ObjectID in PATRONS. To further increase efficiency, decrease required space, and improve ease of maintenance, we can separate the book information into its own table. PATRONS TABLE ObjectID 1 2 3 First Name Bob Alicia Zayn Last Name Smith Petersohn Murray Address 123 Main St. 136 Oak St. 248 Pine Dr. Phone 555-1212 555-1234 555-1248 CHECKOUT TABLE ObjectID 1 2 3 4 5 6 Patron ObjectID 1 2 1 1 3 1 Book ObjectID 1 6 3 5 2 4 Due Date 7-14-09 7-16-09 8-15-09 8-15-09 8-17-09 9-10-09 BOOKS TABLE ObjectID 1 2 3 4 5 6 Title Don Quixote Heidi Things Fall Apart The Old Man and the Sea Anna Karenina Three Men in a Boat Author Miguel Cervantes Johanna Spyri Chinua Achebe Earnest Hemingway Leo Tolstoy Jerome K. Jerome Year 1605 1880 1958 1952 1873 1889 Now ObjectID in BOOKS is related to Book ObjectID in CHECKOUT. When two tables have an unequal relationship, we call the independent table the parent and the dependent table the child. You can identify the parent table by determining which table could contain a record without needing a corresponding record in the table on the other side of the relationship. For example, is it possible to have an unpopular library book which never gets checked out? Yes. Is it possible to check out a book that doesn’t exist? No. Since BOOKS can contain 4

Text from page-5

records that aren’t referenced by CHECKOUT, BOOKS is the parent in this relationship, and CHECKOUT is the child. If somehow the child table contains a record that does not have a corresponding record in the parent table, that record is called an orphan. Orphaned records are a problem that generally requires attention from the database administrator. Another way to identify the child table is to find the field which refers to the other table’s ObjectID. BOOKS does not contain an ObjectID field for the CHECKOUTS, but CHECKOUTS does contain a field to store Book ObjectIDs. Therefore, CHECKOUTS is the child table in this relationship. The last new concept to consider is cardinality, which describes how many records in one table can be related to records in another table. Two tables might have a cardinality of 1-1 (one to one), 1- ! (one to many), 1-3 (one to three), ! - ! (many to many), etc. The PATRONS – CHECKOUT relationship has a 1- ! cardinality, because 1 patron may have any number of checkouts, from zero to infinity. Put another way, the CHECKOUT – PATRONS relationship has a cardinality of ! - 1. If the cardinality of PATRONS – CHECKOUT were 1-1, then each patron could check out only one book. If it were ! - !, then several patrons together might share joint responsibility for one or more checkouts. The BOOKS – CHECKOUT relationship is also 1 - !, since one book may be checked out multiple times. If we really were designing the data model (tables, fields, relationships, etc.) for a library, we would continue by separating even more data (such as the authors) into other tables until the model was as efficient as possible. Since we are modeling utility data instead, let’s see how these ideas apply to meters and service points: SERVICE POINT TABLE ObjectID Shape Type 1 2 3 <Shape> <Shape> <Shape> Single Residence Multi-family Single Residence METER TABLE ObjectID 1 2 3 4 5 6 Address 123 Main St. 136 Oak St. #3 136 Oak St. #4 248 Pine Dr. 136 Oak St. #2 136 Oak St. #1 Service Point Object ID 1 2 2 3 2 2 5 Status Active Active Inactive Active Active Active Installation Date 2-4-1974 3-1-1980 2-12-1998

Lecture Notes