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

Database Management System-New-Solution_ Download from (www.arjun00.com.np)

education purpose

Uploaded by

rakesh45096
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 views50 pages

Database Management System-New-Solution_ Download from (www.arjun00.com.np)

education purpose

Uploaded by

rakesh45096
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/ 50
DIPLOMA, CTEVT, QUESTION & SOLUTION Database Management System (for Diploma II Yrs. I Part) (DCOMIIT ) By Arjun Chaudhary Publisher in: www.arjun00.com.np www.facebook.com/arjun00.com.np Authors © Arjun Chaudhary **Dont Remove these page, Otherwise You Got Copyright Ac 1 www.arjun00.com.np “Download from www.arjun00.com.np S.No Exam Year, Month 1. 2078 Kartik Regular/Back 2. 2079 Bhadra Regular/Back *** This Pdf download from www.arjun00.com.np *** This Solution is For Educational Purpose Only. *** Any Problem Than Contact on Email:- [email protected] pont Remove these page, Otherwise You Got copyright «AC? 2 ~~» www.arjun00.com.np “Download from www.arjun00.com.np Database Management System ( DCOM ) 35°" ( 2078 ) Question Paper Solution. Compile by © Arjun Chy Website :- www.arjun00.com.np Facebook :-www.facebook.com/Arjun00.com.np > Data :- Data is a raw fact or unorganized form (such as alphabets, numbers, or symbols) that refers to or represent, condition, ideas or objects. Data is limitless and present everywhere in the universe. > Information :- Data that has been verified to be accurate and timely. Data that Is specific and organized for a purpose. Data that Is represented within a context that gives it meaning and relevance. Data that can lead to an increase in understanding and decrease in uncertainty is called information > Database :- A database is information that is set up for easy access, management and updating. Computer databases typically store aggregations of data records or files that contain information, such as sales transactions, customer data, financials and product information. Databases are used for storing, maintaining and accessing any sort of data. They collect information on people, places or things. Copyright © belongs to the Arjun Chy AC 3. wwwarjun00.com.np “Download from www.arjun00.com.np > DBMS :- A database management system (DBMS) is system software for creating and managing databases. A DBMS makes it possible for end users to create, protect, read, update and delete data ina database. The most prevalent type of data management platform, the DBMS essentially serves as an interface between databases and users or application programs, ensuring that data is consistently organized and remains easily accessible. » Data model is a collection of conceptual tools used for describing data, data relationships and data constraints. The model should enable the designer to incorporate a major portion of semantics of the database in the system. > The Different type of Data Model:- * Conceptual data model ° Logical data model * Physical data model Data Model Conceptual Data Model Copyright © belongs to the Arjun Chy AC 4 — wwwarjun00.com.np **Download from www.arjun00.com.np 1. Conceptual Data Model > The conceptual data model describes the database at a very high level and is useful to understand the needs or requirements of the database. It is this model that is used in the requirement-gathering process i.e. before the Database Designers start making a particular database. One such popular model is the entity/relationship model (ER model). The E/R model specializes in entities, relationships, and even attributes that are used by database designers. In terms of this concept, a discussion can be made even with non-computer science(non-technical) users and stakeholders, and their requirements can be understood. 2. Representational Data Model » This type of data model is used to represent only the logical part of the database and does not represent the physical structure of the database. The representational data model allows us to focus primarily, on the design part of the database. A popular representational model is a Relational model. The relational Model consists of Relational Algebra and Relational Calculus. In the Relational Model, we basically use tables to represent our data and the relationships between them. It is a theoretical concept whose practical implementation is done in Physical Data Model. The advantage of using a Representational data model is to provide a foundation to form the base for the Physical model Copyright © belongs to the Arjun Chy AC 5 — wwwarjun00.com.np “Download from www.arjun00.com.np 3. Physical Data Model » The physical Data Model is used to practically implement Relational Data Model. Ultimately, all data in a database is stored physically on a secondary storage device such as discs and tapes. This is stored in the form of files, records, and certain other data structures. It has all the information on the format in which the files are present and the structure of the databases, the presence of external data structures, and their relation to each other. Here, we basically save tables in memory so they can be accessed efficiently. In order to come up with a good physical model, we have to work on the relational model in a better way. Structured Query Language (SQL) is used to practically implement Relational Algebra. > Entity-Relationship (E-R) Diagram An entity-relationship diagram (or, E-R diagram) is a detailed, logical, and graphical representation of the data for an organization or business area. It is a graphical representation of an E-R model. ERD illustrate the logical structure of databases. Peter Chen developed ERDs in 1976. ERD is a picture showing the information created, stored, and used bya business system. —_(wane) Ca) et > fon.) (Prone) > tT a ~\ Employees jorks In>——|Departments ye | — Types of Relationship Three types of relationships can exist between entities: one-to-one, one-to-many, and many-to- many. ™ One-to-One Relationship A one-to-one relationship, abbreviated 1:1, exists when exactly one of the second entity occurs for each instance of the first entity. Figure below shows examples of several 1:1 relationships. A number 1 is placed alongside each of the two connecting lines to indicate the 1:1 relationship. HICLE 1 1 Veal AssieneD VEHICLE = One-to-Many Relationship A one-to-many relationship, abbreviated 1:M, exists when one occurrence of the first entity can relate to many instances of the second entity, but each instance of the second entity can associate with only one instance of the first entity. The line connecting the many entity is labeled with the letter M, and the number 1 labels the other connecting line. 1 M DEPARTMENT EMPLOYS EMPLOYEE Copyright © belongs to the Arjun Chy AC 7 ~~ wwwaarjund0.com.np “Download from www.arjun00.com.np = Many-to-Many Relationship A many-to-many relationship, abbreviated M:N, exists when one instance of the first entity can relate to many instances of the second entity, and one instance of the second entity can relate to many instances of the first entity. One of the connecting lines is labeled with the letter M, and the letter N labels the other connection. M N ‘STUDENT ENROLLS class > Copyright © belongs to the Arjun Chy AC 8 — wwwarjun00.com.np “Download from www.arjun00.com.np oe per ID Peminna —€ 10) per_module ine Copyright © belongs to the Arjun Chy AC 9 www.arjun00.com.np “Download from www.arjun00.com.np » Structured Query Language (SQL) refers to a standard programming language utilized to extract, organize, manage, and manipulate data stored in relational databases. SQL is thereby referred to as a database language that can execute activities on databases that consist of tables made up of rows and columns. EMPLOYEE. Empid Name Salary ‘Address 101 Ravi Regmi 2000 Butwal 103 Keshab Bashyal 3000 | Kathmandu 103 ‘Angeeta Rijal ~~ 20,000 | ~ Surkhet 104 Rajeev Khadka 10,000 Gulmi Select * from employee where employeeName Like 'R%' Select * from employee where Select >=8000 Copyright © belongs to the Arjun Chy AC 10. wwwarjun00.com.np “Download from www.arjun00.com.np > Normalization is needed in a database to eliminate redundancy and improve data integrity. It ensures that data is efficiently organized into separate tables, reducing data duplication and inconsistencies, and making it easier to maintain and query the database. Normalization Normalization is the process of creating table designs by assigning specific fields or attributes to each table in the database. A table design specifies the fields and identifies the primary key in a particular table or file. Normalization involves applying a set of rules that can help you identify and correct inherent problems and complexities in your table designs. The concept of normalization is based on the work of Edgar Codd, a British computer scientist who formulated the basic principles of relational database design. First Normal Form (1NF) > Arelation is in 1NF if every attribute is a single-valued attribute or it does not contain any multi-valued or composite attribute, i.e., every attribute is an atomic attribute. If there is a composite or multi-valued attribute, it violates the 1NF. To solve this, we can create a new row for each of the values of the multi-valued attribute to convert the table into the 1NF. Let’s take an example of a relational table that contains the details of the employees of the company. Copyright © belongs to the Arjun Chy AC 11. wwwarjund0.com.np “*Download from www.ariun00.com.no Employee Code Employee Name Employee Phone Number 101 John 198765623,998234123 101 John (89023467 102 Ryan 76213908 [13 ‘Stephanie ;e322s2—tCSC:«* Here, the Employee Phone Number is a multi-valued attribute. So, this relation is not in ANF. To convert this table into 1NF, we make new rows with each Employee Phone Number as a new row as shown below: Employee Code Employee Name Employee Phone Number 101 John 998234123 101 Joba 198765623 101 John 89023467 102 Ryan 76213908 103 “Second Normal Form (2NF) Stephanie 98132452 > The normalization of 1NF relations to 2NF involves the elimination of partial dependencies. A partial dependency in DBMS exists when any non-prime attributes, i.e., an attribute not a part of the candidate key, is not fully functionally dependent on one of the candidate keys. For a relational table to be in second normal form, it must satisfy the following rules:- = The table must be in first normal form. Copyright © belongs to the Arjun Chy AC 12 www.arjun00.com.np “Download from www.arjun00.com.np = It must not contain any partial dependency, i.e., all non-prime attributes are fully functionally dependent on the primary key. If a partial dependency exists, we can divide the table to remove the partially dependent attributes and move them to some other table where they fit in well. Let us take an example of the following table to understand what is partial dependency and how to normalize the table to the second normal form: Employee Code | Project ID joyee Name | Project Name 101 PO3 John Projectl03 101 POL John Project!01 102 P04 Ryan Project104 108 P02 Stephanie Project102 In the above table, the prime attributes of the table are Employee Code and Project ID. We have partial dependencies in this table because Employee Name can be determined by Employee Code and Project Name can be determined by Project ID. Thus, the above relational table violates the rule of 2NF. The prime attributes in DBMS are those which are part of one or more candidate keys. To remove partial dependencies from this table and normalize it into second normal form, we can decompose the table into the following three tables: Employee Code Employee Name 101 John 101 John 102 Ryan 103 Stephanie Copyright © belongs to the Arjun Chy AC 13. www.arjun00.com.np “Download from www.arjun00.com.np Employee Code Project ID 101 P03 101 POL 102 P04 103 P02 Project ID Project Name P03 Project103 Pol Project101 PO4 Project104 P02 Project102 Thus, we’ve converted the table into 2NF by decomposing it into , and tables. As you can see, the above tables satisfy the following two rules of 2NF as they are in 1NF and every non-prime attribute is fully dependent on the primary key. The relations in 2NF are clearly less redundant than relations in 1NF. However, the decomposed relations may still suffer from one or more anomalies due to the transitive dependency. We will remove the transitive dependencies in the Third Normal Form. “Third Normal Form (3NF) > The normalization of 2NF relations to 3NF involves the elimination of transitive dependencies in DBMS. A functional dependency X -> Z is said to be transitive if the following three functional dependencies hold:- = X->Y = Y does not ->X = Y->Z Copyright © belongs to the Arjun Chy AC 14. www.arjund0.com.np “Download from www.arjun00.com.np For a relational table to be in third normal form, it must satisfy the following rules:- 1. The table must be in the second normal form. 2. No non-prime attribute is transitively dependent on the primary key. 3. For each functional dependency X -> Z at least one of the following conditions hold:- = Xis a super key of the table. = Zisa prime attribute of the table. If a transitive dependency exists, we can divide the table to remove the transitively dependent attributes and place them to a new table along with a copy of the determinant. Let us take an example of the following table to understand what is transitive dependency and how to normalize the table to the third normal form: Employee Code | Employee Name | Employee Zipcode | Employee City 101 John 110033 Model Town 101 John 110044 Badarpur 102 Ryan 110028 Naraina 103 Stephanie 110064 Hari Nagar The above table is not in 3NF because it has Employee Code -> Employee City transitive dependency because:- = Employee Code -> Employee Zipcode = Employee Zipcode -> Employee City Also, Employee Zipcode is not a super key and Employee City is not a prime attribute. To remove transitive dependency from this table and normalize it into the third normal form, we can decompose the table into the following two tables: Copyright © belongs to the Arjun Chy AC 15. wwwarjun00.com.np “Download from www.arjun00.com.np Employee Code | Employee Name | Employee Zipcode 101 John 110033 101 John 110044 102 Ryan 110028 103 Stephanie 110064 Employee Zipcode Employee City 110033 Model Town 110044 Badarpur 110028 Naraina 110064 Hari Nagar Thus, we’ve converted the table into 3NF by decomposing it into and tables as they are in 2NF and they don’t have any transitive dependency. The 2NF and 3NF impose some extra conditions on dependencies on candidate keys and remove redundancy caused by that. However, there may still exist some dependencies that cause redundancy in the database. Copyright © belongs to the Arjun Chy AC 16 www.arjun00.com.np “Download from www.arjun00.com.np > Transactions are a set of operations that are used to perform some logical set of work. A transaction is made to change data in a database which can be done by inserting new data, updating the existing data, or by deleting the data that is no longer required. There are certain types of transaction states which tell the user about the current condition of that database transaction and what further steps to be followed for the processing. > ACID properties are the four key characteristics that define the reliability and consistency of a transaction in a Database Management System (DBMS). The acronym ACID stands for Atomicity, Consistency, Isolation, and Durability. Here is a brief description of each of these properties:- = Atomicity: Atomicity ensures that a transaction is treated as a single, indivisible unit of work. Either all the operations within the transaction are completed successfully, or none of them are. If any part of the transaction fails, the entire transaction is rolled back to its original state, ensuring data consistency and integrity. = Consistency: Consistency ensures that a transaction takes the database from one consistent state to another consistent state. The database is in a consistent state both before and after the transaction is executed. Constraints, such as unique keys and foreign keys, must be maintained to ensure data consistency. = Isolation: Isolation ensures that multiple transactions can execute concurrently without interfering with each other. Each transaction must be isolated from other transactions until it is completed. This isolation prevents dirty reads, non-repeatable reads, and phantom reads. Copyright © belongs to the Arjun Chy AC 17. wwwarjun00.com.np “Download from www.arjun00.com.np = Durability: Durability ensures that once a transaction is committed, its changes are permanent and will survive any subsequent system failures. The transaction’s changes are saved to the database permanently, and even if the system crashes, the changes remain intact and can be recovered. > The Advantages of DBMS approach:- Improved Data Sharing: DBMS enables data sharing among multiple users and applications. Multiple users can access the same data simultaneously, without interfering with each other's work. This improves collaboration and productivity, as well as reduces the risk of data duplication. Data Integration: DBMS allows the integration of data from multiple sources. This means that data can be collected from various systems and combined into a single database, which makes it easier to access and analyze. Data Security: DBMS provides various security features such as access control, authentication, and encryption to safeguard data from unauthorized access and prevent data loss or corruption. Data Consistency: DBMS enforces consistency in data by ensuring that data is accurate, complete, and up-to-date. This helps to avoid data inconsistencies and errors that can result in significant consequences for an organization. Data Integrity: DBMS ensures that data is stored and retrieved without any loss or corruption. It provides mechanisms such as transaction management and recovery, which guarantees data integrity even in case of system failures. Copyright © belongs to the Arjun Chy Ac 18 www.arjun00.com.np “Download from www.arjun00.com.np > Relational mapping is also known as ORM. Object-relational mapping (ORM) is a way to align programming code with database structures. ORM uses metadata descriptors to create a layer between the programming language and a relational database. It thus connects object-oriented program (OOP) code with the database and simplifies the interaction between relational databases and OOP languages. The idea of ORM is based on abstraction. The ORM mechanism makes it possible to address, access and manipulate objects without having to consider how those objects relate to their data sources. ORM lets programmers maintain a consistent view of objects over time, even as the sources that deliver them, the sinks that receive them and the applications that access them change. Developers can also perform various data creating, reading, updating and deleting (CRUD) operations in relational databases without using SQL. This capability is particularly useful for developers who either don't know SQL or don't want to waste time writing SQL code. With ORM, they don't have to understand and write SQL or rely on SQL query builders to add an abstraction layer to the SQL code. > Data recovery can be defined as a process of obtaining the information located on a storage device that cannot be accessed by the standard means due to its previous deletion or certain damage to the digital medium. Different approaches are used to regain the missing files, yet, only on the condition that their content is present somewhere within the storage. For instance, data recovery doesn't cover the situations when a file has never been written to a persistent storage, like documents that were created but could not be eventually saved to the hard disk drive due to a power failure. Also, none of the existing restore methods can cope with the cases of permanent erasure which occurs when some other information occupies its storage space — under such circumstances, the lost files can only be retrieved from an external backup. Copyright © belongs to the Arjun Chy Ac 19 www.arjun00.com.np “Download from www.arjun00.com.np In general, data recovery techniques are divided into two types: software- based and ones involving the repair or replacement of the damaged hardware components in a laboratory setting. A software-based approach is employed in the majority of cases and involves the use of specialized utilities able to interpret the logical structure of the problem storage, read out the required data and deliver it to the user in a usable form for further copying. Physical repairs are conducted by specialists in the most severe instances, for example, when some mechanical or electrical parts of the drive no longer work properly — in this case, all the measures are directed towards a one- time extraction of the critical content, without the possibility of continued usage of the affected device. Copyright © belongs to the Arjun Chy AC 20 wwwarjun00.com.np **Download from www.arjun00.com.np Database Management System ( DCOM ) 3™¢Se™ (2079 ) Question Paper Solution. Compile by © Arjun Chy Website :- www.arjun00.com.np Facebook :-www.facebook.com/Arjun00.com.np > The Advantages of using DBMS approach:- Improved Data Sharing: DBMS enables data sharing among multiple users and applications. Multiple users can access the same data simultaneously, without interfering with each other's work. This improves collaboration and productivity, as well as reduces the risk of data duplication. Data Integration: DBMS allows the integration of data from multiple sources. This means that data can be collected from various systems and combined into a single database, which makes it easier to access and analyze. Data Security: DBMS provides various security features such as access control, authentication, and encryption to safeguard data from unauthorized access and prevent data loss or corruption. Data Consistency: DBMS enforces consistency in data by ensuring that data is accurate, complete, and up-to-date. This helps to avoid data inconsistencies and errors that can result in significant consequences for an organization. Data Integrity: DBMS ensures that data is stored and retrieved without any loss or corruption. It provides mechanisms such as transaction management and recovery, which guarantees data integrity even in case of system failures. Copyright © belongs to the Arjun Chy AC 21. wwwarjun00.com.np “Download from www.arjun00.com.np » The three schema architecture describes how the data is represented or viewed by the user in the database. This architecture is also known as three-level architecture and is sometimes called ANSI/ SPARC architecture. The three schema architecture divides the database into three-level to create a separation between the physical database and the user application. In simple words, this architecture hides the details of physical storage from the user. The database administrator (DBA) should be able to change the structure of database storage without affecting the user’s view. > This architecture contains three layers or levels of the database management system:- = External level External = Conceptual level level = Internal level Conceptual level Internal level DBMS Architecture Copyright © belongs to the Arjun Chy AC 22. www.ariun00.com.np **Download from www.arjun00.com.np = External or View level: This is the highest level of database abstraction. External or view level describes the actual view of data that is relevant to the particular user. This level also provides different views of the same database for a specific user or a group of users. An external view provides a powerful and flexible security mechanism by hiding the parts of the database from a particular user. = Conceptual or Logical level: The conceptual level describes the structure of the whole database. This level acts as a middle layer between the physical storage and user view. It explains what data to be stored in the database, what relationship exists among those data, and what the data types are. There is only one conceptual schema per database. Database administrator and the programmers work at this level. This level does not provide any access or storage details but concentrates on the relational model of the database. The conceptual schema also includes features that specify the checks to retain integrity and consistency. Internal or Physical level: This is the lowest level of database abstraction. It describes how the data is actually stored in the database and provides methods to access data from the database. It allows viewing the physical representation of the database on the computer system. The interface between the conceptual schema and the internal schema identifies how an element in the conceptual schema is stored and how it may be accessed. If there is any change in the internal or physical schema, it needs to be addressed to the interface between the conceptual and internal schema. But there is no need to change in the interface of a conceptual and external schema. It means that the changes in physical storage devices such as hard disks, and the files organized on storage devices, are transparent to application programs and users. Copyright © belongs to the Arjun Chy Ac 23. www.arjun00.com.np “Download from www.arjun00.com.np i i E-R diagram of "Library Management system > Client server network architecture consists of two kinds of computers: clients and servers. Clients are the computers that that do not share any of its resources but requests data and other services from the server computers and server computers provide services to the client computers by responding to client computers requests. Normally servers are powerful computers and clients are less powerful personal computers. Web servers are included as part of a larger package of internet and intranet related programs for serving e- mail, downloading requests for FTP files and building and publishing web pages. Copyright © belongs to the Arjun Chy AC 24 > wwwarjun00.com.np y “Download from www.arjun00.com.np ae C Internet )— Clients ? Li / Server = The client/ server architecture reduces network traffic by providing a query response to the user rather than transferring total files. = The client/ server model improves multi-user updating through a graphical user interface (GUI) front end to the shared database. = Easy to implement security policies, since the data are stored in central location = Simplified network administration «Advantages «Disadvantages = Failure of the server causes whole network to be collapsed = Expensive than P2P, Dedicated powerful servers are needed = Extra effort are needed for administering and managing the server. Client/Server Model > The client-server model is a computing model that acts as distributed application which partitions tasks or workloads between the providers of a resource or service, called servers, and service requesters, called clients. Copyright © belongs to the Arjun Chy Ac 25 www.arjun00.com.np “Download from www.arjun00.com.np Often clients and servers communicate over a computer network on separate hardware, but both client and server may reside in the same system. A server machine is a host that is running one or more server programs which share their resources with Clients. A client does not share any of its resources, but requests a server's content or service function. Clients therefore initiate communication sessions with servers which await incoming requests. > The different kinds of join operations of relational algebra are :- = CROSS JOIN :- CROSS JOIN is the simplest form of JOIN. It matches each row from a database table with all other rows. In other words, it gives us the union of each row of the first table with all the records in the second table. A CROSS JOIN operation returns the Cartesian product of sets of rows from the joined tables. CROSS JOIN INNER JOIN:- INNER JOIN is a JOIN command used to combine rows from both tables that satisfy the given condition. Using INNER JOIN is essentially finding the intersection of two data tables. This is the most commonly used JOIN type and is considered the default JOIN Operation. Copyright © belongs to the Arjun Chy Ac 26 www.arjun00.com.np “Download from www.arjun00.com.ny INNER JOIN = LEFT (OUTER ) JOIN :- A LEFT JOIN (or LEFT OUTER JOIN) is very different from an INNER JOIN. Instead of restricting the results obtained in both tables, it restricts only the results in the left table (A). That is, if the ON clause has no corresponding record in table B, 1 row in the result is still returned but with a NULL value for each column in table B. It returns all values from the left table + those corresponding to the right table or null (when the values in the right table do not match). LEFT OUTER JOIN table 2 | / RIGHT ( OUTER ) JOIN :- RIGHT JOIN (or RIGHT OUTER JOIN) is the opposite of LEFT JOIN. RIGHT JOIN is a JOIN type that results in all columns from the right table even if no matching rows are found in the left table. Where no match is found in the table on the left, the result is Null. Copyright © belongs to the Arjun Chy AC 27. wwwarjun00.com.np “Download from www.arjun00.com.np To be specific, RIGHT JOIN is almost the same as LEFT JOIN, except that the order of the tables is reversed. Each record from the right table, B will be returned and NULL will be returned for rows that do not have a corresponding record in table A. RIGHT OUTER JOIN = FULL (OUTER) JOIN :- FULL (OUTER) JOIN combines both the results of the LEFT OUTER JOIN and the RIGHT OUTER JOIN. These types of JOINs take records of both tables, and fill the corresponding missing rows on both sides with NULLs. In other words, it can detect records with no matches in the joined table and return NULL records of the joined table if no match is found. Some database systems do not support FULL OUTER JOIN, but it can be replaced by using LEFT and RIGHT OUTER JOIN with UNION. FULL OUTER JOIN Copyright © belongs to the Arjun Chy Ac 28 www.arjun00.com.np “Download from www.arjun00.com.np > Normalization is the process of creating table designs by assigning specific fields or attributes to each table in the database. A table design specifies the fields and identifies the primary key in a particular table or file. Normalization involves applying a set of rules that can help you identify and correct inherent problems and complexities in your table designs. The concept of normalization is based on the work of Edgar Codd, a British computer scientist who formulated the basic principles of relational database design. » Transaction processing ensures that related data is added to or deleted from the database simultaneously, thus preserving data integrity in your application. In transaction processing, data is not written to the database until a commit command is issued. When this happens, data is permanently written to the database. > The Desirable properties of transactions, often referred to as ACID properties, ensure the reliability and integrity of data in a database system. ACID stands for:- = Atomicity: Atomicity ensures that a transaction is treated as a single, indivisible unit of work. Either all the operations within the transaction are completed successfully, or none of them are. If any part of the transaction fails, the entire transaction is rolled back to its original state, ensuring data consistency and integrity. Copyright © belongs to the Arjun Chy Ac 29 www.arjun00.com.np “Download from www.arjun00.com.np = Consistency: Consistency ensures that a transaction takes the database from one consistent state to another consistent state. The database is in a consistent state both before and after the transaction is executed. Constraints, such as unique keys and foreign keys, must be maintained to ensure data consistency. Isolation: Isolation ensures that multiple transactions can execute concurrently without interfering with each other. Each transaction must be isolated from other transactions until it is completed. This isolation prevents dirty reads, non-repeatable reads, and phantom reads. = Durability: Durability ensures that once a transaction is committed, its changes are permanent and will survive any subsequent system failures. The transaction’s changes are saved to the database permanently, and even if the system crashes, the changes remain intact and can be recovered. > Structured Query Language (SQL) refers to a standard programming language utilized to extract, organize, manage, and manipulate data stored in relational databases. SQL is thereby referred to as a database language that can execute activities on databases that consist of tables made up of rows and columns. “Applications of SQL :- = SQL is used by developers and DBAs (Database Administrators) in writing Data Integration Scripts. = Retrieving Information Copyright © belongs to the Arjun Chy AC 30. wwwarjun00.com.np “Download from www.arjun00.com.np = It is used to deal with analytical queries to analyze the data and get instincts from it. = Modification/Manipulation of data and database table such as Insertion, Deletion and Updation. “+ Advantages of SQL:- = Data integrity = Standardized query language = Scalability = ACID properties = Data security “+ Disadvantages of SQL: = Complexity = Performance challenges = Not ideal for unstructured data = Vendor lock-in = Scaling difficulties > The basic SQL queries with examples are:- = SELECT:- Retrieve data. Example: “SELECT * FROM employees; INSERT:- Add records. Example: ‘INSERT INTO customers (name, email) VALUES (‘Arjun', ‘[email protected]');” = UPDATE:- Modify records. Example: “UPDATE products SET price = 29.99 WHERE id = 101; = DELETE:- Remove records. Example: ‘DELETE FROM orders WHERE order_id = 123; Copyright © belongs to the Arjun Chy AC 31. wwwarjun00.com.np “Download from www.arjun00.com.np » Testing for serializability is a critical aspect of concurrency control in database management systems. Serializability ensures that concurrent transactions produce the same result as if they were executed sequentially, preserving data consistency and integrity. It helps prevent issues such as data anomalies and conflicts that can arise when multiple transactions access and modify the same data simultaneously. “To determine if a schedule is serializable:- = Conflict Serializability:- Check for conflicts (read-write and write- write) between transactions and create a precedence graph. If the graph contains no cycles, the schedule is serializable. = View Serializability:- Execute the schedule on a temporary database and compare its final state with all possible sequential executions. If the states match for all orders, the schedule is serializable. Copyright © belongs to the Arjun Chy Ac 32 www.arjun00.com.np “Download from www.arjun00.com.np » Constraints are guidelines or limitations imposed on database tables to maintain the integrity, correctness, and consistency of the data. Constraints can be used to enforce data linkages across tables, verify that data is unique, and stop the insertion of erroneous data. A database needs constraints to be reliable and of high quality. > Its Types :- = Primary Key Constraint: A constraint that ensures each row in a table has a unique identifier, which serves as the primary means of identifying and accessing individual records within the table. = Unique Constraint: A constraint that requires values in a specified column or set of columns to be unique across all rows in a table, preventing duplicate entries in that column(s). = Foreign Key Constraint: A constraint that establishes a relationship between two tables by specifying that the values in one table's column(s) must match the values in another table's primary key column(s). This enforces referential integrity between related tables. = Check Constraint: A constraint that defines a specific condition or expression that column values must meet, ensuring that only valid data is allowed in that column. = Default Constraint: A constraint that specifies a default value for a column. If no value is provided during an insert operation, the default value is used. = Not Null Constraint: A constraint that requires a value to be provided for a column during insert operations, disallowing the insertion of null values in that column. Copyright © belongs to the Arjun Chy Ac 33 www.arjun00.com.np “Download from www.arjun00.com.np > The need for security in a DBMS is to protect sensitive data from unauthorized access, ensure data integrity, and prevent data breaches or unauthorized modifications. It safeguards against data theft, corruption, and ensures compliance with privacy regulations and business requirements. > Encryption is the process of converting plaintext data into a secure and unreadable format (cipher-text) using encryption algorithms and keys. It ensures data confidentiality and protects it from unauthorized access during transmission or storage. > Decryption is the reverse process of converting cipher-text back into plaintext using decryption algorithms and keys. It allows authorized users to access and interpret the encrypted data, restoring it to its original, readable form. >The roles of Database Administrators (DBAs) are :- = Database Design: DBAs design the database schema, defining tables, relationships, and data structures for efficient data storage and retrieval. Copyright © belongs to the Arjun Chy AC 34. wwwarjun00.com.np “Download from www.arjun00.com.np = Data Security: They enforce access controls, authentication, and authorization to protect data from unauthorized access and ensure compliance with security policies. = Backup and Recovery: DBAs perform regular backups and develop recovery strategies to minimize data loss and system downtime during failures. = Performance Tuning: They monitor and optimize database performance, identifying bottlenecks and optimizing queries and configurations. = User Management: DBAs manage user accounts, permissions, and roles, granting appropriate access to database resources. = Data Maintenance: They ensure data consistency and integrity by enforcing constraints and maintaining data quality. > A database administrator (DBA) is the information technician responsible for directing and performing all activities related to maintaining a successful database environment. A DBA makes sure an organization's databases and related applications operate functionally and efficiently. Copyright © belongs to the Arjun Chy Ac 35 www.arjun00.com.np “Download from www.arjun00.com.np > Attributes are properties or characteristics of entities in a database. They describe the data that can be stored for each entity. Attributes can be simple or composite. Simple attributes represent atomic, indivisible data, while composite attributes are composed of multiple sub-attributes. Attributes can also be single-valued or multi-valued. Single-valued attributes hold a single value for each entity, while multi-valued attributes can hold multiple values. Example: In an ER diagram for a "Person" entity, attributes could include "Name" (simple, single-valued), "Address" (composite), and "Phone Numbers" (multi-valued). > Keys are attributes (or combinations of attributes) that uniquely identify individual instances (rows) of an entity in a database table. There are different types of keys, including: = Primary Key: A primary key uniquely identifies each entity instance in a table. It must contain unique and non-null values. = Candidate Key: A candidate key is an attribute (or combination of attributes) that could potentially serve as a primary key. = Foreign Key: A foreign key is an attribute that establishes a link between two tables by referencing the primary key of another table. Example: In an ER diagram for a "Product" entity, the "ProductID" attribute could serve as the primary key, ensuring that each product has a unique identifier. Copyright © belongs to the Arjun Chy Ac 36 www.arjun00.com.np “Download from www.arjun00.com.np > Two-phase locking (2pl) is a concurrency control method that guarantees seralizability. It is also the name of the resulting set of the data base transaction schedules (histories). The protocol utilizes locks, applied by a transaction to data, which may block (interpreted as signals to stop) other transaction form accessing the same data during the transactions life. > Timestamp ordering is a concurrency control technique in databases that uses timestamps to manage the execution order of transactions. Each transaction is assigned a unique timestamp, typically based on system time or a logical counter. Transactions with older timestamps have higher priority and are allowed to proceed, while transactions with newer timestamps might be delayed or rejected to ensure data consistency. This approach effectively prevents conflicts, such as simultaneous writes or reads during writes, and guarantees serializability by enforcing a structured order based on timestamps. After completion, a transaction's timestamp may be updated to reflect its completion time, ensuring newer transactions aren't unnecessarily blocked by older ones. Copyright © belongs to the Arjun Chy AC 37. wwwarjun00.com.np “Download from www.arjun00.com.np > functional dependency is a concept that specifies the relationship between two sets of attributes where one attribute determines the value of another attribute. It is denoted as X > Y, where the attribute set on the left side of the arrow, X is called Determinant, and Y is called the Dependent. Functional dependencies are used to mathematically express relations among database entities and are very important to understand advanced concepts in Relational Database System and understanding problems in competitive exams like Gate. “elts Types:- = Trivial Functional Dependency: This is a basic, self-evident relationship where an attribute is functionally dependent on itself, such as {Age} > {Age}. = Non-Trivial Functional Dependency: These are more meaningful relationships that exist between attributes, providing valuable information about how they relate, like {Employee_ID} > {Employee_Name}. Multivalued Functional Dependency: This type involves an attribute being dependent on another but taking multiple values for each value of the dependent attribute. For instance, {Student_ID} > {Course_Name} in a student-course database. Copyright © belongs to the Arjun Chy Ac 38 www.arjun00.com.np “Download from www.arjun00.com.np = Transitive Functional Dependency: It involves three attributes, where one attribute is functionally dependent on another through a third attribute, expressing indirect relationships. An example is {Country} > {City} when combined with {City} > {Postal_Code} to determine postal codes indirectly through cities. ~Data VS Information Data is the raw fact. It is a processed form of data. It is not significant to a business. Data is an atomic level piece of information. It is significant to a business. It is a collection of data. Example: Product name, Name of student. Example: Report card of student. It is a phenomenal fact. Itis organized data. This is the primary level of intelligence. May or may not be meaningful. Itis a secondary level of intelligence. Always meaningful. Understanding is difficult. Understanding is easy. Copyright © belongs to the Arjun Chy AC 39 www.arjun00.com.np “Download from www.arjun00.com.np >» INF Vs 2NF In order to be in 1NF any relation must | In order to be in 2NF any relation must be 1 be atomic and should not contain any in 1NF and should not contain any partial composite or multi-valued attributes. dependency. The identification of functional 2. dependency is not necessary for first normal form. The identification of functional dependency is necessary for second normal form First Normal form only deals with the 3, schema of the table and it does not handle the update anomalies. Second normal form handles the update anomalies. A relation in 1NF may or may not be in 4 | ONe A relation in 2NF is always in 1NF. The primary key in case of frst normal’ | TH Primary key in case of second normal 5. | sormcan bea compohiine form cannot be a composite key in case it g arises any partial dependency. The main goal of first normal form is to The main goal of second normal form is to si Giminate the redundant data within the actually ensure the data dependencies The first normal form is less stronger The second normal form is comparatively 7 than the second normal form. more strong than first normal form. > Security is needed to protect sensitive data, prevent unauthorized access, maintain data integrity, ensure compliance with regulations, and safeguard against cyber threats, data breaches, and unauthorized use. Copyright © belongs to the Arjun Chy AC 40. www.arjund0.com.np “Download from www.arjun00.com.np ri itis already in 4NE Itis already in 1NF as well as in 2NF also In 2NF non-prime attributes are allowed to _| In 3NF non-prime attributes are only 2. be functionally dependent on non-prime allowed to be functionally dependent on attributes. Super key of relation. No partial functional dependency of non- No transitive functional dependency of 3. prime attributes are on any proper subset of | non-prime attributes on any super key is candidate key is allowed allowed. a Stronger normal form than.1NF butlesser | Stronger normal form than 1NF and than 3NF 2NF. It virtually eliminates all the 5. _ | Iteliminates repeating groups in relation. Bailinda bes: a The goal of the second normal form is to The goal of the third normal form is to * | eliminate redundant data. ensure referential integrity. Distributed Database > Distributed VS Centralized Database Centralized Database Multiple database files are stored at various locations. It is made up ofa single database file. Multiple people can access and change data at the same time. Bottlenecks occur when numerous users access the same file at the same time. Files are sent swiftly from the user's closest location. It's possible that delivering files to consumers will take longer. Data can be recovered if one of the sites fails. In the event of a system breakdown, a single site equals downtime The synchronization of several files from various databases is required. Ina single, central system, it is easier to update and manage data. Copyright © belongs to the Arjun Chy AC 41. www.arjun00.com.np “Download from www.arjun00.com.np » Static SQL Vs Dynamic SQL Key Static SQL Dynamic SQL Database In Static SQL, database In Dynamic SQL, how a database Access access procedure is will be accessed, can be predetermined in the determine only at run time. statement. Efficiency | Static SQL statements are Dynamic SQL statements are more faster and efficient. less efficient. Compilation | Static SQL statements are Dynamic SQL statements are compiled at compile time. compiled at run time. Application | Application Plan parsing, Application Plan parsing, Plan validation, optimization and validation, optimization and generation are compile time | generation are run time activities. activities. Use Cases | Static SQL is used in case of | Dynamic SQL is used in case of uniformly distributed data. non-uniformly distributed data. Dynamic Statements like EXECUTE Statements like EXECUTE Statements IMMEDIATE, EXECUTE, IMMEDIATE, EXECUTE, PREPARE are not used. PREPARE are used Flexibility Static SQL is less flexible. Dynamic SQL is highly flexible. Copyright © belongs to the Arjun Chy AC 42. www.arjund0.com.np “Download from www.arjun00.com.np S.NO| Two-Tier Database Architecture Three-Tier Database Architecture 1 It is a Client-Server Architecture. It is a Web-based application. In two-tier, the application logic is In three-tier, the application logic or 2 either buried inside the user interface process resides in the middle-tier, it is on the client or within the database on separated from the data and the user the server (or both). interface. Two-tier architecture consists of two Three-tier architecture consists of three 3 layers : Client Tier and Database layers : Client Layer, Business Layer and (Data Tier) Data Layer 4 It is easy to build and maintain. It is complex to build and maintain. 5 Two-tier architecture runs slower. Three-tier architecture runs faster. 6 It is less secured as client can It is secured as client is not allowed to communicate with database directly. communicate with database directly. i It results in performance loss whenever the 7 Sitrsrvee ie neers oeee cee system is run on Internet but gives more idly. performance than two-tier architecture. Example — Contact Management Example — Designing registration form 8 System created using MS-Access or | which contains text box, label, button or a Railway Reservation System, etc. large website on the Internet, etc. Copyright © belongs to the Arjun Chy AC 43° www.arjun00.com.np **Download from www.arjun00.com.np ‘A database is a collection of information in tables. ‘Sometimes relations between them. A database management system is a collection of programs that helps you to use the database. ‘The database itself cannot back itself up. ‘A database cannot handle multiple users at the same time. (DBMS backups the database ensuring the integrity of he data even after a system failure ‘A DBMS can handle and is designed for multiple queries at a time. [A very big amount of information can be modified at a itime. {A lot of information can be modified because of multi- luser support. lexample: dictionary, Telephone Directory, Mark Ledger ete ‘example: MySQL, PostgreSQL, Microsoft SQL Server, Oracle Database, and Microsoft Access. > Relational Database Management System VS Database Management System Data stored is in table format Data stored is in the file format Multiple data elements are accessible together Individual access of data elements Data in the form of a table are linked together No connection between data Normalisation is not achievable There is normalisation Support distributed database No support for distributed database Data is stored in a large amount Data stored is a small quantity Here, redundancy of data is reduced with the help of key and indexes in RDBMS. Data redundancy is common RDBMS supports multiple users DBMS supports a single user It features multiple layers of security while handling data There is only low security while handling data The software and hardware requirements are higher ‘The software and hardware requirements are low Oracle, SQL Server. XML, Microsoft Access, Copyright © belongs to the Arjun Chy AC 44. www.arjun00.com.np “Download from www.arjun00.com.np Client can access only one server at a time. User can access many sites simultaneously. It is difficult to manage. Itis easy to manage. In this data is distributed across clients. In this data is distributed across sites. Speed of accessing database is poor as compared to Distributed DBMS. If somehow server crashes, the whole system stops. Speed of accessing database is much better than Client/Server Architecture. The crash of one site does not stop the entire system. Accessing of data is easy to control Accessing of data is difficult to control Itis less expensive as compared to Distributed DBMS. TREES. 8, Maintenance cost is low. Maintenance cost is high. >» DML stands for Data Manipulation Language. Tables and formulas are helpful when communicating with data stored up to a point in a database through SQL (Structured Query Language), but a time comes when we actually want to execute some fairly complicated data interactions. We will also need the Data Manipulation Language in that situation. DMLis a way to inform a database precisely what we want it to do by conversing in a manner that it has been built to comprehend from scratch. When it comes to interacting with existing data, whether adding, moving, or deleting data, it provides a convenient way to do so. Copyright © belongs to the Arjun Chy AC 45. www.arjun00.com.np “Download from www.arjun00.com.np “Database Schema :- = A database schema is a logical representation of data that shows how the data in a database should be stored logically. It shows how the data is organized and the relationship between the tables. = Database schema contains table, field, views and relation between different keys like primary key, foreign key. = Data are stored in the form of files which is unstructured in nature which makes accessing the data difficult. Thus to resolve the issue the data are organized in structured way with the help of database schema. = Database schema provides the organization of data and the relationship between the stored data. = Database schema defines a set of guidelines that control the database along with that it provides information about the way of accessing and modifying the data. > There are 3 types of database schema:- “+ Physical Database Schema: = A Physical schema defines, how the data or information is stored physically in the storage systems in the form of files & indices. This is the actual code or syntax needed to create the structure of a database, we can say that when we design a database at a physical level, it’s called physical schema. = The Database administrator chooses where and how to store the data in the different blocks of storage. Copyright © belongs to the Arjun Chy AC 46. wwwarjund0.com.np “Download from www.arjun00.com.np “Logical Database Schema: = A logical database schema defines all the logical constraints that need to be applied to the stored data, and also describes tables, views, entity relationships, and integrity constraints. = The Logical schema describes how the data is stored in the form of tables & how the attributes of a table are connected. = Using ER modelling the relationship between the components of the data is maintained. = In logical schema different integrity constraints are defined in order to maintain the quality of insertion and update the data. “View Database Schema: = It is a view level design which is able to define the interaction between end-user and database. = User is able to interact with the database with the help of the interface without knowing much about the stored mechanism of data in database. > Backups are necessary to safeguard data against loss, corruption, disasters, or accidental deletion. They provide a means to restore critical information and maintain business continuity in the face of data emergencies, hardware failures, or cyber-attacks. Copyright © belongs to the Arjun Chy AC 47 wwwarjun00.com.np “Download from www.arjun00.com.np > DBMS applications must be capable of solving challenging problems of different organizations. some objectives of DBMS are given below :- = Provide for mass storage of relevant data = Making easy access to data for the authorized user. = Providing prompt response to users’ requests for data. = Eliminate redundantly (Duplicate) d data. = Allow multiple users to be active at one time. = Allow the growth of the database system = Provide data integrity. = Protect the data from physical harm and unauthorized access. = Serving different types of users. the = Provide security with a user access privilege. = Combining interrelated data to generate a report = Provide multiple views for the same data. » Query optimization is used to access and modify the database in the most efficient way possible. It is the art of obtaining necessary information in a predictable, reliable, and timely manner. Query optimization is formally described as the process of transforming a query into an equivalent form that may be evaluated more efficiently. The goal of query optimization is to find an execution plan that reduces the time required to process a query. We must complete two major tasks to attain this optimization target. The first is to determine the optimal plan to access the database, and the second is to reduce the time required to execute the query plan. Copyright © belongs to the Arjun Chy AC 48. wwwarjun00.com.np “Download from www.arjun00.com.np = A buffer manager in DBMS is in charge of allocating buffer space in the main memory so that the temporary data can be stored there. = The buffer manager sends the block address if a user requests certain data and the data block is present in the database buffer in the main memory. It is also responsible for allocating the data blocks in the database buffer if the data blocks are not found in the database buffer. = In the absence of accessible empty space in the buffer, it removes a few older blocks from the database buffer to make space for the new data blocks. If the data blocks to be removed have been recently updated then the changes are copied/written to the disk storage, else they are simply removed from the database buffer. = Ifa user requests one of these removed data, the buffer manager copies/reads the data blocks present in the disk storage to the database buffer and returns the requested block's address from the main memory. Programs that might interfere with requests from the disks and the database buffer can't see what the buffer manager is doing inside as it acts as a VM in the system. Copyright © belongs to the Arjun Chy AC 49 wwwarjun00.com.np “Download from www.arjun00.com.np > Serializability in DBMS is a concept that helps to identify which non- serial schedules are correct and will maintain the consistency of the database. A serializable schedule always leaves the database in a consistent state. A serial schedule is always a serializable schedule because, in a serial Schedule, a transaction only starts when the other transaction has finished execution. A non-serial schedule of n transactions is said to be a serializable schedule, if it is equivalent to the serial Schedule of those n transactions. A serial schedule does not allow concurrency; only one transaction executes at a time, and the other starts when the already running transaction is finished. > Types of Serializability:- Conflict Serializability and View Serializability. > Transactions are a set of instructions that perform operations on databases. When multiple transactions are running concurrently, then a sequence is needed in which the operations are to be performed because at a time, only one operation can be performed on the database. This sequence of operations is known as Schedule, and this Process is known as Scheduling. When multiple transactions execute simultaneously in an unmanageable manner, then it might lead to several problems, which are known as concurrency problems. In order to overcome these problems, scheduling is required. Copyright © belongs to the Arjun Chy AC 50. wwwarjund0.com.np

You might also like