imt 37 oracle

73
Subject Code: IMT-37 Subject Name : DBMS (ORACLE) ASSIGNMENTS PART– A Q1. a. Describe what metadata are and what value they provide to the databa se system. b. What are the advantages of having the DBMS between the end user’s ap plications and the database? c. Discuss some considerations when designing a database. ANS a) Metadata is " data about data". The term is ambiguous, as it is used for two fundamentally different concepts ( types ). Structural metadata is about the design and specification of data structures and is more properly called "data about the containers of data"; descriptive metadata , on the other hand, is about individual instances of application data, the data content. Metadata are traditionally found in the card catalogs of libraries . As information has become increasingly digital, metadata are also used to describe digital data using metadata standards specific to a particular discipline. By describing the contents and context of data files , the quality of the original data/files is greatly increased. For example, a webpage may include metadata specifying what language it is written in, what tools were used to create it, and where to go for more on the subject, allowing browsers to automatically improve the experience of users. Metadata (metacontent)are defined as the data providing information about one or more aspects of the data, such as: Means of creation of the data Purpose of the data Time and date of creation Creator or author of the data Location on a computer network where the data were created Standards used For example, a digital image may include metadata that describe how large the picture is, the color depth, the image resolution,

Upload: neema-chaturvedi

Post on 23-Nov-2015

369 views

Category:

Documents


3 download

DESCRIPTION

assignment solution 9818750970

TRANSCRIPT

Subject Code: IMT-37 Subject Name : DBMS (ORACLE)

ASSIGNMENTS

PART A Q1. a. Describewhatmetadataareandwhatvaluetheyprovidetothedatabasesystem.b. WhataretheadvantagesofhavingtheDBMSbetweentheendusersapplicationsandthedatabase?c. Discusssomeconsiderationswhendesigningadatabase.ANS a) Metadatais "dataabout data". The term is ambiguous, as it is used for two fundamentally different concepts (types).Structural metadatais about the design and specification of data structures and is more properly called "data about the containers of data";descriptive metadata, on the other hand, is about individual instances of application data, the data content. Metadata are traditionally found in thecard catalogsoflibraries. As information has become increasingly digital, metadata are also used to describe digital data usingmetadata standardsspecific to a particular discipline. By describing thecontentsandcontextofdata files, the quality of the original data/files is greatly increased. For example, awebpagemay include metadata specifying what language it is written in, what tools were used to create it, and where to go for more on the subject, allowingbrowsersto automatically improve the experience of users. Metadata (metacontent)are defined as the data providing information about one or more aspects of the data, such as: Means of creation of the data Purpose of the data Time and date of creation Creator or author of the data Location on acomputer networkwhere the data were created StandardsusedFor example, adigital imagemay include metadata that describe how large the picture is, the color depth, the image resolution, when the image was created, and other data.[1]A text document's metadata may contain information about how long the document is, who the author is, when the document was written, and a short summary of the document.Metadata are data. As such, metadata can be stored and managed in adatabase, often called aMetadata registryorMetadata repository.[2]However, without context and a point of reference, it might be impossible to identify metadata just by looking at them.[3]For example: by itself, a database containing several numbers, all 13 digits long could be the results of calculations or a list of numbers to plug into an equation - without any other context, the numbers themselves can be perceived as the data. But if given the context that this database is a log of a book collection, those 13-digit numbers may now be identified asISBNs- information that refers to the book, but is not itself the information within the book.The term "metadata" was coined in 1968 by Philip Bagley, in his book "Extension of programming language concepts" where it is clear that he uses the term in the ISO 11179 "traditional" sense, which is "structural metadata" i.e. "data about the containers of data"; rather than the alternate sense "content about individual instances of data content" or metacontent, the type of data usually found in library catalogues.[4][5]Since then the fields of information management, information science, information technology, librarianship and GIS? have widely adopted the term. In these fields the wordmetadatais defined as "data about data".[6]While this is the generally accepted definition, various disciplines have adopted their own more specific explanation and uses of the term.b.) A database management system (DBMS) is a collection of programs which allow end-users to create, maintain and control records in a database. DBMS features primarily address the creation of databases for data extraction, queries and record interrogation. The difference between a DBMS system and an application development environment range from data usage to personnel. Records Interrogation Records interrogation programs are designed to provide the end-user information through several programs, Query, report generator or general inquiry programs. The most popular program is the query program, which allows the end-user to develop basic program skills by constructing simple data programs using a query language processor to extract data. Query programs are powerful utilities for records interrogation.Personnel Advantages A DBMS system consists of data managers and database administrators that oversee the entire DBMS operation. Their primary duties are database records maintenance, loading program releases and making sure primary scheduling is run daily. Applications development consist of programmers, computer technicians and a systems analyst with the job of finding software errors for testing.c. ) Designing a database requires an understanding of both the business functions you want to model and the database concepts and features used to represent those business functions.It is important to accurately design a database to model the business because it can be time consuming to change the design of a database significantly once implemented. A well-designed database also performs better.When designing a database, consider: The purpose of the database and how it affects the design. Create a database plan to fit your purpose. Database normalization rules that prevent mistakes in the database design. Protection of your data integrity. Security requirements of the database and user permissions. Performance needs of the application. You must ensure that the database design takes advantage of Microsoft SQL Server 2000 features that improve performance. Achieving a balance between the size of the database and the hardware configuration is also important for performance. Maintenance. Estimating the size of a database.

Q2. a. Listandbrieflydescribethedifferenttypesdatabasemaintenanceactivities.b. Databasebackupscanbeperformedatdifferentlevels.Listanddescribethese.c. Whataretheclassicalapproachestodatabasedesign?Ans a.) Database maintenance is an activity designed to keep a database running smoothly. A number of different systems can be used to build and maintain databases, with one popular example being MYSQL. The maintenance of databases is generally performed by people who are comfortable and familiar with the database system and the specifics of the particular database, although some maintenance tasks can be performed by people who do not have experience.Databases are used to maintain a library of information in a well organized, accessible format. They usually are not static, however, because changes are constantly being made as material is added, removed, and moved around. People may also change parameters within the database, decide to use different indexing systems, and so forth. Over time, this can cause the database to start to malfunction. Database maintenance is used to keep the database clean and well organized so that it will not lose functionality.One important aspect of maintaining a database is simply backing up the data so that, if anything happens, there will be another copy available. Some databasing systems actually do this automatically, sending a backup to another location every day, every week, or within any other set period of time. Backups are usually not enough, however Database maintenance includes checking for signs of corruption in the database, looking for problem areas, rebuilding indexes, removing duplicate records, and checking for any abnormalities in the database that might signal a problem. The goal is to keep the database operating smoothly for users, so that ideally they never need to think about maintenance issues. A database that is not maintained can become sluggish, and people may start to experience problems when trying to access records.Many servers have extensive databases that are used to serve up content to users on an internal network or on the Internet. An important part ofserver maintenanceinvolves confirming that databases are working properly. This also includes checks for security flaws and other issues that could threaten the integrity of the database, ranging from viruses to records which are entered improperly.Numerous textbooks are available with information about database management, including how to maintain databases properly. It is also possible to take courses to learn about different databasing systems and how to care for databases, whether they are being built from scratch or taken over. People can also earn certifications in specific systems which indicate a high level of competence.

b.) The focus in Oracle backup and recovery is generally on the physical backup of database files, which permit the full reconstruction of your database. The files protected by the backup and recovery facilities built into Enterprise Manager include datafiles, control files, server parameter files (SPFILEs), and archived redo log files. With these your database can be reconstructed. The backup mechanisms that work at the physical level protect against damage at the file level, such as the accidental deletion of a datafile or the failure of a disk drive.Logical-level backups, such as exporting database objects like tables or tablespaces, are a useful supplement to physical backups for some purposes but cannot protect your entire database. Your approach to backing up your database should therefore be based upon physical-level backups.Oracle's flashback features provide a range of physical and logical data recovery tools as efficient, easy-to-use alternatives to physical and logical backups. This chapter will introduce two of the flashback features that operate at a logical level: Oracle Flashback Table, which lets you revert a table to its contents at a time in the recent past; and Oracle Flashback Drop, which lets you rescue dropped database tables. Neither requires advance preparation such as creating logical-level exports to allow for retrieval of your lost data, and both can be used while your database is available.Oracle Database Backup and Recovery Advanced User's Guidediscusses the flashback features of the Oracle database at greater length.Oracle Enterprise Manager's physical backup and recovery features are built onOracle's Recovery Manager (RMAN) command-line client. Enterprise Manager carries out its backup and recovery tasks by composing RMAN commands and sending them to the RMAN client. Enterprise Manager makes available much of the functionality of RMAN, as well as providing wizards and automatic strategies to simplify and further automate implementing RMAN-based backup and recovery.After you are familiar with the basics of backup and recovery through Oracle Enterprise Manager, refer toOracle Database Backup and Recovery Basics, andOracle Database Backup and Recovery Advanced User's Guide, for more details on the full range of Oracle's backup capabilities.

