Transcription of Object-Based Databases
1 C H A P T E R22 Object-Based DatabasesPractice car-rental company maintains a database for all vehicles in its cur-rent fleet. For all vehicles, it includes the vehicle identification number,license number, manufacturer, model, date of purchase, andcolor. Spe-cial data are included for certain types of vehicles: Trucks: cargo capacity. Sports cars: horsepower, renter age requirement. Vans: number of passengers. Off-road vehicles: ground clearance, drivetrain (four- ortwo-wheeldrive).Construct anSQLschema definition for this database. Use inheritancewhere :For this problem, we use table inheritance. We assume thatMyDate,ColorandDriveTrainTypeare pre-defined typeVehicle(vehicleidinteger,licensenumb erchar(15),manufacturerchar(30),modelcha r(30),purchasedateMyDate,colorColor)crea te tablevehicleof typeVehiclecreate tabletruck(cargocapacityinteger)underveh iclecreate tablesportsCar12 Chapter 22 Object-Based Databases (horsepowerintegerrenteragerequ irementinteger)undervehiclecreate tablevan(numpassengersinteger)undervehic lecreate tableoffRoadVehicle(groundclearancereald riveTrainDriveTrainType) a database schema with a relationEmpwhose attributes areas shown below, with types specified for multivalued = (ename, ChildrenSetmultiset(Children))
2 , SkillSetmultiset(Skills))Children = (name, birthday)Skills = (type, ExamSetsetof(Exams))Exams = (year, city)a. Define the above schema inSQL, with appropriate types for Using the above schema, write the following queries Find the names of all employees who have a child born on orafter January 1, Find those employees who took an examination for the skilltype typing in the city Dayton .iii. List all skill types in the :a. No Queries Program:selectenamefromempase, March in( )ii. Program:Practice , , typing Dayton iii. Program:select , theE-Rdiagram in Figure , which contains composite,multivalued, and derived Give anSQLschema definition corresponding to Give constructors for each of the structured types :a.
3 The correspondingSQL:1999schema definition is given that the derived attributeagehas been translated into typeName(firstnamevarchar(15),middleinit ialchar,lastnamevarchar(15))create typeStreet(streetnamevarchar(15),streetn umbervarchar(4),apartmentnumbervarchar(7 ))create typeAddress(street Street,cityvarchar(15),statevarchar(15), zipcodechar(6))create tablecustomer(name Name,customeridvarchar(10),address Adress,phoneschar(7) array[10],dob date)method integerage() functionName(fvarchar(15),mchar,lvarchar (15))returnsNamebeginsetfirstname=f;setm iddleinitial=m;setlastname=l;endcreate functionStreet(snamevarchar(15),snovarch ar(4),anovarchar(7))4 Chapter 22 Object-Based DatabasesreturnsStreetbeginsetstreetname =sname;setstreetnumber=sno;setapartmentn umber=ano;endcreate functionAddress(s Street,cvarchar(15),stavarchar(15),zipva rchar(6))returnsAddressbeginsetstreet=s; setcity=c;setstate=sta;setzipcode=zip; the relational schema shown in Figure Give a schema definition inSQLcorresponding to the relationalschema, but using references to express foreign-key Write each of the queries given in Exercise on the aboveschema, :a.
4 The schema definition is given below. Note that backward ref-erences can be addedbut they are not so important as inOODBS because queries can be written inSQLand joins can take care ofintegrity typeEmployee(personnamevarchar(30),stree tvarchar(15),cityvarchar(15))create typeCompany(companynamevarchar(15),(city varchar(15))create tableemployeeofEmployeecreate tablecompanyofCompanycreate typeWorks(personref(Employee)scopeemploy ee,compref(Company)scopecompany,salaryin t)create tableworksofWorkscreate typeManages(personref(Employee)scopeempl oyee,(managerref(Employee)scopeemployee) create tablemanagesofManagesb. >namePractice Exercises5fromworksgroup bycomphaving count(person) all(select count(person)fromworksgroup bycomp) >namefromworksgroup bycomphaving sum(salary) all(select sum(salary)fromworksgroup bycomp) >namefromworksgroup bycomphaving avg(salary)>(select avg(salary)fromworkswherecomp >companyname="First Bank Corporation") that you have been hired as a consultant to choose a databasesystem for your client s application.))
5 For each of the following appli-cations, state what type of database system (relational, persistent pro-gramming language basedOODB, object relational; do not specify acommercial product) you would recommend. Justify your A computer-aided design system for a manufacturer of A system to track contributions made to candidates for An information system to support the making of :a. A computer-aided design system for a manufacturer of airplanes:AnOODB system would be suitable for this. That is becauseCADrequires complex data types, and being computation oriented,CADtools are typically used in a programming language envi-ronment needing to access the A system to track contributions made to candidates for publicoffice:A relational system would be apt for this, as data types are ex-pected to be simple, and a powerful querying mechanism is An information system to support the making of movies:Here there will be extensive use of multimedia and other complexdata types.
6 But queries are probably simple, and thus an objectrelational system is 22 Object-Based does the concept of an object in the object-oriented model differfrom the concept of an entity in the entity-relationship model?Answer:An entity is simply a collection of variables or data object is an encapsulation of data as well as the methods (code) tooperate on the data. The data members of an object are directly visibleonly to its methods. The outside world can gain access to the object sdata only by passing pre-defined messages to it, and these messagesare implemented by the methods.