You are on page 1of 8

Introduction Storing data and retrieving information has been a necessity in all ages of busi ness.

The term data can be defined as a set of isolated and unrelated raw facts with an implicit meaning. Data can be anything such as, name of a person, a numb er, images, sound, etc. For example, Monica, 25, student, etc., is a data. When the da ta is processed and converted into a meaningful and useful form, it is known as information. For example, Monica is 25 years old and she is a student. is an infor mation. For a business to be successful, a fast access to information is vital a s important decisions are based on the information available at any point of tim e. Traditionally, the data was stored in voluminous repositories such as files, books, and ledgers. However, storing data and retrieving information from these repositories was a time-consuming task. With the development of computers, the p roblem of information storage and retrieval was resolved. Computers replaced ton s of paper, file folders, and ledgers as the principal media for storing importa nt information. Since then numerous techniques and devices have been developed to manage and org anize the data so that useful information can be accessed easily and efficiently . The eternal quest for data management has led to the development of the databa se technology. A databasecan be defined as a collection of related data from whi ch users can efficiently retrieve the desired information. A database can be any thing from a simple collection of roll numbers, names, addresses, and phone numb ers of students to a complex collection of sound, images, and even video or film clippings. Though databases are generally computerized, instances of non-comput erized databases from everyday life can be cited in abundance. A dictionary, a p hone book, a collection of recipes, and a TV guide are all common examples of no n-computerized databases. The examples of computerized databases include custome r files, employee rosters, books catalogue, equipment inventories, and sales tra nsactions. In addition to the storage and retrieval of data, certain other operations can a lso be performed on a database. These operations include adding, updating, and d eleting data. All these operations on a database are performed using a database management system. A Database Management System (DBMS) is an integrated set of p rograms used to create and maintain a database. The main objective of a DBMS is to provide a convenient and effective method of defining, storing, retrieving, a nd manipulating the data contained in the database. In addition, the DBMS must e nsure the security of the database from unauthorized access and recovery of the data during system failures. It must also provide techniques for data sharing am ong several users. The database and the DBMS software are collectively known as database system. Objectives Advantages of Database System Database approach came into existence due to the bottlenecks of file processing system. In the database approach, the data is stored at a central location and i s shared among multiple users. Thus, the main advantage of DBMS is centralized d ata management. The centralized nature of database system provides several advan tages, which overcome the limitations of the conventional file processing system . These advantages are listed here. Controlled data redundancy: During database design, various files are integrated and each logical data item is stored at central location. This eliminates repli cating the data item in different files, and ensures consistency and saves the s torage space. Note that the redundancy in the database systems cannot be elimina ted completely as there could be some performance and technical reasons for havi ng some amount of redundancy. However, the DBMS should be capable of controlling this redundancy in order to avoid data inconsistencies. Enforcing data integrity: In database approach, enforcing data integrity is much easier. Various integrity constraints are identified by database designer durin g database design. Some of these data integrity constraints can be enforced auto matically by the DBMS, and others may have to be checked by the application prog rams. Data sharing: The data stored in the database can be shared among multiple users