c.) There are two approaches for developing any database, the top-down method and the bottom-up method. While these approaches appear radically different, they share the common goal of uniting a system by describing all of the interaction between the processes.Top down design methodThe top-down design method starts from the general and moves to the specific. In other words, you start with a general idea of what is needed for the system and then work your way down to the more specific details of how the system will interact. This process involves the identification of different entity types and the definition of each entitys attributes.

Added byRyan.M

Bottom up design methodThe bottom-up approach begins with the specific details and moves up to the general. This is done by first identifying the data elements (items) and then grouping them together in data sets. In other words, this method first identifies the attributes, and then groups them to form entities.

Added byRyan.M

Two general approaches (top down and bottom up) to the design of the databases can be heavily influenced by factors like scope, size of the system, the organizations management style, and the organizations structure. Depending on such factors, the design of the database might use two very different approaches, centralized design and decentralized design.Centralized designCentralized design is most productive when the data component is composed of a moderately small number of objects and procedures. The design can be carried out and represented in a somewhat simple database. Centralized design is typical of a simple or small database and can be successfully done by a single database administrator or by a small design team. This person or team will define the problems, create the conceptual design, verify the conceptual design with the user views, and define system processes and data constraints to ensure that the design complies with the organizations goals. That being said, the centralized design is not limited to small companies. Even large companies can operate within the simple database environment.

Added byRyan.M

Decentralized designDecentralized design might best be used when the data component of the system has a large number of entities and complex relations upon which complex operations are performed. This is also likely to be used when the problem itself is spread across many operational sites and the elements are a subset of the entire data set. In large and complex projects a team of carefully selected designers are employed to get the job done. This is commonly accomplished by several teams that work on different subsets or modules of the system. Conceptual models are created by these teams and compared to the user views, processes, and constraints for each module. Once all the teams have completed their modules they are all put aggregated into one large conceptual model.

Q3. a.Explainthedifferencesbetweenacentralizedanddecentralizedapproachtodatabasedesign.b. Explainhowdatabasedesignersdesignandnormalizedatabases.c. Explain theBCNF.Howisitrelatedtoothernormalforms?Ans a.) he issue of centralization versus decentralization of computer re- sources is not a new one; it has been widely discussed and hotly debated for at least two decades now. The interest in this issue was originally motivated by the feeling that the computer, a costly expense in terr.s of investment and operat- ing budget, should be used to the fullest possible potential. Interest also grew because it was felt that within a corporation, a large measure of political power rested with whomever controlled the data processing facility. Lately advances in network technology and the advent of efficient low cost mini and micro computers has initiated the era of distributed data processing and in effect thrown new fuel into the centralization/ decentralization fire.

Of the voluminous literature published on this subject, we first concentrate on key articles relating to one aspect of the problem: the centralization/de- centralization decision . Management, faced with decisions regarding proper long range directions toward optimal configurations of hardware, software, and personnel finds little by way of guidelines to follow. There seems then to be a real need for a rigorous decision model to provide management with an approach to solving this dilemma.

Ernest Dale (2) states: "the proper balance between centralization and decentralization often is decided by necessity, intuition, and luck because of the immense variety of possible human behavior and vast multiplicity of minute, undiscoverable causes and effects that cannot be encompassed in

(2) Dale, E. '"Centralization versus Decentralization," Advanced Management , June 1955.

- 3 -

any principal or standard of evaluation." In addition, current solutions seem highly dependent on the characteristics, philosophies, and objectives of the particular organization for which the decision is to be inade. Accord- ing to George Glaser (3) , "the organizational approach to data p'-ocessing should be consistent with the overall* organizational approach of the com- pany in which it functions." The problem is not only of major importance but of substantial complexity also.

b).Database designis the process of producing a detaileddata modelof adatabase. Thislogical data modelcontains all the needed logical and physical design choices and physical storage parameters needed to generate a design in aData Definition Language, which can then be used to create a database. A fully attributed data model contains detailed attributes for each entity.The term database design can be used to describe many different parts of the design of an overalldatabase system. Principally, and most correctly, it can be thought of as the logical design of the base data structures used to store the data. In therelational modelthese are thetablesandviews. In anobject databasethe entities and relationships map directly to object classes and named relationships. However, the term database design could also be used to apply to the overall process of designing, not just the base data structures, but also the forms and queries used as part of the overall database application within thedatabase management system(DBMS).[1]The process of doing database design generally consists of a number of steps which will be carried out by the database designer. Usually, the designer must: Determine the relationships between the different data elements. Superimpose a logical structure upon the data on the basis of these relationships

c. ) BoyceCodd normal form(orBCNFor3.5NF) is anormal formused indatabase normalization. It is a slightly stronger version of thethird normal form(3NF). BCNF was developed in 1974 byRaymond F. BoyceandEdgar F. Coddto address certain types of anomaly not dealt with by 3NF as originally defined.[1]Chris Datehas pointed out that a definition of what we now know as BCNF appeared in a paper by Ian Heath in 1971.[2]Date writes:"Since that definition predated Boyce and Codd's own definition by some three years, it seems to me that BCNF ought by rights to be calledHeathnormal form. But it isn't."[3]Edgar F.Codd released his original paper 'A Relational Model of Data for Large Shared Databanks' in June 1970. This was the first time the notion of a relational database was published. All work after this, including the Boyce-Codd normal form method was based on this relational model.If arelational schemais in BCNF then all redundancy based on functional dependency has been removed, although other types of redundancy may still exist. A relational schemaRis in BoyceCodd normal formif and only iffor every one of itsdependenciesX Y, at least one of the following conditions hold:[4] X Yis a trivial functional dependency (Y X) Xis asuperkeyfor schemaR

Q4. a. Whatisaschema?Howmanyschemascanbeusedinonedatabase?b. Whatcommandisusedtosavechangestothedatabase?Whatisthesyntaxforthiscommand?Howdoyoudeleteatablefromthedatabase?Provideanexample.c. Whatisasubquery?Whenisitused?DoestheRDBMSdealwithsubqueriesanydifferentlyfromnormalqueries?Ans . a. ) Adatabase schema(/ski.m/skee-m) of adatabase systemis its structure described in aformal languagesupported by thedatabase management system(DBMS) and refers to the organization of data as a blueprint of how a database is constructed (divided into database tables in case ofRelational Databases). The formal definition ofdatabaseschema is a set of formulas (sentences) calledintegrity constraintsimposed on a database. These integrity constraints ensure compatibility between parts of the schema. All constraints are expressible in the same language. A database can be considered a structure in realization of thedatabase language.[1]The states of a createdconceptual schemaare transformed into an explicit mapping, the database schema. This describes how real world entities are modeled in the database."A database schema specifies, based on thedatabase administrator's knowledge of possible applications, the facts that can enter the database, or those of interest to the possibleend-users."[2]The notion of a database schema plays the same role as the notion of theory inpredicate calculus. A model of this theory closely corresponds to a database, which can be seen at any instant of time as amathematical object. Thus a schema can contain formulas representing integrity constraints specifically for an application and the constraints specifically for a type of database, all expressed in the same database language.[1]In arelational database, the schema defines thetables,fields,relationships,views,indexes,packages,procedures,functions,queues,triggers,types,sequences,materialized views,synonyms,database links,directories,XML schemas, and other elements.Schemas are generally stored in adata dictionary. Although a schema is defined in text database language, the term is often used to refer to a graphical depiction of the database structure. In other words, schema is the structure of the database that defines the objects in the database.In anOracle Databasesystem, the term "schema" has a slightly different connotation.

