












Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!













A database is an organized collection of data. The data are typically organized to model relevant aspects of reality in a way that supports processes requiring this information. It is an electronic storage of data. It stores information and relationship among different things. Basic terms to examine the structure of a Database A person, place, event or item is called an entity. Example: Customer, Transaction, Employee, Library, etc., The facts describing an entity are known as data. Example: For a Customer, custno, custname, address…, etc., are maintained in a register which describes the characteristics of the entity Customer. Each entity can be described by its characteristics, which are known as attributes. Example: For a Student, name, regno, class, address etc…. All the related entities are collected together to form an entity set. An entity set is given a singular noun. Example: The student entity set contains data about student only. All related entity in the STUDENT entity set is student. Similarly a company keeps track all of its employees is an entity set called EMPLOYEES. The EMPLOYEE entity set does not contain about the company’s customers, because it would not make any sense. A database is a collection of entity sets. Example: A college database may include entities such as student, faculty, course, term, office, building, exam etc., the entities in a database are likely to interact with other entities. The interactions between the entity sets are called relationship. Example: A faculty member teaches in a building, so the relationship between FACULTY and BUILDING is teaches. 1.1 Types of Relationships The database design requires creating various entity sets and establishing the relationship between the entity sets within the database. The different database management software packages handle the creation and use of relationship in different manners. Depending upon the type on interaction, the relationship is classified in to three categories. i)One –to-one relationship: A one-to-one relationship is written as 1:1 in short form. It exists between two entity sets X and Y. If an entity set X has only one matching entity in entity set Y, and vice versa. Example: A College has one Principal. A Department is lead by one Head.
ii)One-to-Many relationship: A one-to-one relationship is written as 1:M in short form. It exits between two entity sets X and Y. If an entity in entity set X has many matching entities in entity set Y, but an entity in entity set Y has only one matching entity in entity set X. Example: A faculty teaches to Many Students of a class room, but the students had a relationship with one faculty member. iii)Many-to-Many relationship: It also write in M:N (or) M:M It exists of two entity set X and Y. If an entity in entity set X has many matching entities inentity set Y and an entity in entity set Y has many matching entities in entity set X. Example: Many Courses availed for Many Students. To determine the type of relationship, consider the following two questions.
The number of columns in a table is called the degree. Example: A table has four columns then the degree of the table is 4. The set of all possible values that a column may have is called the domain of that column. Two domains are same only if they have the same meaning and use. 1.4.1 Terminology Comparison 1.5 KEY A key is a minimal set of columns used to uniquely define any row in a table. A uniquekey or primary key is a key that uniquely defines the characteristics of each row. 1.5.1 Primary Key When a single column is used as a unique identifier, it is known as primary key.
1.5.3 Composite Key When a combination of columns is used as a unique identifier it is known as a compositeprimary key or composite key. For Example:-Suppose a table consist of Employee data with fields Employee_Name, Employee_Address,Employee_Id , Employee_Designation, Employee_PANNo and Employee_PhoneNo in this table to build a composite key we combine Employee_Id and Employee_PhoneNo to fetch data from table. 1.5.4.Secondary Key Sometimes, a more human approach is used to identify or retrieve a row from a table becauseit is not possible to remember primary key values such as the employee number, Book number,department number etc., that time name of the employee, author of the book may be noted with theprimary key. This key is known as Secondary Key. 1.5.5 Surrogate Key Sometimes none of the column is a candidate for the primary key in a table, so the databasedesigners can be add an extra column as a primary key instead of using composite key. For example the customer purchases different items in different locations,for this situation we have to maintain historical data. By using surrogate key we can introduce the row in the data warehouse to maintain historical data. 1.5.6 Foreign Key A column in a table that references a column in another table is known as foreign key. We have two tables: customers and orders. Each customer has zero or more orders and each order belongs to only one customer. For Example:- We can have a Employee_Id column in the Company table which is pointing to Employee_Id column in a Employee table where it a primary key. So with the help of foreign key we can easily identify the data from tables. 1.6 INTEGRITY RULES In RDBMS it is very important that the data underlying the tables be consistent. Ifconsistency is compromised the data are not usable. This need has led to formulate two integrityrules. 1.6.1 Entity Integrity No column in a primary key may be null. The primary key provides the means of unique identifier of a row or an entity.
1.7.1.1. Union The union of two tables results in retrieval of all the rows that are in both tables. The duplicaterows are eliminated from the resulting table. Basic requirement to perform union operations on two tables:
Reg.no Name course 1123 John BCA 1156 Gobi BCA 5556 Mary CS
Reg.n o Nam e course 1123 John BCA 1186 Kavin CS 1196 Priya BCA TABLE_A Reg.no Name course 1123 John BCA 1156 Gobi BCA 5556 Mary CS 1186 Kavin CS 1196 Priya BCA TABLE_B Reg.no Name course 1123 John BCA
1.7.1.4. Projection The projection operation allows creating table based on describable columns from all existingcolumns in a table. The projection operation returns the “vertical slices” of a table. The projection is indicated by including the table name and a list of described columns TABLE_E = WIPRO(Reg.no, Name) 1.7.1.5. Selection The selection operations select rows from a table based on a condition or conditions. The selection operations return “horizontal slices” from a table. The selection (set) operations to the parts table. TABLE_E = sel(WIPRO: COURSE=’CS’) 1.7.1.6. Product A product of two tables is a combination everything in both tables. It is known as a Cartesian product. If the first table has x rows and the second table has y rows the resulting product has x.y rows. If the first table has m columns and second table has n columns the resulting product has m*ncolumns. DEPARTMENT EMPLOYEE
Reg.n o Nam e course 1156 Gobi BCA 5556 Mary CS TABLE_E Reg.no Name 1123 John 1156 Gobi 5556 Mary TABLE_E Reg.no Name course 5556 Mary CS
1.7.1.9. Division The division operations are the most difficult operation to comprehend. It is not as simple as division in mathematics. In relational algebra, it identifiers rows in one table that have a certain relationship to all rows in another table. PROJPARTS PROJ TABLE_I = PROJPARTS / PROJ 1.7.1.10 APPLICATIONS OF RELATIONAL ALGEBRA Relational algebra is a procedural language in the sense that a user is required to use a series of operation to obtain a certain result. RDBMS – COMPUTER APPLICATIONSPage 10
Referring to the above tables, which employee is working on a project in Miami during the year 2003? Solution: A = join(PROJ,EMPLOYEE:PROJNO=PROJNO) B=Sel(A:LOC=’MIAMI’) C=B(ENAME) Alternative solution A=Sel(PROJ:LOC=’MIAMI’) B=Join(EMPLOYEE,A:PROJNO=PROJNO) C=B(ENAME) Table C will have one entry, Carter, an employee who works on project 1 in Miami. 1.7.2 RELATIONAL CALCULUS Relational calculus is nonprocedural. The programmer specifies the data requirement, and the system generates the operations needed to produce a table with the required data. Syntax:Result = (column list) : Expression Referring to the DEPT and EMPLOYEE table, find employee names and salary for employees who work in production. Solution: (r.ENAME, r.SALARY): r in EMPLOYEE and s in DEPARTMENT and s in DEPTNAME = ‘PRODUCTION’ and r.DEPTNO = s.DEPTNO 1.8 DATA MODELING
supervises (1,1) (1,1) employs (1,N) (1,1) contains (1.N) (1,N) Fig: Cardinality 1.8.4 Business Rules: Corporation set rules for minimum and maximum values for cardinality. A corporate maydecide that a department must have minimum of 10 employees and maximum of 25 employees. Thenthe cardinality is (10,25). An employee can be part of zero or more than one department and an itemmay not be in any invoice. These types of decisions are known as Business rules. 1.8.5 Optional Relationship: The relationship becomes optional in such a case; a customer can rent video movies fromvideo rental store. Sometimes, the movie offered by the customer is not available in the store and bysuggestion of salesman the customer can rent other movie instead that one as optional. The optional relationship is can occur in 1:1, 1:M or M:N relationships. Rents (0,N) (0,N) Fig: Optional Relationship 1.8.6 Composite Entity or Associative Entity: The decomposition from M:N to 1:M involves a third entity known as composite entity or anassociative entity. The composite entity is created with the primary key from both tables with M:Nrelationships. In E-R diagram this entity is represented by a diamond within a rectangle. EMPLOYEE DIVISION INVOICE ITEM DEPARTMENT FACULTY CUSTOMER VIDEO
Thecomposite entity has a composite primary key with two columns; they are foreign keys referencingother tables. Here the composite entity INVITEM is created from the tables INVOICE and ITEM. Theforeign keys are INVNO and ITEMNO together formed as a composite primary for the tableINVITEM. 1.8.6 Weak Entity: There are entities that cannot exist by themselves. Such entities are known as weak entities,they are represented by double lined rectangles. 1.9 Types of Attributes:
A dependency diagram in used the show total, partial and transitive dependencies in table.The primary key components are highlighted .they are in bold letters and in boxes with a darker border. The total and functional dependencies are shown with arrows drawn above the boxes. The partial andtransitive are shown with arrows at the bottom of the diagram. 1.11 Normalization In Relational database two phases are used. Synthesize phase is used to design the databasestructure. Once entities, columns, domains and keys are defined then each entity is synthesized by creating a table for it. Analysis phase is used to improve the structure created in synthesis phase. Aprocess called normalization analyzes the tables created by the synthesis process. Normalization is a technique to reduce redundancy by decomposition process into split tables. The splitting is performed carefully, so no information is lost. Unwanted and unnecessary data intables are in lower normal form. The higher the normal form is lower the redundancy. 1.11.1 Normal Forms Redundant data can pose to huge problem in database. First of all someone has to enter thesame data repeatedly. Second if a change in made in one piece of the data the change has to be madein many places. Example: If the customer ANBU changes the name to BABU in INVOICE tablemake changes in two places. This redundancy may also lead to anomalies. A deletion anomaly results when the deletion of information about one entity leads to deletion of information about another entity.
Eg: If an invoice for customer Gracia is removed, information about item number 4 is also deleted. An insertion anomaly occurs when the information about an entity cannot be inserted unless the information about another entity is known. Eg: if the company buys a new item, this information cannot be entered unless an invoice is created for a customer with that new item. An update anomaly can occur if the item price changes to a new price. The price changes is valid after the change date, but not before the change date. 1.11.1.1 First Normal Form (1NF) A table is said to be in 1NF, if the following conditions exists:
1.13 De-normalization The normalization process split tables in the smaller tables. These tables are joined through common columns to retrieve information from different tables. The more tables needs more joins to get the desired information. In a multi user environment, it is a costly overhead and system performance is affected. De-normalization is the reverse process. It reduces the normal form and it increase data redundancy. In de-normalization the information stored with duplicate data, more storage is required and anomalies and inconsistent data exist.