or application programs. Moreover, new applications can be developed to use the same stored data. Due to shared data, it is possible to satisfy the data requir ements of the new applications without having to create any additional data or w ith minimal modification. Ease of application development: The application programmer needs to develop the application programs according to the users needs. The other issues like concurr ent access, security, data integrity, etc., are handled by the DBMS itself. This makes the application development an easier task. Data security: Since the data is stored centrally, enforcing security constraint s is much easier. The DBMS ensures that the only means of access to the database is through an authorized channel. Hence, data security checks can be carried ou t whenever access is attempted to sensitive data. To ensure security, a DBMS pro vides security tools such as user codes and passwords. Different checks can be e stablished for each type of access (addition, modification, deletion, etc.) to e ach piece of information in the database. Multiple user interfaces: In order to meet the needs of various users having dif ferent technical knowledge, DBMS provides different types of interfaces such as query languages, application program interfaces, and graphical user interfaces ( GUI) that include forms-style and menu-driven interfaces. A form-style interface displays a form to each user and user interacts using these forms. In menu-driv en interface, the user interaction is through lists of options known as menus. Backup and recovery: The DBMS provides backup and recovery subsystem that is res ponsible for recovery from hardware and software failures. For example, if the f ailure occurs in between the transaction, the DBMS recovery subsystem either rev erts back the database to the state which existed prior to the start of the tran saction or resumes the transaction from the point it was interrupted so that its complete effect can be recorded in the database. In addition to centralized data management, DBMS also has some other advantages, which are discussed here. Program-data independence: The independence between the programs and the data is known as program-data independence (or simply data independence). It is an impo rtant characteristic of DBMS as it allows changing the structure of the database without making any changes in the application programs that are using the datab ase. To provide a high degree of data independence, the definition or the descri ption of the database structure (structure of each file, the type and storage fo rmat of each data item) and various constraints on the data are stored separatel y in DBMS catalog. The information contained in the catalog is called the metada ta (data about data). Data abstraction: The property of DBMS that allows program -data independence is known as data abstraction. Data abstraction allows the dat abase system to provide an abstract view of the data to its users without giving the physical storage and implementation details. Supports multiple views of the data: A database can be accessed by many users an d each of them may have a different perspective or view of the data. A database system provides a facility to define different views of the data for different u sers. A view is a subset of the database that contains virtual data derived from the database files but it does not exist in physical form. That is, no physical file is created for storing the data values of the view; rather, only the defin ition of the view is stored. 1.7. DBMS Architecture and Data Independence The DBMS architecture describes how data in the database is viewed by the users. It is not concerned with how the data is handled and processed by the DBMS. The database users are provided with an abstract view of the data by hiding certain details of how data is physically stored. This enables the users to manipulate the data without worrying about where it is located or how it is actually stored . In this architecture, the overall database description can be defined at three l evels, namely, internal, conceptual, and external levels and thus, named three-l evel DBMS architecture. This architecture is proposed by ANSI/SPARC (American Na tional Standards Institute/Standards Planning and Requirements Committee) and he nce, is also known as ANSI/SPARC architecture. The three levels are discussed he

re. Internal level: It is the lowest level of data abstraction that deals with the p hysical representation of the database on the computer and thus, is also known a s physical level. It describes how the data is physically stored and organized o n the storage medium. At this level, various aspects are considered to achieve o ptimal runtime performance and storage space utilization. These aspects include storage space allocation techniques for data and indexes, access paths such as i ndexes, data compression and encryption techniques, and record placement. Conceptual level: This level of abstraction deals with the logical structure of the entire database and thus, is also known as logical level. It describes what data is stored in the database, the relationships among the data and complete vi ew of the users requirements without any concern for the physical implementation. That is, it hides the complexity of physical storage structures. The conceptual view is the overall view of the database and it includes all the information th at is going to be represented in the database. External level: It is the highest level of abstraction that deals with the users view of the database and thus, is also known as view level. In general, most of the users and application programs do not require the entire data stored in the database. The external level describes a part of the database for a particular g roup of users. It permits users to access data in a way that is customized accor ding to their needs, so that the same data can be seen by different users in dif ferent ways, at the same time. In this way, it provides a powerful and flexible security mechanism by hiding the parts of the database from certain users, as th e user is not aware of existence of any attributes that are missing from the vie w. These three levels are used to describe the schema of the database at various le vels. Thus, the three-level architecture is also known as three-schema architect ure. The internal level has an internal schema, which describes the physical sto rage structure of the database. The conceptual level has a conceptual schema, wh ich describes the structure of entire database. The external level has external schemas or user views, which describe the part of the database according to a pa rticular users requirements, and hide the rest of the database from that user. Th e physical level is managed by the operating system under the direction of DBMS. The three-schema architecture is shown in Figure 1.1. Fig. 1.1. Three-schema architecture To understand the three-schema architecture, consider the three levels of the BO OK file in Online Book database as shown in Figure 1.2. In this figure, two view s (view 1 and view 2) of the BOOK file have been defined at the external level. Different database users can see these views. The details of the data types are hidden from the users. At the conceptual level, the BOOK records are described b y a type definition. The application programmers and the DBA generally work at t his level of abstraction. At the internal level, the BOOK records are described as a block of consecutive storage locations such as words or bytes. The database users and the application programmers are not aware of these details; however, the DBA may be aware of certain details of the physical organization of the data . In three-schema architecture, each user group refers only to its own external vi ew. Whenever a user specifies a request to generate a new external view, the DBM S must transform the request specified at external level into a request at conce ptual level, and then into a request at physical level. If the user requests for data retrieval, the data extracted from the database must be presented accordin g to the need of the user. This process of transforming the requests and results between various levels of DBMS architecture is known as mapping. The main advantage of three-schema architecture is that it provides data indepen dence. Data independence is the ability to change the schema at one level of the database system without having to change the schema at the other levels. Data i