b. ) A transaction is a unit of work that is performed against a database. Transactions are units or sequences of work accomplished in a logical order, whether in a manual fashion by a user or automatically by some sort of a database program.A transaction is the propagation of one or more changes to the database. For example, if you are creating a record or updating a record or deleting a record from the table, then you are performing transaction on the table. It is important to control transactions to ensure data integrity and to handle database errors.Practically, you will club many SQL queries into a group and you will execute all of them together as a part of a transaction.Properties of Transactions:Transactions have the following four standard properties, usually referred to by the acronym ACID: Atomicity:ensures that all operations within the work unit are completed successfully; otherwise, the transaction is aborted at the point of failure, and previous operations are rolled back to their former state. Consistency:ensures that the database properly changes states upon a successfully committed transaction. Isolation:enables transactions to operate independently of and transparent to each other. Durability:ensures that the result or effect of a committed transaction persists in case of a system failure.Transaction Control:There are following commands used to control transactions: COMMIT:to save the changes. ROLLBACK:to rollback the changes. SAVEPOINT:creates points within groups of transactions in which to ROLLBACK SET TRANSACTION:Places a name on a transaction.Transactional control commands are only used with the DML commands INSERT, UPDATE and DELETE only. They can not be used while creating tables or dropping them because these operations are automatically commited in the database.The COMMIT Command:The COMMIT command is the transactional command used to save changes invoked by a transaction to the database.The COMMIT command saves all transactions to the database since the last COMMIT or ROLLBACK command.

c. ) Oracle is a commercial relational database management system. As with other large-scale RDBMSs, it uses the Structured Query Language for database maintenance, administration and programming. The SQL language lets you create sophisticated database queries for reporting, adding and changing information in the database. These queries can include correlated sub-queries, in which the data from the sub-query depends on the main query. An SQL query is a statement which examines data in the database and uses it to produce a report or update the database. One of the simplest queries is a list of records in a database table. It looks like the following SQL statement:SELECT * FROM customers;This query produces an unsorted list of all the information in the customers table, record by record. By using the powerful WHERE clause, you can create selective queries which evaluate the data and list only those records matching the clauses criteria:SELECT * FROM customers WHERE state = CA;This query lists only customers from California. The WHERE clause accommodates very complex conditions, including the results of correlated sub-queries, for selecting only the data you want.Sub-Queries A sub-query is a query in which the WHERE clause itself has its own query. This is a convenient way to combine information from different database tables to produce more sophisticated results. The following query produces a list of only those customers who have placed orders in 2011:SELECT * FROM customers WHERE customer_code IN (SELECT customer_code FROM orders WHERE order_date BETWEEN 1/1/2011 AND 12/31/2011);Notice that this is a query inside a query. The SELECT statement inside the parentheses generates a list of customer codes from the orders table. The outer query uses the customer codes to produce a list of customer names, addresses and other information. This is a sub-query but not a coordinated sub-query; though the outer query depends on the inner one, a coordinated sub-query also has an inner query that depends on the outer one. Sponsored Links Story of SendFollow an email on its journey. An inside look at how email works.www.google.com/green/storyofsendCorrelated Sub-Queries In a correlated sub-query, each query depends on the other. The following Oracle SQL statement produces a list of customer codes, names, and purchase totals for those customers whose purchase amounts fall below the average for all customers in a state. You then have two mutually dependent queries, one which lists the customers but needs the average sales figure against which to compare, and the other which calculates the average but needs the state. Note the use of the table aliases c1 and c2. The alias c1 refers to the customer table in the outer query, and c2 is the customer table in the inner query.

Q5. a. Explainnormalizationanditsdifferentforms.b. Describetheneedforconvenientandsafebackupstorage.c. ExplainuserrequirementsgatheringaspartoftheDBA'send-usersupportservices.Ans a) Normalization is the process of designing database tables to ensure that the fields in each table do not repeat, are fully identified by a unique KEY, and are not dependent on any non-key ATTRIBUTEs.shr.aaas.org/DBStandards/glossary.html

Normalization helps in reducingdata redundancy. As we move towards higher normalization

1NF: This type of normalization states that there must not be any duplicates in the tables that we use. In other words, all the tables used must have a primary key defined.

2NF: This type of normalization states that data redundancy can be reduced if attributes those are dependent on one of the keys of a composite primary key are isolated to a separate table. Not only does this reduces data redundancy but also helps in increasing data retention when a delete is done. For example, consider a table that has the following columns: Part Id, State, City, and Country. Here, assume Part Id & Country form the composite primary key. The attributes state & city depend only on the country. 2NF states that if such is the case then split the table into 2 tables. One with Part Id & country as the columns. Other with Country, state & city as the columns. In the 1st table if a delete is made to all the rows with Part Id = X then we would lose country related data too. But in the 2nd case this would not happen. b.).abackup, or the process of backing up, refers to the copying and archiving of computerdataso it may be used torestorethe original after adata lossevent. The verb form is toback upin two words, whereas the noun isbackup.[1]Backups have two distinct purposes. The primary purpose is to recover data after its loss, be it by data deletion orcorruption. Data loss can be a common experience of computer users. A 2008 survey found that 66% of respondents had lost files on their home PC.[2]The secondary purpose of backups is to recover data from an earlier time, according to a user-defineddata retentionpolicy, typically configured within a backup application for how long copies of data are required. Though backups popularly represent a simple form ofdisaster recovery, and should be part of adisaster recovery plan, by themselves, backups should not alone be considered disaster recovery.[3]One reason for this is that not all backup systems or backup applications are able to reconstitute a computer system or other complex configurations such as acomputer cluster,active directoryservers, or adatabase server, by restoring only data from a backup.Since a backup system contains at least one copy of all data worth saving, thedata storagerequirements can be significant. Organizing this storage space and managing the backup process can be a complicated undertaking. A data repository model can be used to provide structure to the storage. Nowadays, there are many different types ofdata storage devicesthat are useful for making backups. There are also many different ways in which these devices can be arranged to provide geographic redundancy,data security, and portability.Before data is sent to its storage location, it is selected, extracted, and manipulated. Many different techniques have been developed to optimize the backup procedure. These include optimizations for dealing with open files and live data sources as well as compression, encryption, andde-duplication, among others. Every backup scheme should includedry runsthat validate the reliability of the data being backed up. It is important to recognize the limitations and human factors involved in any backup scheme

c.).In a database environment such as Adabas, the same data is used by many applications (users) in many departments of the organization. Ownership of and responsibility for the data is shared by departments with diverse and often conflicting needs. One task of the DBA is to resolve such differences.Data security and integrity are no longer bound to a single individual or department, but are inherent in systems such as Adabas; in fact, the DBA controls and customized security profiles offered by such systems usually improve security and integrity.In the past, application development teams have been largely responsible for designing and maintaining application files, usually for their own convenience. Other applications wishing to use the data had to either accept the original file design or convert the information for their own use. This meant inconsistent data integrity, varied recovery procedures, and questionable privacy safeguards. In addition, little attention was given to overall system efficiency; changes introduced in one system could adversely affect the performance of other systems.With an integrated and shared database, such a lack of central control would soon lead to chaos. Changes to file structure to benefit one project could adversely influence data needs of other projects. Attempts to improve efficiency of one project could be at the expense of another. The use of different security and recovery procedures would, at best, be difficult to manage and at worst, result in confusion and an unstable, insecure database.Clearly, proper database management means that central control is needed to ensure adherence to common standards and an installation-wide view of hardware and software needs. This central control is the responsibility of the DBA. For these and other reasons, it is important that the DBA function be set up at the very beginning of the database development cycle.

PART B Q1a). Explainheterogeneousdistributeddatabasesystems.b. AfullydistributeddatabasemanagementsystemmustperformallofthefunctionsofacentralizedDBMS.Doyouagree?Whyorwhynot?c. Describethefivetypesofusersidentifiedinadatabasesystem.Ans a). Aheterogeneous database systemis an automated (or semi-automated) system for the integration of heterogeneous, disparatedatabase management systemsto present a user with a single, unified query interface.Heterogeneous database systems (HDBs) are computational models and software implementations that provide heterogeneous database integration.This article does not contain details ofdistributed database management systems(sometimes known asfederated database systems).Technical heterogeneityDifferentfile formats, accessprotocols, query languages etc. Often called syntactic heterogeneity from the point of view of data.Data model heterogeneityDifferent ways of representing and storing the same data. Table decompositions may vary, column names (data labels) may be different (but have the same semantics), dataencodingschemes may vary (i.e.,should a measurement scale be explicitly included in a field or should it be implied elsewhere). Also referred as schematic heterogeneity.Semantic heterogeneityData across constituent databases may be related but different. Perhaps a database system must be able to integrate genomic and proteomic data. They are relateda gene may have several protein productsbut the data are different (nucleotidesequences andamino acidsequences, or hydrophilic or -phobic amino acid sequence and positively or negatively charged amino acids). There may be many ways of looking at semantically similar, but distinct, datasets.

