0% found this document useful (0 votes)
8 views25 pages

DBMS Imp

The document discusses the importance of database management systems (DBMS) in organizing, accessing, and managing data efficiently in a business environment. It outlines the architecture of DBMS, levels of data abstraction, and various data models, including relational and entity-relationship models. Additionally, it highlights the benefits of using DBMS, such as data integrity, reduced redundancy, and improved security.

Uploaded by

mansichaware9
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
8 views25 pages

DBMS Imp

The document discusses the importance of database management systems (DBMS) in organizing, accessing, and managing data efficiently in a business environment. It outlines the architecture of DBMS, levels of data abstraction, and various data models, including relational and entity-relationship models. Additionally, it highlights the benefits of using DBMS, such as data integrity, reduced redundancy, and improved security.

Uploaded by

mansichaware9
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 25
in typical business environment, it is always essential to be able to produce the right information at the right time with minimum efforts. The database shows a change in storage, access and management of data. It is utilized by a large variety of users, to retrieve and manipulate data under its control. * The users could be utilizing that database concurrently from on-line terminals and/or ina batch environment via application programs written in a high-level language. js used for organizing, analyzing and modifying the information stored in a fatabase. * There are various applications available. These are listed below: (tay pPom~ryaurpwWnP ° i. 12. 1B. CG Zz 5 oa go wo W71r ssevenuury sigtus, ULucisy eres Ms, Vv advanta: es » We have following ges: of Software development is reduced. User can get pro ‘ Centralizati me logical organization of dataset. on for in ; + multi-user is available. D ‘alized data reduces management problems and duplication of data also. ata is independ ent. Us i 5 a can monitor database performance. a . a redundancy and consistency are controllable. Program and data interdependency is decreased. Data flexibility is increased. OQ Oo Qo + Data integrity and its quality are maintained. Inconsistency of data is avoided. Same data can be shared by many ap Security to data is provided. oe tion programs. The users of database system can be classified on the basis of degree of expertise or the mode of their interactions with DBMS. There are 4 groups of users of DBMS: 1. 2. 2 Database designers. Applications programmers. anhicticated users. * A database management system is a collection of interrelated files and 4 programs that allow users to access and modify these files. * A main purpose of a database management system is to provide users with abstract view of the data flo —“ — Applicaton] | Application| | Appi [views | [Mew 2 Viewn program 1 | Program 2 | | Pregran - 5) -— DBMS +—+ps,, | level ("me (se level Miro = (a) (b) Fig. 1.1: Architecture of DBMS (Note: (b) is Mirror Image of (a)] . Data abstraction means hiding the implementation details from the end users. Days uses the same principle. _ » It hides the complex details of how the data is actually stored on the secondary storage device in DBMS. There are three levels of data abstraction, Refer Fig. 1.1. Physical Level * Physical level is the lower level of Architecture of DBMS. «This level describes how the data is actually stored in a database. This level defines the data structure used to store the data on secondary storage device. Conceptual Level «The conceptual level describes the structure of the whole database. «The structure of each table is specified in terms of its attributes. Attribute type is specified in terms of logical structure of the database (Fig. 2.4). This level is decided by Database Administrator (DBA). + This level also describes the relationships between various tables. * For example, Struct Emp + defines data structure for a record in a table int emp_id char name (20): Shows type of attributes stored float salary Fig. 1.2: Logical definition of database in ‘C’ Language 4) 1.6 Introduction t Database Management System 8.Com. (ca) (Sem!) 1-6 nt jn ©. DEMS ang oy ii) Logical Data Independence : / “ ‘ is the ability to change the conceptual schema without having to application programs or external schemas ean: ce, the users are protected from In this type of data independen p change d hange logical structure of the data. aly the view definition and the mapping need be changed ina DBMS that supports logical data independence. retrieve data. * DBMS allows us to store / Data consists of facts, which became information when they are processed. information is conveyed to people. For example, if order and payments are the da then balance due and the quantity in hand would be the information. While designing a database, developer has to make decisions about the data which) } stored in a database. The structure and relationship of that data has to be decideq 3 developer uses some methods to create a database for the user and syste implementation. These methods are called Models + Amodel defines the method of storing and retrieving data. + Amodel is an abstraction process that hides the details which are not required whiy highlighting details required to the applications at hand. * A data model is a collection of conceptual tool for describing data, its relationship, data semantics and data constraints. * AData Model consists of: 1. Anamed logical unit i.e. record type and data item. 2. Relationship among these logical units. 3. Data item is logical unit of data and record type is collection of data items. * Actually, it provides abstraction of database application. Data Models Object Based Record Based Physical Logical Model Logical Model Data Mode! Entity - Relationship Mode! Relational Mode! Unifying Model ‘Object Oriented Mode! Network Model Semantic Data Model Functional Data Model Hierarchical Model Frame Memory Model Fig. 1.4: Data Models and Types petabase Management System B.Com. (CA) (Sem-l) 1.7 Introduction to OBMS and Data Mode! There are three types of data models available, (Refer Fig. 1.4]. 1 Object Based Logical Models 2. Record Based Logical Models 3, Physical Data Models. record Based Logical Models: These models are also used to describe data at logical and view level These are used to describe the logical database structure in terms of records «These models show the implementation part + These models have three types in it. 1. Relational Model 2. Network Model. 3, Hierarchical Model. FI Relational Model |. This model shows collection of Tables to represent both data and the relationship. Each table consists of multiple columns and each column is recognized by a unique name. For example, ina database, Customer table and Account table are the two tables available. The relationship between these two tables has been shown by a third table, where one field or column name from both the table is taken together. So a new table called Customer_Amt is formed. Customer Tabie Millar London Mansfield BlackBurn Roger Brown Account Table 10,000 5000 Customer_Amt Table Fig. 1.5: Relational Model Ronrecantatian 1.6 ____ Introduction to DBMS tntrostuction t0 D8H8 and py. Database Management System © com. (CA) (Sonn) Network Model * Data is represented by collection of records and the relationship among the a » represented by links. : * The records are organized asa collection of arbitrary graphs. «For example, in Customer table extra fi considered, which Consiy, the address where account table information 1S stored. he related record address. mation of each link represents # Account tab) eT Account No eld or column 1S * Info! Customer table Mansfield BlackBurn [3424 | 500) epresentation Fig. 1.6: Network M Data is similar to network model sé. links or pointers used to show the relationships. re organized as a collection of tree. only change is that the records ai Baramati [22a [10000] 42a | 5000 Fig. 1.7: Hierarchical Model gram is a photocopy of data structure. ‘An entity-relationship E-R diagram was developed in 1976 by Dr. Peter Chen and others. ‘ed the representation of large and complex data storage conceP! ws » They simplific the E-R diagrams. sua g-R model is based on a perception of @ real world which consists of a collect? basic objects called entities and relationship among these objects. Detabase Management System B.Com (CA) (Sem) 1.9 Introduction to DBMS and Data Model it represents the overall logical structure of a database. An E-R model is normally expressed as an) E-R diagram which is a graphical representation of a particular database Elements of the E-R model: 1 Entities. 2. Attributes. 3. Entity sets, Relationships Relationship sets. ‘An entity is a real world object. This object has its own properties This object is distinguishable from other objects. For example, student, employee, doctor, politician are the entities. Student has its own properties like his/her own name, address etc. An entity is represented by a rectangle in E-R diagram. For example, [Employee] > Here, entity is Employee An entity has set of properties called attributes which holds value in it. ‘An entity must have some attribute through which it is uniquely identified. For example, employee code is the identity of Employee., Roll number is the identity of a Student v Wey Attributes + Once, the entity is identified and then it is described in real terms or through its attributes. An attribute is description that is used to express the property possessed by each member of an entity set or a relationship. « Foreach attribute, set of permitted values are available called as domain. The attributes which uniquely define the occurrence of an entity are called primary keys. Roll_no and Employee_id is a primary key of above entities Student and Employee respectively For example, Disease table Typhoid Salmonella Typhi Dysentery Shigella dysentriae | ‘saynqiyye o sansedoid aures ayy areys yey) adAj aures ay3 Jo sanNUe Jo yas & Styas Qnuauy « ‘sypalqgo 1ayjo uloxy atqeysin3unstp iy pue sayzedord umo syt sey YIYM POM eer ay} uryoalqo ue Ss} nue uy . ‘TePOur Hd Jo Dalgooiseqeyystanuz . nes Gv Bay ‘yunoure ‘adAy suey ‘azep * nu yUNodse ‘ou-sue.y are angen YUeq YI UT paynsaxe suopoesueN JUNODDe [Te JO 29S aL UoRsesueL, -¢ ‘souryeq puke Jequinujunosoe seinguye pue yueq ay} ur peuyeyueu syuNos.e Te JO Jas ayL junossy e ‘Jequinu euoyd pue ewe safoldura “inquye sey eesoydure yoeg “yueG ut WIOM otM ardnad rn wan wee ee vee afl it must be associated with another ccount_no with transaction_no, it d transaction, [Fig. 1.16]. * To make a weak-entity set mea called as owner entity set. If we consider a lly, a healthy relationship between account an‘ . Pear 7] es E a aay 1 +500 1 2000 Fig, 1.16; Strong relationship through Weak Entity Relations and Types of Relationship a tities. * Relationship shows the association between differe! * There are four types of relationships: 1. One-to-One (1:1): An entity in A is associated with at the most one entity inz an entity in B is also associated with at the most one entity in A. [Refer Fig 117 A 8 a b, % fe. | a Bs [=] De Fig. 1.17: One-to-One Relationship The basic E-R concept can model most of the database features. put same aspect of database can be expressed by adding some extra features called extended features. There are 3 extended features” 1. specialization ~~~ 2. Generalization ~ 3, Aggregation specialization (1) It is the abstracting process of introducing new chi or more new classes of objects. In simple words, specialization is a result of taking a subset of higher level entity set to form a lower level entity set, (Fig. 1.32]. Entities are expanded in Specialization. This line implies that Doctor can also be anything else ai and consulting doctor. aracteristics of objects to create one part from permanent doctor ‘Specialization Fig. 1.32: Specialization Process . Generalization (1): It is abstracting process of viewing set o! concentrates on the general characteristics of consequent set while igno! f objects as a single general class. 't ring their differences. It means generalization is the result of taking the union of t produce a higher level entity set, [Fig. 1.33]. This line implies that a doctor has to be either a permanent doctor or 4 consulting doctor, nothing else. Therefore the entities are limited in Generalization wo or more entity sets to Database to DEMS and Data = Management System B.Com. (CA) (Sem-l)___1.22 Introduction Modes Generalization Physiotherapist Fig. 1.33: Generalization Process Table 1.1: The difference between Specialization and Generalizatiot 1. _Itis bottom-top design process. 1,_Itis top-down design process. 2. It is union of two or more lower level| 2. itis subset of higher level entity set to entity sets to produce a higher level form a lower level entity set entity set, 3. In this, lower level entity sets are also|3. Lower level entity sets may have described by attributes and different attributes and may relationship of higher level entity sets. participate in relationship that doe: not apply higher level entity set 4. It is used to emphasize similarities |4. It is used to emphasize distinctioy among lower level entity types. between higher level and lower leve [ | entity set. 5. In this, every higher level entity must |5. It allows for the possibility of more lo also be a lower level entity. level entity sets also, 3. Aggregation: It is the process of combining information on objects so that the higher level obje can be abstracted. * In any entity relationship diagram, we cannot form a relationship among the enti and their relationship. * Aggregation is the process which allows to doing so. (See Fig. 134), cam. (Asem)_134_mteusonte DBNBS NE) nye Magma! er Bam Cems) 28 ‘Solve casestudies areincuded 1+ Tojenrntheetfectvewayof rm ase Stay 1 Construct en £5 diagram for car surance company tht has ef {Sistomers. Each canoer wns ane of orcs aha assed 27 any somber of resrded sence ate Study 3: rove tuo wishes ones a databace to manage Tow ER odes wed for onceptus espn, roe ators and directs The lowing fact aeelerat. P) Eachactorhas appeared in many moves. {ip Exc irector as rected many movie {intach movie ba anedizectr ae eo mone acter. ( enonacorand recor may hav coer adarnoe raw lagram, ‘a es Gs 2 ‘an BR diagram for order Tt a person. pT an gastos © Soe x a Ee Sy 4.138 man = Spe introduction to DBMS: Database Management system com, (ca) sere!) im ~ AS 0 Daa odate a variety of enquiry eS iy 2 RDM is easier to use to accomm 5 RDM enables a compl efficient manner 4 RDMis useful for smalld 5 RDM improves the perfor not with the structures changes data access. tages of RDM are iter syste” jatabases mance of @ sy! in th stem pecause it is concerned with dar; tag e database structure do not influency ce as follows data storas » The disadvan 1, RDM hides the physical e details from the user and it also hig complexities t know hi implementation . ally stored. This ease of design a» 2. In RDM, we need nol jead to bad design 3. As it is easy to use and implement, create their databases, which may ow data 1s actui of departments oF People nconsistency. data duplicate large number lead to data i "There are various terms Whi in following diagram. «The relational data model 16 the most popular mode nceptually simple: understand by all types of USET® and col Joped in 4970 by Dr. EF. codd. He descril | in DBMS because it is #5) This model is devel bed this model to simplt the database structure This model is based on columns Attribute ™~ relation, a two dimensional table. A table consists of rows Domain Relation = Student Cardinality = 6 ie. 6 records/tupies Degree = 3i.e 3 attributes Primary key = RollNo Fig. 1.47: Relational Data Model EY, P RY. FOREIGN KEY 9 identified KEY: SUPER , CANDID, * The rows (tuples/fecords) are unordered in a relation (table) and canna by its position in a relation(table). Every table must have some columns or combination of columns which uniquely identify each row in the table. For that, we require a key * I other words, a key isa relation of subset of attributes with following properties: 1. The value of key is unique for each tuple. 2. Nodata redundancy Hous Parts, we will consider only DDL which allows, manipulation objects such as tables, views, sequenc. 'Y Purpose: The sequence is for creating numeric values. Normalization is simp} where user removes repeated group of data into separate tables In this normalization process, grouping of data can be done. * It is basically the process in which a wide table with lots of columns but few 1s taken and redesigned it as several narrow tables with fewer columns but morerom EEE] second No Database Management System B.Com. (CA) (Sem) an To remove the problems of this relation, it _. normal forms |, it can be normalized through different in typical business environment, it is alw: information at the right time with mini; First Normal Form The definition of First Nor Form is, There are no repeating groups. All the key attributes are defined. Allattributes are dependent on the primary key. A relation is said to be in First Normal Form (INF), if all fields are atomic. In other words, only one value is associated with each attribute A database scheme is in 1NF if every relation schema isin INF. For example, above relation stud can be re] in Fig. 2.13. ays essential to be able to produce the right m efforts, included in the database schema placed by a new relation N. stud as shown cricket cricket cricket Fig. 2.13: N_stud Relation (1 NF) Here each field is now in atomic form. Though some field values are getting repeated for same record multiple times, it is simy non-atomic fields Arelation schema R is ~ itisin1 NFand ~ all its non-prime attributes are fully functionally dependent on the primary key of R A database schema is in second normal form, if every relation schema included in the database schema is in 2NF. So, we go through all the fields, we can see that sport_name is only dependent on sport_code. exam_date, max_marks, scored_marks are dependent upon sub code Now we will have the following 3 tables by the method of decomposition 1. Stud table roll ( primary key) course prof ond Normal Form (2NF) if, [condition]. This query is equivalent to the relational algebra expression. Th ag hpevnns An (Op (ts % 2 % nee Fm) Sometime, the list A,, Ag, ..., An may be replaced with an asterisk (-) to selex attributes of all relations appearing in the FROM clause. * SQL forms the Cartesian product of the relation named in the FROM clause, Perfon a relational algebra selection using the WHERE clause predicate and project; result onto the attribute of the SELECT clause. The semicolon (;) is the termin: SQL expression. *® DDLisa part of SQL which describes the structure of information in the database * DDL basically allows us to create, delete and alter (modify) tables. Data Types: * Let’s learn some basic data types used in SQL for table creation. index in the back of a book syntax: CREATE INDEX index_name ON table_name(column_name) ; Example: Suppose we want to define an index on empname field of emp table. CREATE INDEX ename ON emp(empname) ; An index can be dropped by using DROP INDEX command. syntax: DROP INDEX ena eee The SQL DML includes the commands to insert tuples into database, to delete tuples from the table and to modify tuples in the table. EBs Insert Command To insert a data into a relation, we either specify a tuple to be inserted or write a query whose result is set of tuples to be inserted. Syntax: INSERT INTO table-name (column-name [, column-name] ) values (column-value [, column value} .. ) Fig. 2.40: Result of above query © Here, branch_name is in descending order whereas branch_city is in ascerg order. However, branch_city comes first in the query and even though Adam % should not be the first record, sincé London, New York are in ascending order. Set Operatio’ The SQL provides some set operations like Union, Intersection and Except (Mc which are similar to the relational-algebra operations U, and -. The relations participating in the relational algebra and SQL operations 1 compatible i.e. they must have same set of attributes. « Consider the following example: Example 38: Find set of all customers who have account at the bank. Query: SELECT cust_name FROM Depositor; «+ Note: We have learnt this topic in the section 2.4.1.1. + Let us see examples based on the constraints. Example 46: Create a table Customer with name, city name and street name. Query: CREATE TABLE Customer (cust_name varchar2(2@) NOT NULL, cust_city varchar2(2@) NOT NULL, cust_street varchar2(4@)); This will create a table with name Customer. By using INSERT command, we can insert the records into the table. Consider that the table Customer is related with a table Depositor. Account is one more table which has acc_no as primary key and it is also related with Depositor. The Fig 250 shows the relationship diagram. cust_name cust_name 4) aceno cust_city ace_no. M. branch_name cust_ street | Customer Depositor ra Fig. 2.50: Many-to-Many Relationship _ln the Customer table, cust_name is a primary key. To create a table Customer with timary key, we need to write the following Create command. Fig. 2.57: Result of unique command This query will find the cust_name from the table Depositor and then search for unique record in the account table by checking specified condition. * Similarly, we can check for existence of duplicate tuples just by using keyword y unique. Formally, the unique test on a relation is defined to fail if the relation contains ty tuples t1 and t2 such that ti = t2. If t1 or t2 is null, then the result of unique is try multiple copies of a tuple as long as one of the attributes of a tuple} null. using Oracle) 1. Consider the following entities and relationships. “ Owner (Licence_no, name, address, Phone) ~ Car (car_no, model, colour) management System 8.Com.(CA)(Sem) 2.55 sau ownet and Car are related with one-to-many relationships create a RDB for the above and solve the following queries in SOL jon: owner and Car are the two relations Biven. Let's di a : : . Let's dr , + Spvonships The ER diagram isshown inerg stow an E-R diagram with the given aner drawing E-R diagram, we have to +" jationship. Convert it into the form of table with the given rl a Fig. 2.58: E-R diagram + the relationship is One-to-Many, the primary key of relation one (called parent) is taken and added as a foreign key into the Mai i . RDB which is s in Fig. 259, ny (called child) relation. Let's draw on na Oune Relation = Car 4 Licence_no: carne model address yf colour ° licence_no Fig. 2.59: One-to-Many Relationship + After this we should add some tuples into the table which will answer the written queries. Query 1: Find the name of owner of ‘Zen’ and ‘Indica’ cars. SELECT name, address, model FROM Car c, Owner o WHERE (model='Zen' Or model='Indica’) And c.car_no=0.car_no; Query 2: Insert a record in a car relation. INSERT INTO car VALUES (154, ‘Maruti’, "BLACK" ); Query 3: List all the models of owner 'Mr. Shon’ having colour ‘blue’ SELECT model, colour FROM Car c, Owner 0 WHERE name='Mr. Shon’ and colour=‘blue’ and c.car_no=0.car_no} Database ian Query 4.7, lst the inform, SELECT name, FROM Car c, Com. (CA) (Semm-t) 286 __ ation of all cars in ‘London’ address, model, colour Owner o WHERE £-carnoso.carno and address='London’ GROUP BY name » address, model, colour; 2 der the following Entities and Relationships. lachine (m_no, ™m_name, m_type, m_cost) Part (p_no, P_name, p_desc) Machine and Part are related with One-to-Many relationships. Create @ RDB for the above and solve the following queries in SQL. Sol lution: The One-to-Many relationship is as shown in Fig. 2.60. Machine m_no m_name ™_type m_cost Fig. 2.60: One-to-Many Relationship Query 1: Increase the cost of machine by 5%. UPOATE Machine SET m_cost = m_cost + (m_cost « 8.85); Query 2: Delete all machines having particulars "wheel". DELETE FROM Machine WHERE m_type="wheel"; Query 3; List all the machines whose cost > 1,00,000. SELECT m_name, m_cost FROM Machine e _m_cost>109000; the following Entities and . (cust_no, name, address) ~ Quotation (quot_no, desc, amt_quoted) Customers and Quotations are related with One-to-Many relationships. Create a RDB for the above and solve the f - - 8 queries in sq. Solution: The RDB is as shown in Fig. 2.61, Relationships. ont System B.Com, (CA) (Sem. = ee Customer Quotation 1 cust_no quot_no name desc address. | amtquoted + cust_no Fig. 2.61; One-to-Many Relationship 4, list all the customers who are demandi machine” SELECT name, address FROM Customer, WHERE desc="washing machine" and Customer. cust_no = ing for the quotation of "washing Quotation Quotation. cust_no; 2 Listall the customers who are demanding for the quotation of “fridge” SELECT name, address FROM Customer, Quotation WHERE desc="Fridge” And Customer.cust_no = Quotation. cust_no; query3: Delete all the customers with details with address ‘London DELETE FROM Customer WHERE address="London"; query 4: To print customerwise list of quotation but only those quotations whose amt > 5000. SELECT name, customer.address, desc, amt_quoted FROM Customer, Quotation WHERE amt_quoted > 5@@ And Customer.cust_no = Quotation.cust_no; 4 Consider the following Entities and Relationships. oy (c_product, c_name, region, state) Branches (b_product, city) Company and Branches are related with One-to-Many relationship. Create a RDB for the above and solve the following queries in SQL. Selution: Here we cannot consider c_product and b_product as primary keys because product name can be duplicate. So let us add one more field called c id into relation Company which will save as primary key. The One-to-Many relationship is as shown in Fig. 2.62. Ce Branches Fig. 2.62: One-to-Many Relationship Smmiawe Management System abase Management “ S write queries. juery 1; List all the cities having branch product 'H2S0+ SELECT city, b_product B.Com. (cA) (Sem) 288 and ‘SOs FROM Branches b, Company WH! Query 2. ERE b.c_Sdec.e id and (b product="H:50" + List all the states whose branch product is leu SELECT state or b_product="S0s"): FROM Branches b, Company c WHERE b.c_idec.c_id and (b_product=‘oleum’)i Query 3: Delete all the company details of city ‘New York’ DELETE FROM Branches WHERE city='New York’; Query 4: Print citywise branches in sorted order. SELECT c_name as company, city FROM Branches b, Company ¢ WHERE b.c_idec.c_id ORDER BY c_name; ‘the following Entities and Relationships. er (t_no, t_name, college_name, dept) -_Test(e_no, test_name) Teacher and E_test are related with Many-to-Many relationships. Create a RDB for the above and solve the following queries in SQL. Solution: The relationship is Many-to-Many. So, we have to create & new table with we primary keys. The RDB is as shown in Fig, 2.63. cen Teacher_test t Fig. 2.63: Many-to-Many Relationship Let's write the queries. Give the name of teach college_name, test_name, dept ers who have passed either "SET" or "NET". rom Teacher t» F_test © Teacher_test r

You might also like