ndependence is of two types, namely, logical data independence and physical data independence. Logical data independence: It is the ability to change the conceptual schema wit hout affecting the external schemas or application programs. The conceptual sche ma may be changed due to change in constraints or addition of new data item or r emoval of existing data item, etc., from the database. The separation of the ext ernal level from the conceptual level enables the users to make changes at the c onceptual level without affecting the external level or the application programs . Physical data independence: It is the ability to change the internal schema with out affecting the conceptual or external schema. An internal schema may be chang ed due to several reasons such as for creating additional access structure, chan ging the storage structure, etc. The separation of internal schema from the conc eptual schema facilitates physical data independence. Logical data independence is more difficult to achieve than the physical data in dependence because the application programs are always dependent on the logical structure of the database. Therefore, the change in the logical structure of the database may require change in the application programs. Data base Design 1. Logical database design: Once an appropriate DBMS is chosen, the next st ep is to map the high-level conceptual schema onto the implementation data model of the selected DBMS. In this phase, the database designer moves from an abstra ct data model to the implementation of the database. In case of relational model , this phase generally consists of mapping the E-R model into a relational schem a. 2. Physical database design: In this phase, the physical features such as s torage structures, file organization, and access paths for the database files ar e specified to achieve good performance. The various options for file organizati on and access paths include various types of indexing, clustering of records, ha shing techniques, etc. DBMS Languages The main objective of a database management system is to allow its users to perf orm a number of operations on the database such as insert, delete, and retrieve data in abstract terms without knowing about the physical representations of dat a. To provide the various facilities to different types of users, a DBMS normall y provides one or more specialized programming languages called Database (or DBM S) Languages. DDL Data Definition Language (DDL) statements are used to define the database struct ure or schema. Some examples: o CREATE - to create objects in the database o ALTER - alters the structure of the database o DROP - delete objects from the database o TRUNCATE - remove all records from a table, including all spaces allocat ed for the records are removed DML Data Manipulation Language (DML) statements are used for managing data within sc hema objects. Some examples: o SELECT - retrieve data from the a database o INSERT - insert data into a table o UPDATE - updates existing data within a table o DELETE - deletes all records from a table, the space for the records rem ain DCL Data Control Language (DCL) Data control language is used to create user roles, grant permissions, and contr ol access to database by securing it. Some examples:

Transaction Control (TCL) statements are used to manage the changes made by DML statements. It allows statements to be grouped together into logical transaction s. o COMMIT - save work done o SAVEPOINT - identify a point in a transaction to which you can later rol l back o ROLLBACK - restore database to original since the last COMMIT o SET TRANSACTION - Change transaction options like isolation level and wh at rollback segment to use Concepts of Entity-Relationship Model The entity-relationship (E-R) model is the most popular conceptual model used fo r designing a database. It was originally proposed by Dr. Peter Chen in 1976 as a way to unify the network and relational database views. The E-R model views th e real world as a set of basic objects (known as entities), their characteristic s (known as attributes), and associations among these objects (known as relation ships). The entities,attributes, and relationships are the basic constructs of a n E-R model. Mapping E-R Model to Relational Model E-R model provides a conceptual model of the real-world concepts, which is repre sented in a database. To represent the E-R database schema to the relation schem a, the relational model is used. In other words, E-R model is mapped to the rela tional model by representing E-R database schema by a collection of relation sch emas. The mapping from E-R model to relational model is possible due to the reason tha t both the models represent the real world logically and follow similar design p rinciples. Relational Database Concept o o o Dr E. F. Codd proposed the relational model for database systems in 1970 It is the basis for the relational database management system(RDBMS). The relational model consists of the following: Collection of objects or relations Set of operators to act on the relations Data Integrity for accuracy and consistency

Relational Model The principles of the relational model were first outlined by Dr. E.F. Codd in a Jume 1970 paper called A relational Model of Data for Large Shared Data Banks. I n this paper, Dr. Codd proposed the relational model for the database. The more popular models used at the time were hierarchical and network, or even simple flat file data structures. Relational database management systems soon be came very popular especially for their ease of use and flexibility in structure. In addition , a number of innovative vendors, such as Oracle, supplemented the RDBMS with a suite of powerful application development and user products, provid ing a total solution. Components of the relational Model Collections of objects or relations that store the data A set of operators that can act on the relations to produce other relations Data integrity for accuracy and consistency