b.) Adistributed databaseis adatabasein whichstorage devicesare not all attached to a common processing unit such as theCPU,[1]controlled by adistributeddatabase management system(together sometimes called adistributed database system). It may be stored in multiplecomputers, located in the same physical location; or may be dispersed over anetworkof interconnected computers. Unlike parallel systems, in which the processors are tightly coupled and constitute a single database system, a distributed database system consists of loosely-coupled sites that share no physical components.System administrators can distribute collections of data (e.g. in a database) across multiple physical locations. A distributed database can reside onnetwork serverson theInternet, on corporateintranetsorextranets, or on other companynetworks. Because they store data across multiple computers, distributed databases can improve performance atend-userworksites by allowing transactions to be processed on many machines, instead of being limited to one.[2]Two processes ensure that the distributed databases remain up-to-date and current:replicationandduplication.1. Replication involves using specialized software that looks for changes in the distributive database. Once the changes have been identified, the replication process makes all the databases look the same. The replication process can be complex and time-consuming depending on the size and number of the distributed databases. This process can also require a lot of time and computer resources.2. Duplication, on the other hand, has less complexity. It basically identifies one database as amasterand then duplicates that database. The duplication process is normally done at a set time after hours. This is to ensure that each distributed location has the same data. In the duplication process, users may change only the master database. This ensures that local data will not be overwritten.Both replication and duplication can keep the data current in all distributive locations.[2]Besides distributed database replication and fragmentation, there are many other distributed database design technologies. For example, local autonomy, synchronous and asynchronous distributed database technologies. These technologies' implementation can and does depend on the needs of the business and the sensitivity/confidentialityof the data stored in the database, and hence the price the business is willing to spend on ensuringdata security,consistencyandintegrity.When discussing access to distributed databases,Microsoftfavors the termdistributed query, which it defines in protocol-specific manner as "[a]ny SELECT, INSERT, UPDATE, or DELETE statement that references tables and rowsets from one or more external OLE DB data sources".[3]Oracleprovides a more language-centric view in which distributed queries anddistributed transactionsform part ofdistributed SQLA database user accesses the distributed database through:Local applicationsapplications which do not require data from other sites.Global applicationsapplications which do require data from other sites.Ahomogeneous distributed databasehas identical software and hardware running all databases instances, and may appear through a single interface as if it were a single database. Aheterogeneous distributed databasemay have different hardware, operating systems, database management systems, and even data models for different databases.

c.) Software refers to the collection of programs used with in the database system. It includes the operating system, DBMS Software, and application programs and utilities.Operating SystemDBMS SoftwareApplication Programs and UtilitiesThe operating System manages all the hardware components and makes it possible for all other software to run on the computers. UNIX, LINUX, Microsoft Windows etc are the popular operating systems used in database environment.DBMS software manages the database with in the database system. Oracle Corporation's ORACLE, IBM's DB2, Sun's MYSQL, Microsoft's MS Access and SQL Server etc are the popular DBMS (RDBMS) software used inthe database environment.Application programs and utilities software are used to access and manipulate the data in the database and to manage the operating environment of the database.People in a Database System EnvironmentPeople component includes all users associated with the database system. On the basis of primary job function we can identify five types of users in a database system: System Administrators, Database Administrators, Data Modelers,System Analysts and Programmers and End Users.System AdministratorsData ModelersDatabase AdministratorsSystem Analysts and ProgrammersEnd Users

System Administrators oversees the database system's general operations.Data Modelers (Architect) prepare the conceptualdesign from the requirement.ER model represent the conceptual design of an OLTP application.Database Administrator (DBA) physically implements the database according to the logical design. The DBA performs the physical implementation and maintenance of a database system.System Analysts and programmers design and implements the application programs. They create the input screens, reports, and procedures through which end users access and manipulate the database.End Users are the people who use the application. For example incase of a banking system, the employees, customer using ATM or online banking facility are end users.

Q2. a. DescribetheDBAsmanagerialrole.b. Whatarethethreebasictechniquestocontroldeadlocks?c. Howdoesashared/exclusivelockschemaincreasethelockmanagersoverhead?Ans . a.).The success of a database environment depends on central control of database design, implementation, and use. This central control and coordination is the role of the database administrator (DBA).This part of the DBA documentation describes the roles of the DBA, the authority and responsibility the DBA might have, the skills needed, the procedures, standards, and contacts the DBA may need to create and maintain.In the context of this documentation, the DBA is a single person; however, large organizations may divide DBA responsibilities among a team of personnel, each with specific skills and areas of responsibility such as database design, tuning, or problem resolution. The ability of the database administrator (DBA) to work effectively depends on the skill and knowledge the DBA brings to the task, and the role the DBA has on the overall Information Systems (IS) operation. This section describes how best to define the DBA role, discusses the relationship of the DBA to the IS organization, and makes suggestions for taking advantage of that relationship.Position of the DBA in the OrganizationThe DBA should be placed high enough in the organization to exercise the necessary degree of control over the use of the database and to communicate at the appropriate level within user departments. However, the DBA should not be remote from the day-to-day processes of monitoring database use, advising on and selecting applications, and maintaining the required level of database integrity.The appropriate position and reporting structure of the DBA depends solely on the nature and size of the organization.In most organizations, the DBA is best placed as a functional manager with an status equivalent to the systems, programming, and operations managers. The DBA should have direct responsibility for all aspects of the continued operation of the database. It is also useful to give the DBA at least partial control over the programming and IS operation standards, since the DBA must have the ability to ensure that DBMS-compatible standards are understood and observed.

b. ) Adeadlockis a situation in which two or more competing actions are each waiting for the other to finish, and thus neither ever does.Incomputer scienceadeadly embraceis a deadlock involving exactly two competing actions. It is a term more commonly used in Europe.In atransactional database[disambiguation needed], a deadlock happens when two processes each within its own transaction updates two rows of information but in the opposite order. For example, process A updates row 1 then row 2 in the exact timeframe process B updates row 2 then row 1. Process A can't finish updating row 2 until process B is finished, but it cannot finish updating row 1 until process A finishes. No matter how much time is allowed to pass, this situation will never resolve itself and because of thisdatabase management systemswill typically kill the transaction of the process that has done the least amount of work.In anoperating system, a deadlock is a situation which occurs when aprocessorthreadenters a waitingstatebecause aresourcerequested is being held by another waiting process, which in turn is waiting for another resource. If a process is unable to change its state indefinitely because the resources requested by it are being used by another waiting process, then the system is said to be in a deadlock.[1]Deadlock is a common problem inmultiprocessingsystems,parallel computinganddistributed systems, where software and hardwarelocksare used to handle shared resources and implementprocess synchronization

