0% found this document useful (0 votes)
16 views49 pages

DBMS Edited

DBMS NOTES

Uploaded by

rishikajain0221
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)
16 views49 pages

DBMS Edited

DBMS NOTES

Uploaded by

rishikajain0221
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/ 49
1. Whatis Data? a [uence In other words, data does not carry any specific purpose and has no significance by itself. Moreover, data is measured in terms ofits and bytes ~ which ae basic units of information inthe context of computer storage and processing, Data canbe recorded and doesnt have ay meaning uness processed 2. Types of Data 2. Quantitative iL Numerical form i, Weight, volume, cost ofan tem b. Qualitative iL Descriptive, but not numerical, i, Name, gender, hair color ofa person. 3. Whatis Information? 2. Infos processed, organized, and structured data, Head cata ddr da mag 4. Informations extracted from te data by analyzing and interpreting pieces of data, ‘© Eg, you have dat ofall the people living your locality, is Dat, when you analyze and interpret the data and come to some conclusion that: {There are 100 senior cizens ii, The serratiois 11 ii, Newborn babies are 100. These are information. 4, Data vs Information ‘2. Datais.a collection of facts, while information puts those facts into context ‘C Datapoints are individual nd sometimes unrelated. Information maps out tat data to provide a bigrpicture view of how it al fits together Data, on its own, is meaningless. When it’s analyzed and interpreted, t becomes meaningful information, Data does not depend on information; however information depends on data Data typically comes inthe form of graphs, numbers, figures, r statistics, Information is typically presented through words, language, thoughts, and ideas i Data isn't sufficient for decision-making, but you can make decisions based on information. 5. a b a he collection of dat, usually referred to as the database, Crmrmsin in meni aac a that i both convenient and ecient b. ADBMSis the database itself, jeoasibal the software and seca tiswettoptam ® oo A 8. DBMS wsFile Systems 2, File-processing systems has major disadvantages. \ Shae : : wi Security problems b. Above 7 are also the Advantages of DBMS (answer to "Why to use DBMS?") LEC-2: DBMS Architecture a Thema} = ‘of DBMS isto sai users with an abstract view ofthe data. Thats the b. To simpliy user interaction withthe system, abstraction is applied through Several levels! while storing the underiying data only once Lovelevel data structures used thas Physical schema which describes physical storage structure of DB. Talks about: Storage allocation (N-ary tee etc), Data compression & encryption etc. Goal: We must define algorithms that allow efficient access to data, DBA, who must decide what information to keep inthe DB use the logical level of li Atthe extemal level, a database contains several schemas that sometimes called as subschema, The subschera i Used to describe the different view of the database. iv. Atviews also provide a security mechanism to prevent uses from accessing certain pats, of DB, External Schema | External Level ) ( External Level External / Conceptual Mapping Conceptualschema { Conceptual Level Conceptual Internal Mapping Incernal Schema Tnvernal Level & 2. Instances and Schemas The olection of information stored in the DB a particular momentis called an instance of DB, frequently. d._DBschema corresponds to the variable declarations (along with type) in a program. e Seiae a SaaS aL {Logical scheme is most important in terms ofits eect on application programs, as programmers construct apps by using logical schema & Physical data independence, physical schema change should not affect logical schema/applcation programs. 3. Data Models: a. Provides a way to describe the design of a DB at logical level. . Undertying the structure ofthe DB's the Data Mode; a collection of conceptual tools for describing data, data relationships, data semantics & consistency constraints, , ER model, Relational Model, object-oriented model, object-elational data model ete. Ina single DB language, e, SQL language. DDL i. We specity consistency constraints, which must be checked, everytime DB is updated mu 2. Insertion of new information into DB. 3. Deletion of information from the DB. in DB. i 8 part of DML to speciy statement requesting the retrieval of information 5. How is Database accessed from Application programs? 2 Apps (written in host languages, C/C++, Java) interacts with DB. b. Eg, Banking system's module generating payrolls access DB by executing DML statements from the host langua / romance & Database Administrator (DBA) 2 ae ee ._ Functions of DBA Schema Definition Storage structure and access methods i. Schema and physical organization modification. Authorization control. Routine maintenance 1. Periodic backups. 2 Secunty patches 3. Any upgrades DBMS Application Architectures: Client machines, on which remote DB users work, and server machines ‘on which DB system runs. 2 TAhtecre 2 > TRArchitecture ili_API standards like ODBC & JDBC are used t interact between client and server. TBAcchitecture aaa hat action to take at that condition isin App server itself Advantages: Scalability due to distributed application servers. Data integrity, App server acts as middle layer between client and DB, which minimize the chances of data coruption Security, clint cant directly access DB, hence itis more a. twortier architecture client server ‘application server database system bb. three-tier architecture ship Model Data Mode: Collection of conceptual tools for describing data, data relationships, data semantics, and consistency constraints, 4 Strong Entity: Can be uniquely identified. 5. Weak Entity: Cant be uniquely identified, depends on some other strong entity 1. Itdoesn'thave sufficient attributes to select a uniquely identifiable attribute 2 Loan-> Strong Entity, Payment > Weak, as instalment are sequetial number counter can be generated separate foreach loan. 3. Weakeentty depends on strong entity for existence. 4. Entityset |. tsa setof entities ofthe same type that share the same properties, or atributes. 2. Eg, Student isan entity set. 3. Eg, Customer ofa bank 5. Attributes 1 2. Esch entity has a value foreach of its attributes, 3. Foreach attribute, there i set of permitted values, called the domain, or value set, ofthat attribute 4 Eg, Student Entity has following attributes ‘A Student_ID [ER model stands for an Entity- | Relationship model. Itis @ high- oe level data madel. This model is. Standard lused to define the data elements and relationship for a specified isystem. It devetops a conceptual design for the database. talso. develops a very simple and easy to design view of daa, B « o E E « lin ER modeling, the database ‘structure is portrayed as a idiagram called an entity- ‘relationship diagram. Ittpsi/www javatpoint.com/ idbms-er-model-concept 2. eg Age, loan-age, membership-priod etc. 6. NULLValue 1. Anattribute takes a null value when an entity does not have a value frit 2. _Itmay indicate “not applicable value doesn't exist eg, person having no middle-name 3. _Itmay indicate ‘unknown’ 1. Unknown can indicate missing entry, eg, name value ofa customer is NULL, means itis missing as name must have some value 2. Not known, salar attribute value of an employee is nul, means tis not known yet 6g, Person has vehicle, Parent has Chile, Customer borrow loan ete Strong Relationship, between two independent entities. Weak Relationship, between weak entity and its owner/strong entity. 1.__eg, Loan Payment. ‘eg, Employee manages employee. eg, Student takes Course Eg, Employee works-on branch, employee works-on job. nary are common, 1. Mapping Cardinality / Cardinality Ratio 1 Number of entities to which another entity can be associated via a relationship. 2 infty in A associates with at most one entity in B, where A & Bare entity sets. And an entity of Bis associated with at mast one entity ofA. entity in 1_eg, le Entity in A associated with at most one entity in 8. While entity in B can be associated with 4 Nentityn A. 1_eg.! cen by Professor 5 Entity in A associated with N entity in 8, While entity in 8 also associated with N entity in A 1. Customer buys produc. 2. Student attend course. 2. Participation Constraints ‘Aka, Minimum cardinality constraint. Types Partial & Total Participation. Pattal Participation, not ll entities are involved inthe relationship instance Total Participation, each entity must be involved in atleast one relationship instance. eg, Customer borrow lan, loan has total participation asit can't exist without customer entity. And ‘customer has partial paticpation ‘5. Weak entity has total participation constraint, but strong may not have total 8. ERNotations Atoute Entity Entity ‘Weak Entty LEC-4: Extended ER Features Basic ER Features studied in the LEC-3, can be used to itis better Specialisation 1. InER model, we may requiteto subgroup an entity st into other entity sets that are distinctin some way with other entity sets, 2. Specialisation is spiting up the entity set into further sub entity sets on the basis oftheir functionalities, specialities anc features, 3, Itisa Top-Down approach 4. eg, Person entity set canbe divided into customer, student, employee. Person is superclass and other specialised entity sets are subdlasses. 1. We have “is-3 relationship between superclass and subclass. 2. bene by tangle cmporet 5. hy Spector V7 1 etanatrntes moony be apple fees the parent entity set. 2. DB designer can show the distinctive features ofthe sub entities. 3. Togroup such entities we apply Specialisation to overall refine the DB blueprint. Generalisation 1. Itisjusta reverse of Specialisation. 2. DB Designer, may encounter certain properties of two entities are overlapping Designér may consider to make @ new generalised entity set. That generalised entity set will be a super cass, 3. “isa relationship is present between subclass and super cass, 4. €8, Car, Jeep and Bus all have some common attributes, to avoid data repetition forthe common attributes. DB designer may consider to Generalise to a new entity set Vehicle 5. tis Bottom-up approach 6. Why Generalsation? 1 Makes DB more refined and simpler. 2. Common attributes are not repeated. Attribute Inheritance 1. Both Specialisation and Generalistion has attbute inheritance 2. Theatributes of higher level entity sets areinherted by lower level entity sets. 3. Eg, Customer & Employee inher the attributes of Person. Partidpation inheritance 1. fa parent entity set participates ina relationship then its child entity sets wil also participate in that relationship Aggregation 1. Howto show relationships among relationships? - Aggregation i the technique. 2. Abstraction is applied to treat relationships as higher-level entities. We can cllit Abstract entity 3. Avoid redundancy by aggregating relationship as an entity set itself ‘row ina table represents a relationship among a set of values, and table is collection of such relationships. Each attribute, there is a permitted value, called domain of the attribute, Relation Schema: defines the design and structure of the relation, contains the name ofthe relation and al the columns/attributes table/relation, in a given relation. Important properties of Table in Relational Model 1. Thename of relation i distinct among al other relation The values have tobe atomic. Can'tbe broken down further. The name of each atribute/column must be unique Exch tuple must be unique in a table The sequence of row and column has no significance. Tables must follow integrity constraints -it helps to maintain data consistency across the tables Relational Model Keys 1. Super Key (SK): Any P&C of attributes present ina table which can uniquely identity each tuple. 2. Candidate Key (CK): minimum subset of super keys, which can uniquely identify each tuple. t contains no redundant attribute 1._CKvalue shouldnt be NULL. 1. Selected out of CK set, has the least no. of attributes 4. Alternate Key (AK) 1._AlLCK except Pk. 2. Atelaton, say, may include among its atributes the PK of an other relation, say r2. This attribute is called FK from r referencing 2 3 Therelation is aka Referencing (Child) retation of the FK dependency and r2s called Referenced (Parent) relation of the Fk : ee ‘ Surrogate Key: 1. Synthetic PK. 2 Generated automatically by DB, usualy an integer value. 3. Maybe used as PK. Integrity Constraints 1. CRUD Operations must be done with some integrity policy so that DB is always consistent. 2. Introduced so that we do not accidentally corrupt the DB. 3. Domain Constraints 1. Restricts the value in the attribute of relation, specifies the Domain, 2. Restrict the Datatypes of every attribute. 3. Eg, Wewant to specify thatthe enralment should happen for candidate bith year < 2002. 4. Entity Constraints 1. Every relation should have PK. PK '= NULL 5. Referential Constraints 1. Specified between two relations & helps maintain consistency among tuples of two relations 2. _Itrequires that the value appearing in specified attributes of any tuple in referencing relation also appear in the specified atributes of at least one tuple in the referenced relation 3. _IFFKin referencing table refers to PK of referenced table then every value ofthe FKin referencing table must be NULL oravalable in referenced table 4, FK must have the matching PK for its each value inthe parent table or it must be NULL 65. Key Constraints: The si types of key constraints present inthe Database management system are: 1. NOTNULL: This constraint wil restrict the user from not having a NULL value. I ensures that every element in the database has a value 2. UNIQUE: Ithelps us to ensure that al the values consisting ina column are diferent from each other. 3. DEFAULT: its used to set the default value tothe column. The default value is added to the columns ino value isspecitied for them, 4. CHECK: tis one ofthe integrity constraints in DBMS, I keeps the check tat integrity of data is maintained before and ater the completion of the CRUD. 5 PRIMARY KEY: This is an attribute or set of attributes that can uniquely identify each entity in the entity set. The primary key must contain unique as well as not null values. ‘6. FOREIGN KEY: Whenever there is some relationship between two entities, there must be some'common attribute between them. This common attribute must be the primary key ofan entity set and will become the foreign key of another entity set. This key will prevent every action which can result in loss of connection between tables. LEC-8: Transform - ER Model to Relational Model Both ER-Model and Relational Model are abstract logical representation of real word enterprises. Because the two 2. Entity’ Primary Key (PK) is used as Relation’ Pk. 3. Fk are added to establish relationships with other relations [Br entity that depends on anather entity called a weak ently. | 1 Atable formed Wit alte attibutes oF the entity, 2 PKofits corresponding Strong Entity will be added as FK. 3__ PK of the relation willbe a composite PK, {Fk + Partial discriminator Key). 1.__ Represented as columns directly in the tables/telations 1. Handled by creating a separate attribute itself in the original relation for each composite attribute. 2. eg, Address: {street-name, house-no},'s2 composite atnbute in customer ration, we add address-treet- name & address-house-name as new columns in the attribute and ignore “address” as an attribute. 5. Multivalued Attributes New tables (named as original attribute name) are created for each multivalued attribute. PK of the entity is used as column FK in the new table, Mutivalued attribute's similar name s added as column to define multiple values, PK of the new table would be {FK + multivalued name}. ‘eg, For Strong entity Employee, dependent-name is a multivalued attribute. 1.” New table named dependertname wil be formed with columns emp-id, and dname 2. PK: {emp-id, name} 3._FK: emp-id} 6 lot considered ithe tables. 7. Generalisation |. Method:t: Create a table forthe higher level entity set. Fr each lower-level entity se, create a table that includes a column for each of the attributes of that entity set plus a column for each attribute of the primary key ofthe higher-level entity set. For eg. Banking System generalisation of Account - saving & current. 1 Table account (account-number, balance) 2. Table 2: savings account (acount. number interest-rate aly. withdrawal) 3. \Teble3: curent account (account-number,overdraf-amount,pe-transaction-charges) 2 Method-2: An alternative representation is possible if the generalisation is disjoint and complete—that no entity isa member of two lower-level entity sets relly below a higher-level entity set, and if every entity in the higher level entity set is also a member of one of the lower-level entity sets, Here, do not create a table for the higher-level entity set. Instead, for each lower-level entity set, create a table that includes a column for each ofthe attributes of that entity st plusa column foreach attribute of the higher-level entity sets Tables would be: “Table: savingsaccount(account-number, balance, interestate, daiywithdrawalimit) 2. Table 2: current-account (account-number, balance, overdraft-amount, per-transaction-charges) 3. Drawbacks of Method-2: ithe second method were used for an overapping generalisation, some values such as balance would be stored twice unnecessarily. Similarly, ifthe generalisation were not complete—that is, if some accounts were neither savings nor current accounts—then such accounts could not be represented with the second method 8. Aggregation 1 Table ofthe relationship set is made. 2. Attributes includes primary keys of entity set and aggregation set's entities. 3. Also, add descriptive attribute ifany onthe relationship. LEC-9: SOL in 1-video ‘CREATE - execute INSERT statements to insert new tuple int the relation READ - Read data already inthe relations. UPDATE - Modify already inserted data inthe relation DELETE - Delete specific data pointtuple/row or multiple rows 1 2 3 4 1. Software that enable us to implement designed relational model 2. eg, MySQL, MS SQL, Oracle, IBM ete 3 5 6 ‘MySQL used client-server model, where client is CL! or frontend that used services provided by MySQL server. SSQL DATA TYPES (Ret https:/wwrmaschools.com/sal/sql_datatypes.asp) 1. InSQLDB, datais stored in the form of tables. 2.__Data can be of different types, ike INT, CHAR etc. DATATYPE q Description CHAR ‘string(0-255), string with size = (0, 255], e.9., CHAR(251) VARCHAR ‘string(0-255) TINYTEXT String(0-255) TEXT string(0-65535) BLOB string(0-65535) MEDIUNTEXT string(0-16777215) MEDIUMBLOB- ‘string(0-16777215) LONGTEXT string(0-4294967295) LONGBLOB string(0-4294967295) TINYINT integer(-128 to 127) SMALLINT integer-82768 t0 32767) MEDIUMINT integer(-8388608 to 8388607) INT integor(-2147489648 to 2147489647) BIGINT integer (-9228372096854775006 to 9223372036854775807) FLOAT Decimal with precision to 28 digits DOUBLE Decimal with 24 to 68 digits DATATYPE, Description / Ey DECIMAL Double stored as string DATE YYvyeMM-DD DATETIME YYYY-MM-DD HH:MM:SS TIMESTAMP YYYYMMDDHHMMSS. TIME HHMMSSS ENUM One ofthe preset values SET (One or many of the preset values BOOLEAN on BIT 2.9., BIT(n), n upto 64, store values in bits. 3. Size: TINY < SMALL < MEDIUM < INT < BIGINT, 4, Variable length Data types eg, VARCHAR, are better to use as they occupy space equal tothe actual data size 5 ed eg, INT UNSIGNED. 6 defining relation schema, odification in table structure. eg, change column datatype or add/remove columns Jelete table, DB, view, remove all the tuples from the table, retrieve data from the tables. be use to perform madificationsin the DB 1 Insert data into a relation 2 ipdate relation data. 3 :delete row(s) from the relation. (DEL (Data Control language): grantor revoke authorities from user, 1. GRANT: access privileges tothe DB 2. REVOKE: evoke user acess privileges. ‘TCL (Transaction control language): to manage transactions done in the DB 1. START TRANSACTION: begin a transaction 2 COMMIT: apply athe changes and end transaction 3. ROLLBACK: discord changes and end transaction 4 SAVEPOINT: checkout within the group of transactions in which to rollback. [MANAGING 08 (DDL) 1. Creation of DB 1 2 ‘CREATE DATABASE IF NOT EXISTS db-name; USE db-name;//need to execute to choose on which DB CREATE TABLE etc commands will be executed {Imake switching between DBs possible DROP DATABASE IF EXISTS db-name; //dropping database. ‘SHOW DATABASES; ist all the DBs in the serve. ‘SHOW TABLES; [ist tables inthe selected DB, DATA RETRIEVAL LANGUAGE (DRL) 1. Syntax: SELECT FROM ; 2 Order ofexecaton trom RIGHT to LEFT 3. Q Canwe use SELECT keyword without using FROM cause? 1. Yes, using DUAL Tables. 2 Dua tables are dummy tables created by MySQL, help usersto do certain obvious actions without refering to user defined tables. 3 eg, SELECTS5 +1 SELECT now) SELECT ucase() ete 4. WHERE 1, Reduce rows based on given conditions. 2._ Eg, SELECT* FROM customer WHERE age > 18; ‘SELECT * FROM customer WHERE age between 0 AND 100; Inthe above eg, 0 and 100 are inclusive. Reduces OR conditions; ce. SELECT * FROM officers WHERE officer_name IN Lakshay; ‘Maharana Pratap, Deepika), 1. AND: WHERE condi AND cond2 2. OR: WHERE condi OR cond2 3._NOT: WHERE col_name NOTIN (12.34); ELECT * FROM customer WHERE prime_status is NULL; 8. Patter Searching Wildcard (96) {Lamy number of character rom Oto. irr to asters eb 2. “Jonlyone character. 3._SELECT* FROM customer WHERE name LIKE‘ we 10 Sorting dt retrieved using WHERE cause. 2. OROER BY DESC; 3. DESC = Descending and ASC= Ascending 4g, SELECT FROM customer ORDER BY name DES; 1 GRouP By 1, GROUP BY Clause is used to collect data from multiple records and group the result by one or more column. tt is ererly used na SELECT statement 2. Groups into category based on column given. ‘SELECT cl, 2,3 FROM sample_table WHERE cond GROUP BY cl, ¢2, ¢3. 4 Alte column names mentioned after SELECT statement shall be repeated in GROUP BY, inorder successfully execute the query 5. Used with aggregation functions o prion various actos. 1. COUNT() 2 SUM() 3. AVG() 4 5 ‘MNO. MAX) 12. DISTINCT 1. Find distinct values inthe table 2, SELECT DISTINCT(col_name) FROM table_name; 3. GROUP BY canalso be used forthe same 1. "Select col_name from table GROUP BY col_name,” same output as above DISTINCT query 2. SQLis smart enough to realise that f you are using GROUP BY and not using any aggregation function, then. you mean "DISTINCT", 13, GROUP BY HAVING 1. Qutofthe categories made by GROUP BY, we would ike to know only particular thing (cond). 2. Similar to WHERE. 3, Select COUNT(cust_id), country from customer GROUP BY country HAVING COUNT(cust_i4) > So; 4, WHERE vs HAVING Both have same function of itering the row base on certain conditions 1 2. WHERE clause is used to filter the rows fom the table based on specified condition 3. HAVING clause is used to filter the rows from the groups based on the specified condition 4, HAVING is used after GROUP BY while WHERE s used before GROUP BY clause. 5 youare using HAVING, GROUP BY is necessary. ‘5. WHERE can be used with SELECT, UPDATE & DELETE keywords while GROUP BY used with SELECT. CONSTRAINTS (DDL) 1. Primary Key ble, 2 1. Fé refers to PK of other table. 2. Eachrelation can having any number of FK. 3 ce a oot i INT, FOREIGN KEY (cust_id) REFERENCES customer(id) i 3. UNIQUE 1. Unique can Bernul table can have mutile unique attributes. 2. CREATETABLE customer ( ‘email VARCHAR(1024) UNIQUE, y 4. CHECK |. CREATE TABLE customer ( CONSTRAINT age_check CHECK (age> 12), i 2. "age check’, can also avoid this, MySQL generates name of constraint automaticaly 5. DEFAULT 1 2 Set default value ofthe column. CREATE TABLE account ( saving rate DOUBLE NOT NULL DEFAULT 425, i 6 Anattribute can be PK and FK both in a table. 7. ALTER OPERATIONS 1 2 ‘Changes schema ADD 1. Add new column, 2__ ALTER TABLE table_name ADD new_col_name datatype ADD new_col_name_2 datatype; 3. eg, ALTER TABLE customer ADD age INT NOT NULL; ‘MODIFY 1. Change datatype ofan attribute. 2 ALTER TABLE table-name MODIFY colname col-datatype; 3. Eg, VARCHAR TO CHAR, ALTER TABLE customer MODIFY name CHAR(I024); 1. Rename column name. 2, ALTERTABLE table name CHANGE COLUMN ol-col name new cob name new-,the lft side of FD isknown as a Determinant, the right side ofthe production i known asa Dependent 3. TypesofFD 1. Trivial FD 1. A> Bhas trivial functional dependency if 8 is @ subset of A. A->A, B->B are aso Trivial FD. 2. Non-tivial FD 1. A.» Bhas2-non trivial functional dependency if is not a subset ofA. (A intersection B is NULL] 4. Rules of FD (Armstrong's axioms) 1. Reflexive 1. IFMisa set attributes and'8' is a subset of: Then, A> B holds 2. FAD BthenA>B, 2. Augmentation 1. IfB can be determined from A, then adding an attribute to this functional dependency won't change anything. 2. If Ae Bholds, then AX BX holds too.’ being a set of attributes. 3. Transitvity 1. If Adetermines 8 and B determines , we can say that A determines C. 2. ifA> Band B> Cthen A> C arises. 5. Anomalies 1L_Anomalies means abnormalities, there are three types of anomalies introduced by data redundancy. 2. Insertion anomaly 1 When certain data (attribute) can not be inserted into the DB without the presence of other data 3. Deletion anomaly 1L._ The delete anomaly refers tothe situation where the deletion of data results inthe unintended loss of some ‘other important data, 4 (or modification anomaly) 10 updation to many places, may be Data inconsistency arises, i one forgets to update the data at all the intended places. 5. ‘6 NORMALISATION. 6. Whatis Normalisation? L ike Insertion, Update, ané Deletion Anomalies. Normalisation divides the composite attributes into individual attributes OR larger table ito smaller and tnks them sing relationships. 3, The normal form is used to reduce redundancy from the database table, 7. Types of Normal forms 1 INF 1. Every relation cell musthave atomic value 2. Relation must not have multi-valued attributes 2 2. INF 1. Relation must bein INF 2. There should not be any partial dependency 1 Allnon-prime attrbutes must be fully dependent on PK 2. Non prime atrbute can not depend on the part of the PK. 3. 3NF 1 Relation must bein 2NF 2. Notransiivity dependency exists 1. Non-prime attribute should not find a non-prime attribute. 4. BNF (Boyce-Codd normal form) 1. Relation must bein 3NF 2. FD:A > B,A must bea super key 1. Wemmust not derive prime attribute from any prime or non-prime attribute LEC-12; Transaction Transaction 1. Aunit of work done against the DB in a logical sequence 2. Sequenceis ery important in transaction 3. Itisa logical unt of work that contains one or mare SQL statements. The resuit of al these statements in a transaction ether gets completed successfully (al the changes made tothe database are permanent) orf at any point any failure happens it gets rollbacked (all the changes being done are undone) ACID Properties 1. Toensure integrity of the data, we require thatthe DB system maintain the following properties ofthe transaction. 2. atomicity 1. Either ll operations of transaction are reflected propery inthe DB, or none are. 3. Consistency 1. Integrity constraints must be maintained before and after transaction 2. DBmustbe consistent aftr transaction happens. 4. Isolation 1. Even though muitiple transactions may execute concurrently, the system guarantees tha, forever pair of transactions Ti and Tit appears to Ti that either T finished execution before Ti started, or Tj started execution after Tfinished. Thus, each transaction is unaware of other transactions executing concurrently inthe system. 2. Multiple transactions can happen in the system in isolation, without interfering each other 5. Durability 1. Alter transaction completes successfully the changes it has made tothe database persist even f there are system fitures. ‘Transaction states Partially committed state Permanent store 1. After transaction is executed the changes ae saved inthe buffer inthe main memory ifthe changes made are permanent onthe DB then the state will transfer tothe committed state and if there is any failure, the T wil potorateesate 3. commited sate 1L._ When updates are made permanent on the DB. Then the Tis said to be inthe committed state. Rollback cant be dane from the committed states, New consistent state is achieved at this stage 4. Failed state 1. When Tis being executed and some failure occurs Due to this itis impossible to continue the execution of theT. 5. Aborted state 1. When T reaches the failed state, all the changes made in the buffer are reversed. After thatthe T rollback completely T reaches abort state after rollback D3‘ state prior tothe Tis achieved. 6. Terminated state 1L._Atransaction is sad to have terminated if has ether committed or aborted Recovery Mechanism Component of OBMS supports atomicity and durability. Shadow-copy scheme 1. Based on making copies of (ak, shadow copies) Assumption only one Tansaction ()is active ata time. ‘pointe called db-ponter is maintained on the ds which at any instant pons to current copy of D8 “that wants to update DB fst creates complete copy of DB Afurther updates are dane on new DB copy leaving the orignal copy (shadow copy) untouched !fatany pont the Thas tobe aborted the sytem deletes the rew copy. And theo copy isnot afected IFT succes its commited as, 1. OS makes sure all the pages ofthe new con of D8 written on the disk, 2. DBsystem updates the db-ponterto point the new copy of 8, 3. New copy snow the curent copy of D8, 4 Theold copyisdeleted 5, The Tis said to have been COMMITTED atthe point where the updated db-pointeris writen to disk. 8. Alomicity 1. fT fs at any time before dbpointeris updated the od content of DB are no afete. 2. Tabort canbe done by jst deleting the new copy of DB 3. Hence ether all updates are reflected or none 8 Durability 1. Suppose, system fas are any tne before the updated db-ponteris writen ods 2. When the sytem restarts tl ead db-ponter & wil ths, ee the orignal content of 8 and none ofthe eects of Twill be visible 3. Tisassumed tobe successful only when db-pointeris updated 4 Hfsytem fis aftr db-pointer has been updated. Before thal the pages ofthe new copy were writen to disk Hence, ‘when system restarts itil read new DB copy 10. The implementation i dependent on wrt tothe db pointer being atomic. Lucky disk system provide atomic updates to entire ‘lock or at east a disk sector. So, we make sure db-pointer es entirely in asingle sector. By storing db-pontr athe beginning cfabiock 1 Inefcent, sentire D8 is copied for every Tansacton Uap recvery nets Thelogisa sequence of records. Logo each transactions maintained in some stable storage sothatf any file occurs, then itcanbe recovered fom there. 2. _ifany operations performed onthe database, then t wil be recorded the log Butthe process of storing the logs shouldbe dne before the actual transactions applied in the database 4 Stable storage isa classification of computer data storage technology that guarantes atomicty fr any gven write operation andallows software tobe writen that robust against some hardware and power aus. 5. Deferred DB Modifications 1. Ensuring atomic by recording al the D8 modifications in the logbut defering the exciton fal the wrt operations nti the final action of the Thas been executed. 2. Laginformationis used to execute deferred writes when Tis completed 3 system crashed before the T completes ors aborted the information nthe logs are ignored 4-1 T completes, the records associated to tin the log file are used in executing the deferred writes. 5 flture occur while this updating is taking place, we preform redo 6. Immediate DB Modifications 1. D8 modifications tobe outputto the DB while the Tis tilin active stat. 8 modifications writen by ate Tare alld uncommitted maificatons. Inthe event of rash rT fale, system uses od value field ofthe og records to restore modified values. Update takes place only afer log records nastabe storage. Failure handing 1. Sytem failure before T completes, if aborted then old vale fields used o undo the 2 fT completes andsystem crashes, then new value Fld is used to redo T having commit gs inthe logs LEC-14: Indexing in DBMS Indexing is wed to optimise the perfomance of database by minimising the number fd aceseseuied when aqueryis processed “The indexis typeof data structure tis used to locate and access the data na database abe quickly. Speeds up operation with ea operations ike SELECT qui, WHERE caus et. Search Key: Contains copy of primary ky oranda key primary mean to access the tuple, it is the secondary mean. Index isabways srted. Indexing Methods 1. Pimary index (Ctustering Inde) 1. Afieray have severandies on diferent search sth dtafle conning the ears sequent ordered, 2 Primaryindexsaninder whos earch ey aso defines the sequetal order ofthe fle 2._NOTE-Thetem primary ndexs sometimes used to mean anindex na pimary ky. Howeve such usage s nonstandard and shoud be avoided. 3. Ales are odeted sequently on Some earch ey it cul be Primary Key or non-primary ey 4 Dense And Sparse Indices 1. Dense index 1. The dense indexcntains an indexrecrd forever search ey value inthe dita fe. 2. The indexrecord contains the earch key valu and pointer the fis ata record wth that search ey vale The est othe recocds wth these Search value would be stored sequently ae te fsecod 3. ltneedsmorespaceto tore nde eord sel The index recods hve the etch ey and ponte the actual recordonthe dk. 2. Sparseindex 1) Anindex recor appr for onl some ofthe search ey values. 2. Sparse ndex helps you to resolve the sues of dense ndexing in DBMS. nti methd of index technique 8 ‘ang of index corns stores the sme data blockades, and whe data need tbe retrieve, the block adress il be fetched ‘5. Primary Indexing can be based on Data file is sorted wert Primary Key attribute or non-key attributes. Based on Key atrbute 1. Dates sorted wt primary key tibute 2. Pkivilbe ued as search yn inde 5. Spars Indexwil be frmed en. of ents inthe inde le = oof bck in data 7. Based on Non-Ky tribute 1. Data e's sorted wt norte tribute 2a. fentesinthe index =unquenn-key att value in the data fle. 3. Tisisdens indenas athe unique eles hve an entry in the indexie 4. Eg, Lets assumethata company recited many empoyeesin varios department nts case, custeringindengin DBMS shoul be created forall employes who belong the same wl: dept. \ . 8 Muitsleelindex : — \— 1. ndexwith two or ore eves ; ‘2. Ifthe single level index become enough large that the binary ‘ousrindes search isl oul tke much te, We an rea own indexing into util evel othe able o- something ee. Data Reference: Pointe: holding the address of disk block — SearchKey | Data Reference ar acne up Indexing is optional but increases access speed ts nat the Key vate 2. Secondary index (Non-Clustering index) 1 Datafleis unsorted. Hence, rimary Indexing snot possible ee 2. Canbe done on key non key atibute 3. Called secondary indexing because normally one indexing is already \ ‘applied. 4. No.of ents in the index 5. Wsan example of Dense index 30. of record inthe data, 9. Advantages of Indexing 1. Faster access and retrieval of data 2 isles. 10. Limitations of indexing 1. Additional space stor indexable 2_Indexing Decrease performance in INSERT, DELETE, and UPDATE query Le NoSOL NoSQL. databases (aa “not only SOU) are nonabular databases and tre cata dierent than lato tables NoSQL databases come in a vary of types based on ther data model The mein types ae document, key-valve,wide-column, and 'aph They provide lnbe schemas ad scale easly wih arg amounts of at anc bigh user loads {They are schema tee 2. Data structures used are not tabulay, they are more flexible, has the ability to adjust dynamically. 2. anhandle huge amount of data (bg dt). 4 Most ofthe NoSQL ae open sources and ha the apaity of harzontal scaling 5 tjuststres data in some format ther than relational. History behind NoSQL 1. NoSQL databases emerge inthe lte 2000 asthe cost of storage amatcly decreased, Gone were the days of needing to create a comply, difcutto-manage date mode n order to aid data duplication. Developers (ther than storage) were becoming the primary cost of sofware development so NeSQl databases optimised for developer productivity 2. Data becoming unstructured more, hence structuring (defining schema in advance) them had becoming costly. 'NosQ database alow developers to tore huge amounts of unstructured data, ging them alot of exit. 4 Recogising the need to reply adap to changing requirements ina software system Developers needed the abit to teat icky and make changes throughout ther software tack — all he way downto the database. NoSQL databases gave them tis tex. 5 Cloud computing also rose in popularity, and developers began using pubic oud o hos their applications and data. They wonted the abit to distibute data aos multiple servers and rego to make the applications resent, o scale out instead cfscale up andtointligenty geo plac her data. Some NoSQl databases ike MongoD8 proud these capable, NoSQL Databases Advantages A Feibe Schema 1. RDBMS has pre-defined schema, which become an issue when we do not have alhe data with us or we need to change the schema i's. huge tsk change schema on the go. 8. Horizontal cating 1. Horizontal sang, also known a cale-ou, refer to binging on addtional nodes toshae the load. Tiss ft with telational databases duet the dificult in spreading ot related data across nodes, With nonelatonal databases, ths made simpler since colecons are sel-cotained and not coupled relational. This allows them tobe dstrbuted across nodes more simply as queries do not have tthe together across nodes. 2. Scaling horizontally is achieved through Sharding OR Replica-sets. C. High Availability 1. NSQL databases are highly available due to its auto replication feature ie. whenever any kind of failure happens data replicates tothe preceding consistent sate 2 Wa server fais, we can access that data fom another server as wel sin NoSQL database daa is stored at mulpe ._Exgy insert and read operations. 1. Quetes in NoSOL databases can be fester than SQL databases Why? Date in SOL databases i typically normalised 50 ‘queries for single objet rent requite you jon data from multiple tables. As your tables grow ins, the joins an become expensive. However data in NoSQL databases is typical stored in a way thats optimised for queries. The rule of thumb when you use MongoD8 is at thats accessed together shouldbe stored together. Queries typical do not require Joins othe queries are ver fst. 2 But dficat delete or update operations. E. Caching mechanism, F NoSQL usecase is more fr Cloud applications. Wen o use NosQl? 1. Fastpaced age development 2. Storage f structured and semistructured data 3. Huge volumes of ata 4. Requirements forsale out architecture 5. Modem application araigm ike micr-services and rettime seaming, NoSQL DB Misconceptions 1 Relaanship dats best suited forrelatina databases 1. common misconceptions that NOSQL databases or non eltional databases don store relationship data wel. NoSQL databases can tre eatonsip data — they ust tre diferent than latonal databases dn fat, when compared With relatonal databases, many fd modeling relationship dala in NoSQL databases to be ese than in elatonal databases, because elated data doesnt have tbe splt between tales. NaSQl data model allow related data to be rested within single data structure 2. NoSQL databases doit supprt ACD transactions 1. Another commen misconception is that NoSQL databases doit support ACID transactions. Some NoSQL databases like Mongo da, infact, support ACID transactions. 6. Types of NoSQL Data Models 1 Key-Value stores 1. Thesimplest typeof NoSQL database isa key-value store. Every dat element inthe database is stored asa key val pair consisting ofan attribute name (or key") anda value. na sense, a key-value stor is ikea relational database with only ‘wo columns the key or attribute name (such atte") and the value (such as Alaska") 2. Use casesinclude shopping cats user preferences and user profes. eg, Oracle NoSQL, Amazon DynamoDB, MangoD8 aso supports Key Value store, Reds. ‘key-value database associates a value (which can be anything from a number er simple sting to a complex objet) with key, which is used to keep track ofthe abject. nits simplest form, a key-value stores Uke @ dictionarylaray/map object {a It exists in most programming paradigms, but whichis stored in a persistent way and managed by a Database Management System (OMS) 5. Key-xolue dotaboses use compact, efficient index structures to be able to quikiy and reliably locate 2 value by its key, ‘making ther ideal for systems tat ned tobe abet find and retrieve data in constant time. {5 There are several use-cases where choosing 3 key value store approach isan optimal solution: 4) eal time random data access, eg, user session attributes in an online application such a gaming ofnance 1b) Caching mechanism for frequently acessed data or configuration based on keys Application i designed on simple key based queries. 2 Column-Oriented /Columnar / C-Store / Wide-Column 1. The dataisstored such that each ow ofa column willbe nett ather rows from that same column, 2 White a relational database stores data in rows and reads data row by row, 2 column store is organised asa st of clurmns. This means that when you want to run analytics on a small numberof columns, you can read those columns directy ‘without consuming memory withthe unwanted data. Columns are often ofthe same type and benefit from more efcient compression, making reads even faster, Columnar databases can quickly aggregate the value of a given column (adding up the total sales forthe year, for example). Use cases include analytics. 3. eg, Cassandra, RedShit, Snowflake 3. Document Based Stores 1. This DB store data in documents similar to JSON (avaScrpt Object Notation) objects. Each document contains pais of fields and values. The values cn typically be a varity of types incuding things like stings, numbers, booleans, arrays, or ‘objects. 2._Use cases include e-commerce platforms, trading platforms, and mobile app development across industries. 3. Supports ACID properties hence suitable for Transactions. 4 eg, MongoDB, CouchDB. 4. Graph Based Stores 1. A graph database focuses onthe relationship between data elements, Each elements stored as anode (such a a person ina socal media graph). The connections between elements are called links or relationships. n a graph database, ‘connections arefist-lass element of the database, stored directly In relational databases, Unks are implied, sing data to ‘xpress the relationships. 2. Agaph database is optimised to capture and search the connections between data elements, overcoming the overhead ‘associated wit JINing multiple tables in SQL. 3. Very few rea-word business systems can survive solely on graph queries. As 2 result graph databases are usually run alongside other more tradtonal databases. 4. Usecases include raud detection, social networks, and knowledge graphs. 7. NoSQL Databases Disadvantages 1 Data Redundancy 1 Sing data models in NoSQL databases ae typically optimised for queries and not for reducing data duplication, Nos. ‘databases can be larger than SQL. databases. Storage is curently so cheap that mast consider this a minor drawback, and ‘some NoSQ{ databases als support compression to reduce the storage footprint. 2. Update & Delete operations are costly 3._Alltype of NoSQL Data model does fui al ofyour application needs 1. Depending on the NoSQL. database type you select, you may not be able to achieve all of your use cases in a single database. For example, graph databases are exelent for analysing relationships in your data but may not provide what you need fo everyday retrieval of the data such as range queries. When selecting a NoSQL database, consider what your ‘se cases willbe anda general purpose database ke MongoD3 would bea better option. Does support ACID propetiesin general. 5. Doesnt support data entry wih consistency constrains 8 SQLVsNosQL S0L Databases NeBaL Databoces |) V/) Data Storage Model Tables with fixed rows and Documer ‘columns: dynamic columns, Grapn: nodes ool DevlopmentHstny | Oewoadin te 970s wna |evopdin i ie 200 wih ieieaagas"" |ecewensagscaneg Ses tran spteten ange driven by agile and DevOps: paca Examples Oracle, MySQL, Microsoft SQL Document: MongoDB and Sona raresiesac Gounod Dyraneb, Wd Cassandra and HBase, Graph: Naot ara sn pre Primary Pupose ner Purpose Dosimetry ‘Sos gest aa wh dine pees, We Shier shou ota wipe gy pater, Gpicwany ed ony Tears no coma Sia a fet Fie ‘Scaling ‘Vertical (Scale-up) Horizontal (scale-out across: ‘commodity servers) 0 Propane xpi Hit Sporn exentn e Hongo sows ‘yily aie "cay ot ed Dein tocbect mang (| request! Many do oro Ot mapping MongoDB documents map directly to data structures in most popular programming languages. 4 LEC-16: Types of Databases . Relational Databases 1 Based on Relational Model 2. Relational databases are quite popular, eventhough twas a sytem designed in the 1970. Also known as eatonl database ‘management systems (ROBMS), relational databases commoniy use Structured Query Language (SO) fr operations such 5 creating reading updating and deleting date. Relational databases stre information in discrete tables, which canbe JOINed together by fields known as foreign key. For example, you might havea User table which contains information about ll your ses, and jin ito Purchases table which contains information about al the purchases they've made MySQL, Microsoft SQL Server, and Oracle are types of latinal databases. they are ubiquitous having acquted a steady user base since te 1970s they ae highty optimised for working with structured data they provide stronger guarantee of data normalisation they use a wellknown querying language trough SQL Scalability issues (Horizontal Scaling) Data become hug, system become mare complex. bject Oriented Databases “The object-oriented data mode, is based on the object-oriented-programming paradigm, whichis now in wide use. Inheritance, object identity, and encapsulation (information hiding), with methods to provide an intrfce to objects are among the key concepts of object-oriented programming that have found applications in data modeling. The object-oriented {ta model also supports arch type syste, including structured and collection types While inheritance and, to some extent,

You might also like