o o TCL

GRANT - gives user s access privileges to database REVOKE - withdraw access privileges given with the GRANT command

Definition of a Relational Database A relational database is a collection of relations or two-dimensional table

A relational database is a collection of relations or two-dimensional tables to store information. For Example, you might want to store information about all the employees in your company. In a relational database, you create several tables to store different pieces of information about your employees, such as an employee table, a depart ment table and a salary table Relational Database Terminology

EMPNO 7839 10 7698 30 7782 10 7566 20 7654 30 7499 30 7544 7900 30 7521 30 7902 7369 7788 7376 20 7934 10





SAL 17-NOV-81

COMM 5000 2850



11-MAY-81 7839 12-APR-81 18-SEP-81 7698

10-JUN-81 2975 1250 1600



10-FEB-81 7698

300 1500

18-SEP-81 950 1250 3000

03-DEC-81 7698 7566 22-FEB-81 03-DEC-81 800 19-DEC-82


7902 17-DEC-80 ANALYST 7566 CLERK CLERK 7788

20 3000

12-JAN-83 7782

1100 1300


Terminology Used in a Relational Database A relational database can contain one or many tables. A table is the basic stora ge structure of an RDBMS. A table holds all the data necessary about something i n the real world for example employees, invoices, customers.

The table shows the contents of the EMP table or relation. The numbers indicate the following: 1. A single row or representing all data required for a particular employee . Each row in a table should be identified by a primary key, which allows no dup licate rows. The order of rows is insignificant; specify the row order when th e data is retrieved. 2. A column or attribute containing the employee number which is also the p rimary key. The employee number identifies a unique employee in the EMP table. A primary key must contain a value. 3. A column that is not a key value. A column represents one kind of data i n a table; in the example, the job title of all the employees. Column order is i nsignificant when storing data; specify the column order when the data is retr ieved. 4. a column containing the department number, which is also a foreign key. A foreign key is a column that defines how tables relate to each other. A foreig n key refers to a primary key or a unique key in another table. In the example, DEPTNO uniquely identifies a department in the DEPT table. 5. A field can be found at the intersection of a row and a column. There ca n be only one value in it. 6. A field may have no value in it. This is called a null value. In the EMP table, only employees who have a role of salesman have a value in the COMM (com mission) field. Relating Multiple Tables Each row of data in a table is uniquely identified by a primary key (PK). You can logically relate data from multiple tables using foreign keys (FK).

Each table contains data that describes exactly one entity. For example, the EMP table contains information about employees. Categories of data are listed acros s the top of each table, and individual cases are listed below. Using a table fo rmat, you can readily visualize, understand and use information. Because data about different entities is stored in different tables, you may nee d to combine two or more tables to answer a particular question. For example, yo n may need to know the location of the department where an employee works. In th is scenario, you need information from the EMP table (which contains data about employees) and the DEPT table (which contains information about departments). An RDBMS enables you to relate the data in one table to the data in another by usi ng foreign key. Foreign key is a column or a set of columns that refer to a prim ary key in the same table or another table. The ability to relate data in one table so data in another enables you to organi ze information in separate, manageable units. Employee data can be kept logicall y distinct from department data by storing it in a separate table. Guidelines for Primary Keys and Foreign Keys No duplicate values are allowed in a primary key. Primary keys generally cannot be changed. Foreign keys are based on data values and are purely logical, not physical point

ers. A foreign key value must match an existing primary key value or unique key value or else be null. You cannot define foreign keys without existing primary (unique) keys. Relational Database Properties A relational database: Can be accessed and modified by executing structured query language (SQL) statem ents Contains a collection of tables with no physical pointers Uses a set of operators Properties of a Relational Database In relational database, you do not specify the access route to the tables, and y on do not need to know how data is arranged physically. To access the database, you execute a structured query language (SQL) statement, which is the American National Standard Institute (ANSI) standard language oper ating upon relational databases. The language contains a large set of operators for partitioning and combining relations. Database can be modified by using the SQL statements. Structured Query Language SQL allows you to communicate with the server and has the following advantages Efficient Easy to learn and use Functionally complete (SQL allows you to define, retrieve, and manipulate data i n the tables)