c.) This article is aboutconcurrency control. For commit consensus within a distributed transaction, seeTwo-phase commit protocol.Indatabasesandtransaction processing,two-phase locking(2PL) is aconcurrency controlmethod that guaranteesserializability.[1][2]It is also the name of the resulting set ofdatabase transactionschedules(histories). The protocol utilizeslocks, applied by a transaction to data, which may block (interpreted as signals to stop) other transactions from accessing the same data during the transaction's life.By the 2PL protocol locks are applied and removed in two phases:1. Expanding phase: locks are acquired and no locks are released.2. Shrinking phase: locks are released and no locks are acquired.Two types of locks are utilized by the basic protocol:SharedandExclusivelocks. Refinements of the basic protocol may utilize more lock types. Using locks that block processes, 2PL may be subject todeadlocksthat result from the mutual blocking of two or more transactions.2PL is asupersetofstrong strict two-phase locking(SS2PL),[3]also calledrigorousness,[4]which has been widely utilized for concurrency control in general-purpose database systems since the 1970s. SS2PL implementations have many variants. SS2PL was calledstrict 2PL[1]but this name usage is not recommended now. Nowstrict 2PL(S2PL) is the intersection ofstrictnessand 2PL, which is different from SS2PL. SS2PL is also a special case ofcommitment ordering,[3]andinherits many of CO's useful properties. SS2PL actually comprises only one phase: phase-2 does not exist, and all locks are released only after transaction end. Thus this useful 2PL type is not two-phased at all.Neither 2PL nor S2PL in their general forms are known to be used in practice. Thus 2PL by itself does not seem to have much practical importance, and whenever 2PL or S2PL utilization has been mentioned in the literature, the intention has been SS2PL. What has made SS2PL so popular (probably the most utilizedserializabilitymechanism) is the effective and efficient locking-based combination of two ingredients (the first does not exist in both general 2PL and S2PL; the second does not exist in general 2PL):1. Commitment ordering, which provides bothserializability, and effectivedistributed serializabilityandglobal serializability, and2. Strictness, which providescascadelessness(ACA, cascade-less recoverability) and (independently) allows efficient databaserecoveryfrom failure.Additionally SS2PL is easier, with less overhead to implement than both 2PL and S2PL, provides exactly the same locking, but sometimes releases locks later. However, practically (though not simplistically theoretically) such later lock release occurs only slightly later, and this apparent disadvantage is insignificant and disappears next to the advantages of SS2PL.Thus, the importance of the generalTwo-phase locking(2PL) is historic only, whileStrong strict two-phase locking(SS2PL) is practically the important mechanism and resulting schedule property. Alockis a system object associated with a shared resource such as a data item of an elementary type, a row in a database, or a page of memory. In a database, a lock on a database object (a data-access lock) may need to be acquired by a transaction before accessing the object. Correct use of locks prevents undesired, incorrect or inconsistent operations on shared resources by other concurrent transactions. When a database object with an existing lock acquired by one transaction needs to be accessed by another transaction, the existing lock for the object and the type of the intended access are checked by the system. If the existing lock type does not allow this specific attempted concurrent access type, the transaction attempting access is blocked (according to a predefined agreement/scheme). In practice a lock on an object does not directly block a transaction's operation upon the object, but rather blocks that transaction from acquiring another lock on the same object, needed to be held/owned by the transaction before performing this operation. Thus, with a locking mechanism, needed operation blocking is controlled by a proper lock blocking scheme, which indicates which lock type blocks which lock type.Two major types of locks are utilized: Write-lock(exclusive lock) is associated with a database object by a transaction (Terminology: "the transaction locks the object," or "acquires lock for it") beforewriting(inserting/modifying/deleting) this object. Read-lock(shared lock) is associated with a database object by a transaction beforereading(retrieving the state of) this object.The common interactions between these lock types are defined by blocking behavior as follows: An existingwrite-lockon a database object blocks an intendedwriteupon the same object (already requested/issued) by another transaction by blocking a respectivewrite-lockfrom being acquired by the other transaction. The second write-lock will be acquired and the requested write of the object will take place (materialize) after the existing write-lock is released. Awrite-lockblocks an intended (already requested/issued)readby another transaction by blocking the respectiveread-lock. Aread-lockblocks an intendedwriteby another transaction by blocking the respectivewrite-lock. Aread-lockdoes not block an intendedreadby another transaction. The respectiveread-lockfor the intended read is acquired (shared with the previous read) immediately after the intended read is requested, and then the intended read itself takes place.

Q3. a. Describeaconceptualmodelanditsadvantages.Whatisthemostwidelyusedconceptualmodel?b.Whatisakeyandwhyisitimportantintherelationalmodel?Describetheuseofnullsinadatabase.c. Explainsingle-valuedattributesandprovideanexample.Explainthedifferencebetweensimpleandcompositeattributes.Provideatleastoneexampleofeach.Ans . a. ) In the most general sense, amodelis anything used in any way to represent anything else. Somemodelsarephysical objects, for instance, a toy model which may be assembled, and may even be made to work like the object it represents. Whereas, aconceptual modelis a model made of thecompositionofconcepts, that thus exists only in the mind. Conceptual models are used to help usknow,understand, orsimulatethe subject matter they represent.The termconceptual modelmay be used to refer to models which are formed after a conceptualization process in the mind. Conceptual models represent human intentions or semantics[citation needed]. Conceptualization from observation of physical existence and conceptual modeling are the necessary means human employ to think and solve problems[citation needed]. Concepts are used to convey semantics during various natural languages based communication[citation needed]. Since a concept might map to multiple semantics by itself, an explicit formalization is usually required for identifying and locating the intended semantic from several candidates to avoid misunderstandings and confusions in conceptual models.[ The term "conceptual model" is ambiguous. It could meana model of conceptor it could meana model that is conceptual. A distinction can be made betweenwhat models areandwhat models are models of. With the exception of iconic models, such as a scale model ofWinchester Cathedral, most models are concepts. But they are, mostly, intended to be models of real world states of affairs. The value of a model is usually directly proportional to how well it corresponds to a past, present, future, actual or potential state of affairs. A model of a concept is quite different because in order to be a good model it need not have this real world correspondence.[2]Models of concepts are usually built by analysts who are not primarily concerned about the truth or falsity of the concepts being modeled. For example, in management problem structuring, Conceptual Models of human activity systems are used inSoft systems methodologyto explore the viewpoints of stakeholders in the client organization. In artificial intelligence conceptual models andconceptual graphsare used for buildingexpert systemsandknowledge-based systems, here the analysts are concerned to represent expert opinion on what is true not their own ideas on what is true.Type and scope of conceptual modelsConceptual models (models that are conceptual) range in type from the more concrete, such as themental imageof a familiar physical object, to the formal generality and abstractness ofmathematical modelswhich do not appear to the mind as an image. Conceptual models also range in terms of the scope of the subject matter that they are taken to represent. A model may, for instance, represent a single thing (e.g. theStatue of Liberty), whole classes of things (e.g.the electron), and even very vast domains of subject matter such asthe physical universe.The variety and scope of conceptual models is due to the variety of purposes had by the people using them.b.) Therelational modelfordatabasemanagement is adatabase modelbased onfirst-order predicate logic, first formulated and proposed in 1969 byEdgar F. Codd.[1][2]In the relational model of a database, all data is represented in terms oftuples, grouped intorelations. A database organized in terms of the relational model is arelational database.

Diagram of an example database according to the Relational model.[3]

In the relational model, related records are linked together with a "key".The purpose of the relational model is to provide adeclarativemethod for specifying data and queries: users directly state what information the database contains and what information they want from it, and let the database management system software take care of describing data structures for storing the data and retrieval procedures for answering queries.Most relational databases use theSQLdata definition and query language; these systems implement what can be regarded as an engineering approximation to the relational model. Atablein an SQL database schema corresponds to a predicate variable; the contents of a table to a relation; key constraints, other constraints, and SQL queries correspond to predicates. However, SQL databases, including DB2,deviate from the relational model in many details, and Codd fiercely argued against deviations that compromise the original principles.

c.) For the next section we will look at a sample database called the COMPANY database to illustrate the concepts of Entity Relationship Model.This database contains the information about employees, departments and projects: There are several departments in the company. Each department has a unique identification, a name, location of the office and a particular employee who manages the department. A department controls a number of projects, each of which has unique name, a unique number and the budget. Each employee has name, an identification number, address, salary, birthdate. An employee is assigned to one department but can join in several projects. We need to record the start date of the employee in each project. We also need to know the direct supervisor of each employee. We want to keep track of the dependents of the employees. Each dependent has name, birthdate and relationship with the employee.Entity, Entity Set and Entity TypeAn entity is an object in the real world with an independent existence and can be differentiated from other objectsAn entity might be An object with physical existence. E.g. a lecturer, a student, a car An object with conceptual existence. E.g. a course, a job, a positionAn Entity Type defines a collection of similar entities.An Entity Set is a collection of entities of an entity type at a point of time. In ER diagrams, an entity type is represented by a name in a box. Source: http://cnx.org/content/m28250/latest/Types of EntitiesIndependent entities, also referred to as Kernels, are the backbone of the database. It is what other tables are based on. Kernels have the following characteristics: they are the building blocks of a database the primary key may be simple or composite the primary key is not a foreign key they do not depend on another entity for their existenceExample: Customer table, Employee table, Product tableDependent Entities, also referred to as derived, depend on other tables for their meaning. Dependent entities are used to connect two kernels together. They are said to be existent dependent on two or more tables. Many to many relationships become associative tables with at least two foreign keys. They may contain other attributes. The foreign key identifies each associated table. There are three options for the primary key: use a composite of foreign keys of associated tables if unique use a composite of foreign keys and qualifying column create a new simple primary keyCharacteristic entities provide more information about another table. These entities have the following characteristic. They represent multi-valued attributes. They describe other entities. They typically have a one to many relationship. The foreign key is used to further identify the characterized table. Options for primary key are as follows: foreign key plus a qualifying column or create a new simple primary key Employee(EID,Name, Address, Age, Salary) EmployeePhone(EID, Phone)AttributesEach entity is described by a set of attributes. E.g. Employee = (Name, Address, Age, Salary).Each attribute has a name, associated with an entity and is associated with a domain of legal values. However the information about attribute domain is not presented on the ER diagram.In the diagram, each attribute is represented by an oval with a name inside.

Q4. a. Describespecializationandgeneralization.b. Explainthedifferenttypesofjoinoperations.Whataretheyandhowdotheywork?c. WhatareSQLfunctionsandwhenaretheyused?Provideacoupleofexamplesofsituationsinwhichtheyarenecessary. Ans a.) A specialization may be a subclass, and also have a subclass specified on it.

