Rdbms Concepts 1

  • Published on

  • View

  • Download

Embed Size (px)


<p>Database Management System Concepts RDBMS CONCEPTS Introduction: RDBMS is the acronym for Relational Database Management System. The concept of relational database is known since 1980s but the idea of database Management System is definitely quite old. The most famous RDBMS packages are Oracle, Sybase, and Informix. Before we move to the RDBMS it would be helpful if we first have a brief idea about DBMS and the reason for RDBMS being preferred to DBMS. Database Management System: A database management system is essentially a collection of interrelated data and a set of programs to access the data. This collection of data is called database. The primary objective of a DBMS is to provide a convenient environment to retrieve and store database information. Database System supports single user and multi-user. While DBMS lets only one person to access the database at a given time, RDBMS allows many users to simultaneously access the database. A database system consists of two parts namely the Database Management System and the Database Application. Database Management System is the program that organizes and maintains the information whereas the Database application is the program that lets us view, retrieve and update information stored in the database. DBMS has to protect database against unintentional changes that could be caused by users and application like disk crash etc. in case of multi-user system, it must be capable of notifying any database changes to the other user. Database Management System Services: 1. Data definition: It is a method of data definition and storage. 2. Data Maintenance: It checks whether each record has fields containing all information about one particular item. For example if an employee table is considered, it is seen that all information about the employee like name, address, designation, salary, dept-name are recorded. 3. Data Manipulation: allows data in the database to be inserted, updated, deleted and stored. 4. Data display: this ensures the accuracy of the data. 5. Data Integrity: this ensures the accuracy of the data. Before proceeding further, it is necessary to be familiar with certain terms of DBMS.</p> <p>1 / 122</p> <p>By Naveen Jaiswal</p> <p>Database Management System Concepts Entity: an entity is any object, place, person, concept, or activity about which an enterprise records data. The below table gives an idea about an entity. Name Biscuits Pen price 12.00 8.00 description food item stationary</p> <p>A vendor has to maintain a list of all the items that he sells like name price, description etc. These are called entity types. For instance, the values that they store may be Biscuits, 12.00, food item respectively. These are called entity instances. Each of these is termed as an entity and Entity is always identified by a rectangle. There exists a relation ship between two entities. For example, a vendor sells many items and many vendors can sell a particular item. Attribute: an attribute is the characteristic property of an existing entity. The difference between attribute type and attribute instance has to be understood. Attribute type is the property of entity type, and attribute instance of entity instance. An ellipse always represents the attributes. Ex: suppose a student is an entity then student name, number, address would be the attributes of the entity student and the specific- Rama, no-15, S.V.nagar etc. are the attribute instances. Below figure illustrates this with an e-r diagram.</p> <p>Addres</p> <p>Address Student</p> <p>student</p> <p>Roll no.</p> <p>rollno</p> <p>Name Name Any attribute or set of attributes can be uniquely identify a row in a table. This attribute acts as a candidate for a primary key and is referred to as the candidate key. Candidate key can be chosen as primary key depending on factors like uniqueness, usage etc. the relations among data must be suited in detail before proceeding further with certain things. Relationship among data: A relationship is defined as an association among entities. A relationship type is an association of entity types, while a relationship instance is an association of entity instances. A relationship may associate an entity with itself. Several relationships may exist between the same entities. The three different types of relationships recognized among various data stored in the database are:</p> <p>2 / 122</p> <p>By Naveen Jaiswal</p> <p>Database Management System Concepts One-to-one One-to-many(or many-to-one) Many-to-many</p> <p>One-to-one: Consider for example a set of students in a class. Each student can have only one roll number. Similarly, each roll number can be associated only with one student. This is the case of one-to-one relation ship. Below shows the relationship.</p> <p>Student 1</p> <p>Assigne</p> <p>Rollno1</p> <p>Student 2</p> <p>Assigne</p> <p>Rollno2</p> <p>Many-to-one A student can register for only one particular course at a time. Where as many students could register for that particular course. Below figure gives the details</p> <p>Student1 Regist Student 2 Student 3 Course.</p> <p>Many-to-many A vendor can sell many items and many vendors can sell a particular item. This can be understood from the below figure Vendor 1 Item 1 3 / 122 By Naveen Jaiswal</p> <p>Database Management System Concepts</p> <p>Vendor 2 Database Models:</p> <p>Item 2</p> <p>Database models are broadly classified into two categories. They are Object-based logical models. Record-base logical models.</p> <p>The object-base logical model can be defined as a collection of conceptual tools for describing data, data relationships, and data constraints. The record-base logical model describes the data structures and access techniques of a DBMS. There are three types of record-based logical models. They are the hierarchical model, the network model, and the relational model. Consider an example of a company. There are many employees who work in various departments earning a different salary. EMPLOYEE, DEPARTMENT, SALARY Represents the entities about which data has to be recorded. It would be really meaningless if the data just exist in the database. Hence it is necessary that these data should be related to each other. Therefore a database should maintain information about these data and relationships. File management system: The File management system was the first method used to store data in a computerized database. The data item is stored sequentially in one large file. A particular relation ship cannot be drawn between the items other than the sequence in which it is stored. If one has to locate a particular data item, the search starts at the beginning and each item is checked subsequently till the required item is found. These drawbacks in the system necessitated improvisation. Locating a record is tedious. If data has to be inserted the whole file has to be read and rewritten. This can be overcome by adopting an indexing system. An index file contains a subset of the data files based on one or more key fields. There is a pointer to each record in the database. It satisfies ones requirement at the earliest. Any changes in the database have to be updated. The process of updation is also quite tedious. For ex: adding the age to each employees record would require the DBMS to read each record. Then the DBMS writes in to a temporary file and adds the new information after the last field of each record. After the new file is written, the original file is deleted and the temporary file is renamed. The necessity for establishing a relationship among records and 4 / 122 By Naveen Jaiswal</p> <p>Database Management System Concepts quicker way to access the records led to the development of another model called hierarchical database model. Hierarchical database systems: DBMS Root</p> <p>Dept1</p> <p>Dept 2</p> <p>Dept 3</p> <p>Id1</p> <p>Id 1.1</p> <p>Id 2</p> <p>Id 2.2</p> <p>Id 3</p> <p>Id 3.3</p> <p>Jack</p> <p>Clerk</p> <p>3000</p> <p>Rama</p> <p>MGR</p> <p>7000</p> <p>This can be said to have parent-child relationship. The origin of the data tree is the root. Data located at different levels along a particular branch from the root is called the node. The lat node in the series is called leaf. This model supports one-to-many relationship. From the figure above it ca be seen that the nodes in the third level are interrelated. Each child has pointers to numerous siblings and there is just one pointer to the parent thus proving a one-to-many relationship. Proceeding to how to access the data- suppose an information is required, id2, it is not necessary for the DBMS to search the entire file to locate the data. Instead, it first follows the dept2 branch and fetches the data. If an index were used in the HDS as in the FMS the process would definitely he hastened. Here the index would be on a particular level of data. It is not possible to insert a new level in the table without alerting the structure. FMS does not support many-to-many relationship. Suppose a new level is required between the root and the department, the only alternative is to frame an entirely new structure. To set this relationship, multiple copies of the same data must be stored at multiple levels that could cause redundancy of data. To overcome this drawback, the network database model was introduced.</p> <p>Network database system: This model comes under record-based logical model. The main idea behind this model is to bring about many-to-many relationships. The relationship between the different data 5 / 122 By Naveen Jaiswal</p> <p>Database Management System Concepts items is called as the sets. This system also uses a pointer to locate a particular record. Let us consider the item-vendor example as shown in figure.</p> <p>Vendor 1</p> <p>Vendor 2</p> <p>Vendor 3</p> <p>Item 1</p> <p>Item 2</p> <p>Item 3</p> <p>Item 4</p> <p>If one has to know which vendor(s) is selling a particular item or which particular item the vendor sells, it is completely dependent on the pointer to map out the relationship. But even here in case of large volumes of data it is very difficult to locate the item because it will increase the complexity as it uses pointers, the mapping of data would become very difficult. Since all the models use pointers it increases complexity. To overcome all the drawbacks the idea of relational database system came up. Relational database model: Dr. E.F. Codd first introduced the relational database model in 1970. This model allows data to be represented in a simple row-column format. Each data field is considered as a column and each record is considered as a row of a table. Taking the example of a vendor, the vendors are grouped in one table as given table below. Vendor_details Vno V1 V2 V3 V4 company company1 company2 company3 company4</p> <p>The description of items is given in the below table.</p> <p>Item Pno P1 item desc desc1 6 / 122 vno v1 By Naveen Jaiswal</p> <p>Database Management System Concepts P2 P3 P4 The other table is cost table. Cost Pno P1 P2 P3 P2 vno v1 v1 v2 v3 price 1500 2000 1000 2200 desc2 desc3 desc4 v2 v1 v3</p> <p>Different relationships between the various tables are achieved by mathematical set functions namely JOIN and UNION. It can also be seen from the above tables that each table has one or more columns with same names as in other table. To get details about a particular item from a particular vendor, the DBMS searches the item table for the name of the item and matches the vno column of the vendor_details table to get the name of the company. The price of the item can be found out by comparing the pno and vno columns in the item and cost tables. Any changes will invoke adding and deleting columns to/from the existing tables. It is not necessary to build the entire database from the scratch. Relational operators: The relational model is based on the solid foundation of relational algebra. Relational algebra consists of a collection of operators that operate on relations. Each operator takes one or two relations as its input and produces a new relation as its output. The main objective of relational algebra is data retrieval. Some of such operators are defined below. Restrict: It extracts specified rows from a given relation based on certain conditions. Consider for example a students table from which records of similar ages are fetched, then the results will as be given in the table below. Table result Rno 15 20 22 30 name Rama saritha suresh raja age 22 22 26 30 7 / 122 rno 12 20 name age</p> <p>Rama 22 saritha 22</p> <p>By Naveen Jaiswal</p> <p>Database Management System Concepts</p> <p>Project: Extracts specified attributes or columns from a given relation. For ex: if only name and age of the student is to be extracted then the resultant is as shown below. Table Rno 15 30 Product: All possible relations from two existing relationships can be obtained as is illustrated below. Rno 15 name Rama 20 saritha 22 suresh Results Rno 15 15 20 20 22 22 Union: Data present in more than one table can be fetched without join operator. Data present in one table and absent in the other table is also fetched as shown below. Table1 Name rno table 2 Name rno result Name rno name Rama Rama saritha saritha suresh suresh sub maths eng maths eng maths eng sub maths eng name age rno 12 30 result name Rama 20 saritha 22 suresh raja</p> <p>Rama 22 20 saritha 22 22 suresh 26 raja 30</p> <p>8 / 122</p> <p>By Naveen Jaiswal</p> <p>Database Management System Concepts Asha Rama Saritha Niranjan 1 15 20 10 Anu Anil Saritha Niranjan 11 17 20 10 Asha Rama Saritha Niranjan Anu Annil 1 15 20 10 11 17</p> <p>Intersect: Common records resent in the described tables alone are fetched. Considering the same example as above, when intersect is performed the result would be as shown below. Result Name Saritha Niranjan Difference: Data from table1 is fetched provided it is not present in table 2. The result would be as given below. Table1 Deptno 10 20 35 name accounts sales computers Results Deptno 15 35 Join: name Marketing Computers. deptno 15 10 20 Table2 name marketing accounts sales rno 20 10</p> <p>9 / 122</p> <p>By Naveen Jaiswal</p> <p>Database Management System Concepts The data from one or more tables that have some data in common are fetched. The following example illustrates a join the ecode. Column of table 1 and table 2 is identical. Table1 Ecode name 25 20 30 basic table1 dept-code 101 201 301 Result Ecode 25 20 30 Divide This operator returns those rows from the divided table that has occurrences that match those in the division table as given below. Table 1 X A B C A E y a b c d e table 2 x a d result x A name Rama saritha venu dept-code 101 201 301 ecode dept-name 25 20 30 sales marketing computers</p> <p>Rama 3000 saritha 3500 venu 4000</p> <p>Normalization: Normalization theory is built around the concept of normal forms. Normalization reduces redundancy. Redundancy is unnecessary repetition of data. It can cause problems with storage and retrieval of data. During the process of normalization, dependencies can be identified, which can cause problems during deletion and updation. Normalization theory is based on the fundamental notation of functional dependency. Normalization helps in simplifying the struct...</p>