EmployeeSecretaryTechnicianEngineerManagerSalaried_EmpHourly EmpEngineering Managerdd

For example, in the figure above, Engineer is a subclass of Employee, but also a super class of Engineering Manager. This means that every Engineering Manager, must also be an Engineer. Specialization Hierarchy has the constraint that every subclass participates as a subclass in only one class/subclass relationship, i.e. that each subclass has only one parent. This results in a tree structure. Specialization Lattice has the constraint that a subclass can be a subclass of more than one class/subclass relationship. The figure shown above is a specialization lattice, because Engineering_Manager participates has more than one parent classes. In a lattice or hierarchy, the subclass inherits the attributes not only of the direct superclass, but also all of the predecessor super classes all the way to the root. A subclass with more than one super class is called a shared subclass. This leads to multiple inheritance, where a subclass inherits attributes from multiple classes. In a lattice, when a superclass inherits attributes from more than one superclass, and some attributes are inherited more than once via different paths (i.e. Engineer, Manager and Salaried Employee all inherit from Employee, that are then inherited by Engineering Manager. In this situation, the attributes are included only once in the subclass.

Modeling Union Types using Categories In the subclass-superclass relationship types we have seen so far, each has a single superclass. This means that in a particular subclass/super class relationship (Engineer, Engineering Manager) even though the subclass has more than one subclass/super class relationship, each relationship is between a single super class and subclass. There are situations when you would like to model a relationship where a single subclass has more than one super class, and where each super class represents a different entity type. The subclass will represent a collection of objects that is a subset of the UNION of the distinct entity types. This type of subclass is a union type, or category subclass. See Text Example, page 99.

A category has two or more super classes that may be distinct entity types, where other super class/subclass relationships have only one super class. If we compare the Engineering Manager subclass, it is a sub class of each of the three super classes, Engineer, Manager and Salaried employee, and inherits the attributes of all three. An entity that exists in Engineering Manager exists in all three super classes. This represents the constraint that an Engineering Manager must be an Engineer, a Manager, AND a Salaried Employee. It can be thought of as an AND condition. By contrast, a category is a union of its subclasses. This means that an entity that is a subclass of a union, exists in ONLY ONE of the super classes. An owner may be a Company, OR a Bank OR a PERSON, but not more than one. A category can be partial or total. A total category holds the union of ALL its super classes, where a partial category can hold a subset of the union. If a category is total, it can also be represented as a total specialization.

Comparison of Registered Vehicle Category to Vehicle

VehicleCarTruckdRegistered_VehicleCarTrucku1. 2.

The first example implies that every car and truck is also a vehicle. In the second example, a registered vehicle can be a car or a truck, but every car and truck is not a registered vehicle.

Other examples: University (Researcher)

Example 4.21Design a database to keep track of information for an art museum. Assume that the following requirements were collected. The museum has a collection of ART_OBJECTS . Each art object has a unique IDNo, and Artist, if known, a Year (when created, if known) a Title and a Description. The art objects are categorized in several ways, as discussed below. ART_OBJECTS are categorized based on types. There are three main types, Painting, Sculpture and Statue, plus an Other category for those that dont fit into one of the categories above. A PAINTING has a PaintType (oil, watercolor, etc) a material on which it is CrawnOn (paper, canvas, wood) and Style (modern, abstract etc) A SCULPTURE or a STATUE has a Material from which it was created (wood, stone, etc) Height, Weight and Style. An art object in the OTHER category has a Type(print, photo, etc) and Style. ART_OBJECTS are also categorized as PERMANENT_COLLECTION, which are owned by the museum (DateAcquired, whether it is OnDisplay or Stored and Cost) or BORROWED, which has information on the Collection (where it was borrowed from), DateBorrowed, and DateReturned. ART_OBJECTS also have information describing their country-culture using information on country/culture of Origin (Italian, Egyptial, American, Indian etc) and Period(Renaissance, Modern, Ancient) The museum keeps track of ARTISTSs information, if known: Name, DateBorn, DateDied, CountryOfOrigin, Period, MainStyle and Description. The name is assumed unique. Different EXHIBITIONS occur, each having a Name, StartDate and EndDate. EXHIBITIONS are related to all the art objects that were on display during the exhibition. Information is kept on other COLLECTIONS with which the museum interacts, including Name (unique), Type (museum, personnel etc), Description, Address, Phone and ContactPerson.

b.) Acomposite tablerepresents the result of accessing one or more tables in a query. If a query contains a single table, only one composite table exists. If one or more joins are involved, anouter composite tableconsists of the intermediate result rows from the previous join step. This intermediate result might, or might not, be materialized into a work file.Thenew table(orinner table) in a join operation is the table that is newly accessed in the step.A join operation can involve more than two tables. In these cases, the operation is carried out in a series of steps.For non-star joins, each step joins only two tables. SometimesDB2has to materialize a result table when an outer join is used in conjunction with other joins, views, or nested table expressions. You can tell when this happens by looking at the TABLE_TYPE and TNAME columns of the plan table. When materialization occurs, TABLE_TYPE contains a W, and TNAME shows the name of the materialized table as DSNWFQB(xx), wherexxis the number of the query block (QBLOCKNO) that produced the work file. Cartesian join with small tables firstACartesian joinis a form of nested loop join in which no join predicates exist between the two tables. Nested loop join (METHOD=1)Innested loop joinDB2scans the composite (outer) table. For each row in that table that qualifies (by satisfying the predicates on that table),DB2searches for matching rows of the new (inner) table. When a MERGE statement is used (QBLOCK_TYPE ='MERGE')You can determine whether a MERGE statement was used and how it was processed by analyzing the QBLOCK_TYPE and PARENT_QBLOCKNO columns. Merge scan join (METHOD=2)Merge scan joinis also known asmerge joinorsort merge join. For this method, there must be one or more predicates of the form TABLE1.COL1=TABLE2.COL2, where the two columns have the same data type and length attribute. Hybrid join (METHOD=4)The hybrid join method applies only to an inner join, and requires an index on the join column of the inner table. Star schema accessDB2can use special join methods, such as star join and pair-wise join, to efficiently join tables that form a star schema.

c.) Stored procedures are generally non-portable, meaning they are specific to a particular RDBMS. As a matter of fact, stored procedures tend to be specific to a particular VERSION of a particular RDBMS.The development tools for the lifecycle of stored procedures tend to be very limited compared to the tools available for general programming languages/platforms. The tools are lacking in contextual help, in storage of the code, in debugging, in refactoring, etc.The languages for writing stored procedures tend to be very limited compared to general programming languages/platforms. They tend to be procedural, lack many operations, lack most common APIs, and lack many syntax advances (classes, scope, etc.). This has changed somewhat with the introduction of Java into Oracle and .NET into SQL Server.So, as a general rule, avoid writing stored procedures; writing your code in a general programming environment is more desirable. Use stored procedures when you need their particular advantages, which mainly means high-performance and/or tightly-isolated data processing. A typical system will then have maybe a stored procedure or two, but definitely not dozens to hundreds.Best wishes.EDIT: Clarification...Please note that I am addressing enterprise-class developmentin-the-large. If you have a tiny application and a few toy stored procedures, then you can probably ignore everyone's advice. I am assuming that the question is being asked for non-trivial scenarios.I have dealt with every significant RDBMS over a period of nearly twenty years. I have dealt with databases upto 138 TBs, and individual tables of 8 TBs. I have worked with systems exceeding one thousand SPs. I have converted such databases across major versions and across major vendors. I am an architect, DBA, and just a programmer. If you want the benefit of such experience, then here it is. If not, fair enough.EDIT: Expounding...Nearly everything done in a stored procedure can be done by issuing comparable SQL statements from an application, particularly including anonymous procedure blocks (the guts of an SP without the name and permanence). Doing it well can avoid the problems and limitations of stored procedures while still retaining most of the benefits.However, don't forget thatbad code can be written in any language, so it is just as possible to write bad SP code as it is to write bad application code. Indeed, based on history and reports of observations in the wild, it seems even more likely to write bad SP code.EDIT: @Chris Lively: regarding putting database code where the DBA can apply his tools...Crippling your application development by using the DBA's limited tools is not an advantage or a step forward, nor is it even necessary.Besides that, having been a senior DBA/architect for about twenty years, I am not generally impressed with what most DBAs do with database code in the applications that they support. I have mentored a lot of DBAs and programmers regarding database code, so please let me describe what I encourage them to do.Every DBA should know how to make the database engine show them every SQL statement that is executed, regardless of source (inside or outside the engine), and they should know how to analyze that SQL's performance characteristics. I recommend that every programmer learn to do the same. If you can do this, then it no longer matters where the SQL originated, so Chris' recommendation to put the SQL in a SP is null and void.If the performance of your system matters, such as when several million customers depend on it every day, then you should be checking the performance of every piece of SQL before it gets deployed to production. I recommend doing so as part of the automated tests that can be run as a part of the automated build for the system.For example, it is very easy to configure an Ant build script to issue each piece of SQL to the database engine for an execution plan analysis. I like to save each execution plan to a text file and commit it to source control, where I can readily see a history of changes. I also make the build script check the execution plan against some simple criteria to ensure that SQL changes have not altered or compromised the performance.Likewise, I check all my SQL into source control, and I make it easily available both to my application (for execution) and to my build script (for verification). At a minimum, my build script for the database can recreate the entire structure from scratch, and I often make it capable of loading or transferring data as well.Obviously, I can handle stored procedures, but they are just one tool among many. It is a mistake (an antipattern) to treat SPs as aGolden Hammer.On the other hand, when the performance really matters, a stored procedure can often be the best and even the only option. For example, when I redesigned a database recently for a major telecommunications provider, a stored procedure was an essential part of the strategy. I was loading forty thousand data files per day, totaling forty million rows, into a single database table (8 TB) that was growing past two billion rows of current data. A public-facing web site accessed that data via a web service, which required pulling a handful of rows from those two billion within just a few seconds. This was done using Oracle 10g, a custom C application, external tables, some bulk data loading, and a stored procedure. However, most of the database code was still in the C application and the stored procedure handled just one specific, performance-intensive piece.

Q5. a.) DescribethecharacteristicsofanOraclesequence.b.)Triggersarecriticaltoproperdatabaseoperationandmanagement.Whataresomeofthewaysthattriggersareused?c.) Describequeryoptimization.Ans . a.) A sequence is a database object that generates numbers in sequential order. Applications most often use these numbers when they require a unique value in a table such as primary key values. Some database management systems use an "auto number" concept or "auto increment" setting on numeric column types. Both the auto numbering columns and sequences provide a unique number in sequence used for a unique identifier.The quickest way to retrieve the data from a table is to have a column in the table whose data uniquely identifies a row. By using this column and a specific value, in the where condition of a select statement the oracle engine will be able to identify and retrieve the row fast.To achieve this, a constraint is attached to a specific column in the table that ensures that the column is never left blank and the data in the column are unique. Since data entry is done by human being so it is quite likely to enter duplicate values.If the value to be entered is machine generated it will always fulfill the constraints and the row will always be accepted for storage. So sequences plays important role for generating unique values.FeaturesThe following list describes the characteristics of sequences: Sequences are available to all users of the database. Sequences are created using SQL statements.Sequences have a minimum and maximum value (the defaults are minimum=0 and maximum=263-1); they can be dropped, but not reset Once a sequence returns a value, the sequence can never return that same value. While sequence values are not tied to any particular table, a sequence is usually used to generate values for only one table. Sequences increment by an amount specified when created (the default is 1).

b.) Oracle allows you to define procedures that are implicitly executed when an INSERT, UPDATE, or DELETE statement is issued against the associated table. These procedures are called database triggers.Triggers are similar to stored procedures, discussed inChapter14, "Procedures and Packages". A trigger can include SQL and PL/SQL statements to execute as a unit and can invoke stored procedures. However, procedures and triggers differ in the way that they are invoked. While a procedure is explicitly executed by a user, application, or trigger, one or more triggers are implicitly fired (executed) by Oracle when a triggering INSERT, UPDATE, or DELETE statement is issued, no matter which user is connected or which application is being used.For example,Figure 15 - 1shows a database application with some SQL statements that implicitly fire several triggers stored in the database.

Figure 15 - 1.TriggersNotice that triggers are stored in the database separately from their associated tables.Triggers can be defined only on tables, not on views. However, triggers on the base table(s) of a view are fired if an INSERT, UPDATE, or DELETE statement is issued against a view.How Triggers Are UsedIn many cases, triggers supplement the standard capabilities of Oracle to provide a highly customized database management system. For example, a trigger can permit DML operations against a table only if they are issued during regular business hours. The standard security features of Oracle, roles and privileges, govern which users can submit DML statements against the table. In addition, the trigger further restricts DML operations to occur only at certain times during weekdays. This is just one way that you can use triggers to customize information management in an Oracle database.In addition, triggers are commonly used to automatically generate derived column values prevent invalid transactions enforce complex security authorizations enforce referential integrity across nodes in a distributed database enforce complex business rules provide transparent event logging provide sophisticated auditing maintain synchronous table replicates gather statistics on table accessExamples of many of these different trigger uses are included in theOracle7 Server Application Developer's Guide.A Cautionary Note about Trigger UseWhen a trigger is fired, a SQL statement within its trigger action potentially can fire other triggers, as illustrated inFigure 15 - 2. When a statement in a trigger body causes another trigger to be fired, the triggers are said to becascading.

Figure 15 - 2.Cascading TriggersWhile triggers are useful for customizing a database, you should only use triggers when necessary. The excessive use of triggers can result in complex interdependences, which may be difficult to maintain in a large application.Database Triggers vs. Oracle Forms TriggersOracle Forms can also define, store, and execute triggers. However, do not confuse Oracle Forms triggers with the database triggers discussed in this chapter.Database triggers are defined on a table, stored in the associated database, and executed as a result of an INSERT, UPDATE, or DELETE statement being issued against a table, no matter which user or application issues the statement.Oracle Forms triggers are part of an Oracle Forms application and are fired only when a specific trigger point is executed within a specific Oracle Forms application. SQL statements within an Oracle Forms application, as with any database application, can implicitly cause the firing of any associated database trigger. For more information about Oracle Forms and Oracle Forms triggers, see theOracle Forms User's Guide.Triggers vs. Declarative Integrity Constraints

c.) Queryoptimizationis the overall process of choosing the most efficient means of executing a SQL statement. The database optimizes each SQL statement based onstatistics collected about the actual data being accessed. The optimizer uses the number of rows, the size of the data set, and other factors to generate possible execution plans, assigning a numeric cost to each plan. The database uses the plan with the lowest cost.In Oracle Database optimization,costrepresents the estimated resource usage for an execution plan. The optimizer is sometimes called thecost-based optimizer (CBO)to contrast with the legacy rule-based optimizer. The CBO bases the cost of access paths and join methods on the estimated system resources, which includes I/O, CPU, and memory. The plan with the lowest cost is selected.Note:The optimizer may not make the same decisions from one version of Oracle Database to the next. In recent versions, the optimizer might make different decision because better information is available and more optimizer transformations are possible.4.1.3Execution PlansAnexecution plandescribes a recommended method of execution for a SQL statement. The plans shows the combination of the steps Oracle Database uses to execute a SQL statement. Each step either retrieves rows of data physically from the database or prepares them for the user issuing the statement.InFigure 4-1, the optimizer generates two possible execution plans for an input SQL statement, uses statistics to calculate their costs, compares their costs, and chooses the plan with the lowest cost.Figure 4-1 Execution Plans

Description of "Figure 4-1 Execution Plans"4.1.3.1Query BlocksAs shown inFigure 4-1, the input to the optimizer is a parsed representation of a SQL statement. EachSELECTblock in the original SQL statement is represented internally by aquery block. A query block can be a top-level statement, subquery, or unmerged view (see"View Merging").InExample 4-1, the SQL statement consists of two query blocks. The subquery in parentheses is the inner query block. The outer query block, which is the rest of the SQL statement, retrieves names of employees in the departments whose IDs were supplied by the subquery.Example 4-1 Query BlocksSELECT first_name, last_nameFROM hr.employeesWHERE department_id IN (SELECT department_id FROM hr.departments WHERE location_id = 1800);The query form determines how query blocks are interrelated.See Also:Oracle Database Conceptsfor an overview of SQL processing4.1.3.2Query SubplansFor each query block, the optimizer generates a query subplan. The database optimizes query blocks separately from the bottom up. Thus, the database optimizes the innermost query block first and generates a subplan for it, and then generates the outer query block representing the entire query.The number of possible plans for a query block is proportional to the number of objects in theFROMclause. This number rises exponentially with the number of objects. For example, the possible plans for a join of five tables are significantly higher than the possible plans for a join of two tables.Analogy for the OptimizerOne analogy for the optimizer is an online trip advisor. A cyclist wants to know the most efficient bicycle route from point A to point B. A query is like the directive "I need the most efficient route from point A to point B" or "I need the most efficient route from point A to point B by way of point C." The trip advisor uses an internal algorithm, which relies on factors such as speed and difficulty, to determine the most efficient route. The cyclist can influence the trip advisor's decision by using directives such as "I want to arrive as fast as possible" or "I want the easiest ride possible."In this analogy, an execution plan is a possible route generated by the trip advisor. Internally, the advisor may divide the overall route into several subroutes (subplans), and calculate the efficiency for each subroute separately. For example, the trip advisor may estimate one subroute at 15 minutes with medium difficulty, an alternative subroute at 22 minutes with minimal difficulty, and so on.The advisor picks the most efficient (lowest cost) overall route based on user-specified goals and the available statistics about roads and traffic conditions. The more accurate the statistics, the better the advice. For example, if the advisor is not frequently notified of traffic jams, road closures, and poor road conditions, then the recommended route may turn out to be inefficient (high cost).

PART C Q1. a.) ExplainORDERBYandGROUPBYclausewithanexample.b.)Whatisthedifferencebetweenanonprocedurallanguageandaprocedurallanguage?Giveanexampleofeach.Ans . a.) The GROUP BY clause will gather all of the rows together that contain data in the specified column(s) and will allow aggregate functions to be performed on the one or more columns. This can best be explained by an example:GROUP BYclause syntax: SELECT column1, SUM(column2) FROM "list-of-tables" GROUP BY "column-list";Let's say you would like to retrieve a list of the highest paid salaries in each dept: SELECT max(salary), dept FROM employee GROUP BY dept;This statement will select the maximum salary for the people in each unique department. Basically, the salary for the person who makes the most in each department will be displayed. Their, salary and their department will be returned.Multiple Grouping Columns- What if I wanted to display their lastname too?Use these tables for the exercises

items_ordered

customers

For example, take a look at the items_ordered table. Let's say you want to group everything of quantity 1 together, everything of quantity 2 together, everything of quantity 3 together, etc. If you would like to determine what the largest cost item is for each grouped quantity (all quantity 1's, all quantity 2's, all quantity 3's, etc.), you would enter: SELECT quantity, max(price) FROM items_ordered GROUP BY quantity;Enter the statement in above, and take a look at the results to see if it returned what you were expecting. Verify that the maximum price in each QuantityGroupis really the maximum price.Review Exercises1. How many people are in each unique state in the customers table? Select the state and display the number of people in each. Hint:countis used to count rows in a column,sumworks on numeric data only.2. From the items_ordered table, select the item, maximum price, and minimum price for each specific item in the table. Hint: The items will need to be broken up into separate groups.3. How many orders did each customer make? Use the items_ordered table. Select the customerid, number of orders they made, and the sum of their orders. Click the Group By answers link below if you have any problems.

b.) There are two types of Data manipulation language (DML). One is known as nonprocedural DML and other is known as procedural DML.

Nonprocedural DML: It is also known as high level Data Manipulation language. It is used to specify complex database operations. We can enter these high level DML statements from a display monitor with the help of Database Management Systems or these statements can also be entered through a terminal. We can also embed these high level DML statements in a programming language.Procedural DML: It is also known as low level DML. It is used to get data or objects from the database. It processes each operation separately. That's why it has to use programming language constructs to get a record or to process each record from a set of records. Because of this property low level DML is also called set at a time or set oriented DMLs.Low level and high level DMLs are considered as part of the query language because both languages may be used interactively. Normally casual database (end) users use a nonprocedural language.

Q2.a). Whatareviews?Mostdatabasemanagementsystemssupportthecreationofviews.Givereasons.b.)HowcanyouusentheCOMMIT,SAVEPOINTandROLLBACKcommandstosupporttransactions?Ans a). Adatabaseis an organized collection ofdata. The data are typically organized to model relevant aspects of reality in a way that supports processes requiring this information. For example, modeling the availability of rooms in hotels in a way that supports finding a hotel with vacancies.Database management systems (DBMSs) are specially designed applications that interact with the user, other applications, and the database itself to capture and analyze data. A general-purposedatabase management system (DBMS)is asoftwaresystem designed to allow the definition, creation, querying, update, and administration of databases. Well-known DBMSs includeMySQL,MariaDB,PostgreSQL,SQLite,Microsoft SQL Server,Oracle,SAP,dBASE,FoxPro,IBM DB2,LibreOffice BaseandFileMaker Pro. A database is not generallyportableacross different DBMS, but different DBMSs can interoperate by usingstandardssuch asSQLandODBCorJDBCto allow a single application to work with more than one database

b.) JDBC Connection is inauto-commitmode, which it is by default, then every SQL statement is committed to the database upon its completion.That may be fine for simple applications, but there are three reasons why you may want to turn off auto-commit and manage your own transactions: To increase performance To maintain the integrity of business processes To use distributed transactionsTransactions enable you to control if, and when, changes are applied to the database. It treats a single SQL statement or a group of SQL statements as one logical unit, and if any statement fails, the whole transaction fails.To enable manual- transaction support instead of theauto-commitmode that the JDBC driver uses by default, use the Connection object'ssetAutoCommit()method. If you pass a boolean false to setAutoCommit( ), you turn off auto-commit. You can pass a boolean true to turn it back on again.For example, if you have a Connection object named conn, code the following to turn off auto-commit:

Q3. a.) Whatisanindex?Whatarethedisadvantagesofusinganindex?b. )DescribetheformatfortheUPDATEcommand.Ans a.) There are tradeoffs to almost any feature in computer programming, and indexes are no exception. While indexes provide a substantial performance benefit to searches, there is also a downside to indexing. Let's talk about some of those drawbacks now.Indexes and Disk SpaceIndexes are stored on the disk, and the amount of space required will depend on the size of the table, and the number and types of columns used in the index. Disk space is generally cheap enough to trade for application performance, particularly when a database serves a large number of users. To see the space required for a table, use the sp_spaceused system stored procedure in a query window.EXECsp_spaceused OrdersGiven a table name (Orders), the procedure will return the amount of space used by the data and all indexes associated with the table, like so:Name rows reserved data index_size unused ------- -------- ----------- ------ ---------- -------Orders 830 504 KB 160 KB 320 KB 24 KBAccording to the output above, the table data uses 160 kilobytes, while the table indexes use twice as much, or 320 kilobytes. The ratio of index size to table size can vary greatly, depending on the columns, data types, and number of indexes on a table.Indexes and Data ModificationAnother downside to using an index is the performance implication on data modification statements. Any time a query modifies the data in a table (INSERT, UPDATE, or DELETE), the database needs to update all of the indexes where data has changed. As we discussed earlier, indexing can help the database during data modification statements by allowing the database to quickly locate the records to modify, however, we now caveat the discussion with the understanding that providing too many indexes to update can actually hurt the performance of data modifications. This leads to a delicate balancing act when tuning the database for performance.A Disadvantage to Clustered IndexesIf we update a record and change the value of an indexed column in a clustered index, the database might need to move the entire row into a new position to keep the rows in sorted order. This behavior essentially turns an update query into a DELETE followed by an INSERT, with an obvious decrease in performance. A table's clustered index can often be found on the primary key or a foreign key column, because key values generally do not change once a record is inserted into the database.

b. ) To create a PROC SQL table from a query result, use a CREATE TABLE statement, and place it before the SELECT statement. When a table is created this way, its data is derived from the table or view that is referenced in the query's FROM clause. The new table's column names are as specified in the query's SELECT clause list. The column attributes (the type, length, informat, and format) are the same as those of the selected source columns.The following CREATE TABLE statement creates the DENSITIES table from the COUNTRIES table. The newly created table is not displayed in SAS output unless you query the table. Note the use of the OUTOBS option, which limits the size of the DENSITIES table to 10 rows.proc sql outobs=10; title 'Densities of Countries'; create table sql.densities as select Name 'Country' format $15., Population format=comma10.0, Area as SquareMiles, Population/Area format=6.2 as Density from sql.countries;

select * from sql.densities;Table Created from a Query Result Densities of Countries

Country Population SquareMiles Density ------------------------------------------------- Afghanistan 17,070,323 251825 67.79 Albania 3,407,400 11100 306.97 Algeria 28,171,132 919595 30.63 Andorra 64,634 200 323.17 Angola 9,901,050 481300 20.57 Antigua and Bar 65,644 171 383.88 Argentina 34,248,705 1073518 31.90 Armenia 3,556,864 11500 309.29 Australia 18,255,944 2966200 6.15 Austria 8,033,746 32400 247.96The following DESCRIBE TABLE statement writes a CREATE TABLE statement to the SAS log:proc sql; describe table sql.densities;SAS Log for DESCRIBE TABLE Statement for DENSITIESNOTE: SQL table SQL.DE