D B M S Animate


Published on

Published in: Technology
  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

D B M S Animate

  1. 2. Data <ul><li>Data - raw facts/details </li></ul><ul><li>Entity: a thing of significance about which information needs to be known. </li></ul><ul><li>Attributes :The characteristics that describe or qualify an entity are called its attributes </li></ul>
  2. 3. Data Continued: <ul><li>In case of a student , the basic entity is the student. </li></ul><ul><li>Entity attributes (information recorded about that entity) may include: </li></ul><ul><li>First and last name </li></ul><ul><li>Home address </li></ul><ul><li>Current address </li></ul><ul><li>Date of birth </li></ul><ul><li>Course opted </li></ul><ul><li>Grade point average etc… </li></ul>
  3. 4. Data Continued: <ul><li>Field: A field consists of a group of characters. </li></ul><ul><li>Record : All the details related to an entity is combined to form a record. </li></ul><ul><li>File : A collection of related records </li></ul><ul><li>Example: For a student, Admission file, Fee detail file, exam detail file etc… </li></ul><ul><li>Database: Collection of logically related records & files. </li></ul>
  4. 5. Traditional Approach <ul><li>Applications developed in an ad-hoc and opportunistic manner </li></ul><ul><li>Data files developed for individual applications </li></ul>
  5. 6. Files Dedicated to Application Programs
  6. 7. Database <ul><li>What is a database? </li></ul><ul><li>A database is an organized collection of related files and records designed to meet the needs of an organization. </li></ul>
  7. 8. Database System Components <ul><li>Data </li></ul><ul><li>Hardware </li></ul><ul><li>Software </li></ul><ul><li>Users </li></ul>
  8. 9. Interacting with a Database Application
  9. 10. Data Sharing in a Database Environment
  10. 11. DBMS <ul><li>The Database Management System (DBMS) software that enables users to define, create and maintain the database and provides flexible management of the data. </li></ul>
  11. 12. Why We Need DBMS <ul><li>There is an information explosion in today’s society </li></ul><ul><li>Need to have right information at the right time to make accurate decisions </li></ul>
  12. 13. Using DBMS <ul><li>Centralization of information management </li></ul><ul><li>Data shared by different groups of users and application programs </li></ul><ul><li>Provision of multiple interfaces </li></ul><ul><li>Advanced facilities for backup and recovery </li></ul>
  13. 14. DBMS Advantages <ul><li>Controlled redundancy </li></ul><ul><li>Data Consistency/Integrity </li></ul><ul><li>Sharing of data </li></ul><ul><li>Enforcement of security </li></ul><ul><li>Enforcement of development and maintenance standards </li></ul><ul><li>Data independence </li></ul>
  14. 15. DBMS Disadvantages <ul><li>Centralized Database </li></ul><ul><li>More Disk Space </li></ul><ul><li>Operationality of the system </li></ul><ul><li>Security Risk </li></ul>
  15. 16. DBMS-Users <ul><li>There are a number of users who can access or retrieve data on demand using the applications and interfaces provided by the DBMS. </li></ul><ul><li>Each type of user needs different software capabilities: </li></ul><ul><li>DDL-The application programmers interact with the database by accessing the data from programs written in high-level languages </li></ul><ul><li>DML– The end users are the people who sit at workstations and interact directly with the system. </li></ul><ul><li>DCL– The database administrator (DBA) is the person or group in charge of implementing the database system within the organization. </li></ul>
  16. 17. The Entity Relationship Model <ul><li>The ER model is a graphic representation to concisely present the data requirements of an application in a way that is easy to understand </li></ul><ul><li>Today ER model is a standard for the design methodologies of software systems </li></ul>
  17. 18. Data Models <ul><li>Models generally allow people to conceptualize </li></ul><ul><li>an abstract idea more easily </li></ul><ul><li>Model airplanes </li></ul><ul><li>Model homes </li></ul><ul><li>A data model is a way of explaining the logical </li></ul><ul><li>layout of the data and the relationship of various parts to each other and the whole. </li></ul>
  18. 19. Data Models <ul><li>Hierarchical Model </li></ul>
  19. 20. Data Models <ul><li>Network Model </li></ul>
  20. 21. Data Models <ul><li>Relational Model </li></ul>
  21. 22. Data Models <ul><li>The Relational Database Model: </li></ul><ul><ul><li>Relational database model, where all data are kept in tables or relations. </li></ul></ul><ul><ul><li>More flexible & easy to use. </li></ul></ul><ul><ul><li>Almost any item of data can be accessed more quickly than the other models. </li></ul></ul><ul><ul><li>Retrieval time is reduced so that interactive access becomes more feasible. </li></ul></ul><ul><ul><li>This is what is referred to as Relational Database Management System(RDBMS) </li></ul></ul>
  22. 23. Relational DBMS <ul><li>Edgar F. Codd at IBM invented the relational database in 1970. Called Father of RDBMS. </li></ul><ul><li>RDBMS allows operations in a human logical environment. </li></ul><ul><li>The main elements of RDBMS are based on Codd’s 13 rules for a relational system. </li></ul><ul><li>The relational database is perceived as a collection of tables. </li></ul><ul><li>Each table consists of a series of row/column intersections. </li></ul><ul><li>Tables (or relations) are related to each other by sharing common characteristics </li></ul>
  23. 24. H How do I design a database? <ul><li>„ Logical design </li></ul><ul><li>™ Determine and define fields, tables, keys, and </li></ul><ul><li>data integrity </li></ul><ul><li>„ Physical implementation </li></ul><ul><li>™ Creating tables, establishing key fields, and </li></ul><ul><li>table relationships </li></ul><ul><li>„ Application development </li></ul><ul><li>™ Determine end-user tasks </li></ul>
  24. 25. Data Abstraction <ul><li>The major purpose of a database system is to provide users with an abstract view of the system. The system hides certain details of how data is stored and created and maintained </li></ul><ul><li>Complexity should be hidden from database users. </li></ul><ul><li>1.Physical level :- The lowest level of abstraction that describes how the data is actually stored. </li></ul>
  25. 26. Data Abstraction <ul><li>2.Logical Level :-The next level of abstraction that describes the relationships among data. </li></ul><ul><li>3.View level :- Highest level of abstraction that describes part of the database for a particular group of users </li></ul><ul><ul><ul><li>Can be many different views of a database. </li></ul></ul></ul>
  26. 27. Data Abstraction
  27. 28. Instances & Schemas <ul><li>Instance :- The information that is currently being stored in the database is called an instance of the database </li></ul><ul><li>Schema :- Overall design of the database is called schema. </li></ul><ul><li>At the lowest level is the physical schema, followed by Logical schema & the highest level is the subschema. </li></ul><ul><li>Database Systems will support only one Physical & Logical Schema but can have several subschemas. </li></ul>
  28. 29. RDBMS <ul><li>A database management system that stores data in the form of related tables is called Relational Database Management System. </li></ul><ul><li>The goal of RDBMS is to make data easy to store & retrieve </li></ul><ul><li>Relational databases help solve problems as they are designed to create tables & then combine the information in interesting ways to create valid information. </li></ul>
  29. 30. RDBMS <ul><li>Typical RDBMS include </li></ul><ul><li>Microsoft Access </li></ul><ul><li>Microsoft SQL Server </li></ul><ul><li>Sybase (The forerunner of Microsoft SQL Server) </li></ul><ul><li>IBM DB2 </li></ul><ul><li>Oracle </li></ul><ul><li>Ingres </li></ul><ul><li>MySQL </li></ul><ul><li>Postgresql etc </li></ul>
  30. 31. RDBMS <ul><li>Constraints are conditions that must hold on all valid relation instances. There are different types of constraints: </li></ul><ul><li>Entity integrity constraints, and referential integrity constraints </li></ul><ul><li>A candidate key is one that can identify each row of a table uniquely. </li></ul><ul><li>Generally a candidate key becomes the primary key of the table. </li></ul>
  31. 32. RDBMS <ul><li>If the table has more than one candidate key, one of them will become the primary key, and the rest are called alternate keys. </li></ul><ul><li>A key formed by combining at least two or more columns is called composite key. </li></ul>
  32. 33. Integrity Rules <ul><li>Entity integrity rule states that Primary attribute in the table should be unique & not null </li></ul><ul><li>Referential integrity rule states that a given non-null foreign key value must have a matching primary key value somewhere in the referenced relation </li></ul><ul><li>Cascading deletions through related tables & preventing deletion when related records exist are the methods used to enforce referential integrity </li></ul>
  33. 34. Integrity Rules <ul><li>Domain Integrity rule ensures that the value of the columns of a relation are legal according to the domain definitions. </li></ul><ul><li>Domain definitions can be physical & Logical. </li></ul>
  34. 35. Normalization <ul><li>Normalization is the the process of reducing duplication in a database, with the ultimate goal of eliminating duplicate data entirely. A basic goal of normalization is to create a set of relational tables that are free of redundant data and the data should be consistent. </li></ul><ul><li>Duplication takes more disk space, the bigger issue is consistency. Duplication creates the risk of data corruption when information is inserted, updated, or deleted, by having a particular piece of information in more than one place. </li></ul>
  35. 36. Relations that have redundant data may have problems called update anomalies , which are classified as , Insertion anomalies Deletion anomalies Modification anomalies
  36. 37. Unnormalized form (UNF) A table that contains one or more repeating groups. Figure 3 ClientRental unnormalized table Repeating group = (propertyNo, pAddress, rentStart, rentFinish, rent, ownerNo, oName) ClientNo cName propertyNo pAddress rentStart rentFinish rent ownerNo oName CR76 John kay PG4 PG16 6 lawrence St,Glasgow 5 Novar Dr, Glasgow 1-Jul-00 1-Sep-02 31-Aug-01 1-Sep-02 350 450 CO40 CO93 Tina Murphy Tony Shaw CR56 Aline Stewart PG4 PG36 PG16 6 lawrence St,Glasgow 2 Manor Rd, Glasgow 5 Novar Dr, Glasgow 1-Sep-99 10-Oct-00 1-Nov-02 10-Jun-00 1-Dec-01 1-Aug-03 350 370 450 CO40 CO93 CO93 Tina Murphy Tony Shaw Tony Shaw
  37. 38. First Normal Form (1NF) <ul><li>First Normal Form is a relation in which the intersection of each row and column contains one and only one value. </li></ul><ul><li>There are two approaches to removing repeating groups from unnormalized tables: </li></ul><ul><ul><li>Removes the repeating groups by entering appropriate data in the empty columns of rows containing the repeating data. </li></ul></ul><ul><ul><li>2. Removes the repeating group by placing the repeating data, along with a copy of the original key attribute(s), in a separate relation. A primary key is identified for the new relation. </li></ul></ul>
  38. 39. Client ( clientNo , cName) PropertyRentalOwner ( clientNo , propertyNo , pAddress, rentStart, rentFinish, rent, ownerNo, oName) ClientNo cName CR76 John Kay CR56 Aline Stewart ClientNo propertyNo pAddress rentStart rentFinish rent ownerNo oName CR76 PG4 6 lawrence St,Glasgow 1-Jul-00 31-Aug-01 350 CO40 Tina Murphy CR76 PG16 5 Novar Dr, Glasgow 1-Sep-02 1-Sep-02 450 CO93 Tony Shaw CR56 PG4 6 lawrence St,Glasgow 1-Sep-99 10-Jun-00 350 CO40 Tina Murphy CR56 PG36 2 Manor Rd, Glasgow 10-Oct-00 1-Dec-01 370 CO93 Tony Shaw CR56 PG16 5 Novar Dr, Glasgow 1-Nov-02 1-Aug-03 450 CO93 Tony Shaw
  39. 40. Second Normal Form (2NF ) <ul><li>Second normal form (2NF) is a relation that is in first normal form and every non-primary-key attribute is fully functionally dependent on the primary key. </li></ul><ul><li>The normalization of 1NF relations to 2NF involves the removal of partial dependencies . If a partial dependency exists, we remove the function dependent attributes from the relation by placing them in a new relation along with a copy of their determinant. </li></ul>
  40. 41. Second Normal Form (2NF) <ul><li>After removing the partial dependencies, the creation of the three new relations called Client, Rental, and PropertyOwner </li></ul>Client Rental PropertyOwner ClientNo cName CR76 John Kay CR56 Aline Stewart ClientNo propertyNo rentStart rentFinish CR76 PG4 1-Jul-00 31-Aug-01 CR76 PG16 1-Sep-02 1-Sep-02 CR56 PG4 1-Sep-99 10-Jun-00 CR56 PG36 10-Oct-00 1-Dec-01 CR56 PG16 1-Nov-02 1-Aug-03 propertyNo pAddress rent ownerNo oName PG4 6 lawrence St,Glasgow 350 CO40 Tina Murphy PG16 5 Novar Dr, Glasgow 450 CO93 Tony Shaw PG36 2 Manor Rd, Glasgow 370 CO93 Tony Shaw
  41. 42. Third Normal Form <ul><li>Transitive dependency </li></ul><ul><li>A condition where A, B, and C are attributes of a relation such that </li></ul><ul><li>if A  B and B  C, then C is transitively dependent on A via B (provided that A is not functionally dependent on B or C). </li></ul>
  42. 43. The resulting 3NF relations have the forms: Client ( clientNo , cName) Rental ( clientNo , propertyNo , rentStart, rentFinish) PropertyOwner ( propertyNo , pAddress, rent, ownerNo) Owner ( ownerNo , oName)
  43. 44. Client Rental PropertyOwner Owner ClientNo cName CR76 John Kay CR56 Aline Stewart ClientNo propertyNo rentStart rentFinish CR76 PG4 1-Jul-00 31-Aug-01 CR76 PG16 1-Sep-02 1-Sep-02 CR56 PG4 1-Sep-99 10-Jun-00 CR56 PG36 10-Oct-00 1-Dec-01 CR56 PG16 1-Nov-02 1-Aug-03 propertyNo pAddress rent ownerNo PG4 6 lawrence St,Glasgow 350 CO40 PG16 5 Novar Dr, Glasgow 450 CO93 PG36 2 Manor Rd, Glasgow 370 CO93 ownerNo oName CO40 Tina Murphy CO93 Tony Shaw
  44. 46. INTRODUCTION <ul><li>SQL (Structured Query Language) is a computer language aimed to store, manipulate, and retrieve data stored in relational databases. </li></ul><ul><li>The first incarnation of SQL appeared in 1974, when a group in IBM developed the first prototype of a relational database. </li></ul><ul><li>The first commercial relational database was released by Relational Software later becoming Oracle. </li></ul>
  45. 47. DDL <ul><li>DDL - Data Definition Language: </li></ul><ul><li>Statements used to define the database structure or schema. Some examples: </li></ul><ul><li>CREATE - to create objects in the database </li></ul><ul><li>ALTER - alters the structure of the database </li></ul><ul><li>DROP - delete objects from the database </li></ul><ul><li>RENAME - rename an object </li></ul>
  46. 48. Data Manipulation Language <ul><li>DML- Data Manipulation Language: </li></ul><ul><li>Statements used for managing data within schema objects. </li></ul><ul><li>SELECT - retrieve data from the a database </li></ul><ul><li>INSERT - insert data into a table </li></ul><ul><li>UPDATE - updates existing data within a table </li></ul><ul><li>DELETE - deletes all records from a table, the space for the records remain </li></ul><ul><li>CALL - call a PL/SQL or Java subprogram </li></ul>
  47. 49. CREATE TABLE <ul><li>The SQL syntax for CREATE TABLE is </li></ul><ul><li>CREATE TABLE &quot;table_name&quot; (&quot;column &quot;data_type_for_column_1&quot;, &quot;column &quot;data_type_for_column_2&quot;, ... ); </li></ul>
  48. 50. CREATE TABLE <ul><li>So, if we are to create the customer table specified as above, we would type in </li></ul><ul><li>CREATE TABLE customer (First_Name char(50), Last_Name char(50), Address char(50), City char(50), Country char(25), Birth_Date date) ; </li></ul>
  49. 51. <ul><li>CREATE TABLE customer (Cust_ID int Primary key, </li></ul><ul><li>First_Name char(50), Last_Name char(50), Address char(50), City char(50), Country char(25), Birth_Date date); </li></ul>
  50. 52. ALTER TABLE <ul><li>Using the &quot;customer&quot; table created in the CREATE TABLE section: </li></ul><ul><li>If we want to add a column called &quot;Gender&quot; to this table. To do this, we key in: </li></ul><ul><li>ALTER table customer add Gender char(1) ; </li></ul>
  51. 53. DROP TABLE <ul><li>Sometimes we may decide that we need to get rid of a table in the database for some reason. </li></ul><ul><li>The syntax for DROP TABLE is </li></ul><ul><li>DROP TABLE &quot;table_name&quot; </li></ul><ul><li>So, if we wanted to drop the table called customer that we created in the CREATE TABLE section, we simply type </li></ul><ul><li>DROP TABLE customer . </li></ul>
  52. 54. TRUNCATE TABLE <ul><li>Sometimes we wish to get rid of all the data in a table. One way of doing this is with DROP TABLE . But here we get rid of the data but not the table itself ? For this, we can use the TRUNCATE TABLE command. </li></ul><ul><li>The syntax for TRUNCATE TABLE is </li></ul><ul><li>TRUNCATE TABLE &quot;table_name&quot; </li></ul><ul><li>So, if we wanted to truncate the table called customer that we created ,we simply type, </li></ul><ul><li>TRUNCATE TABLE customer </li></ul>
  53. 55. RENAME TABLE <ul><li>If we want the change the name of the table we have created ,use the rename command </li></ul><ul><li>The syntax for RENAME TABLE is </li></ul><ul><li>RENAME TABLE customer TO new table name </li></ul><ul><li>So if we want to change the name to persons ,type in </li></ul><ul><li>RENAME TABLE customer TO Person </li></ul>
  54. 56. Data manipulation language are used for managing data within schema objects
  55. 57. INSERT <ul><li>INSERT INTO table_name VALUES (value1, value2, value3,...) </li></ul><ul><li>The second form specifies both the column names and the values to be inserted: </li></ul><ul><li>INSERT INTO table_name (column1, column2, column3,...) VALUES (value1, value2, value3,...) </li></ul>
  56. 58. UPDATE <ul><li>The UPDATE statement is used to update existing records in a table. </li></ul><ul><li>SQL UPDATE Syntax </li></ul><ul><li>UPDATE table_name SET column1=value, column2=value2,... WHERE some_column=some_value </li></ul>
  57. 59. DML Commands <ul><li>SELECT: retrieve data from the database </li></ul><ul><li>INSERT : insert data into the table </li></ul><ul><li>UPDATE : updates existing data within a table </li></ul><ul><li>DELETE: delete all records from a table ;only the space for the records remain </li></ul><ul><li>CALL: call a PL/SQL OR Java subprogram </li></ul>
  58. 60. DELETE <ul><li>The DELETE statement is used to delete rows in a table. </li></ul><ul><li>SQL DELETE Syntax </li></ul><ul><li>DELETE FROM table_name WHERE some_column=some_value </li></ul>
  59. 61. SELECT <ul><li>To illustrate this , assume that we have the following table: </li></ul><ul><li>Table : Store Information </li></ul>
  60. 62. SELECT <ul><li>To select all the stores in this table, we key in, </li></ul><ul><li>SELECT store_name FROM Store_Information </li></ul><ul><li>Result: </li></ul><ul><ul><li>store_name </li></ul></ul><ul><ul><li>Los Angeles </li></ul></ul><ul><ul><li>San Diego </li></ul></ul><ul><ul><li>Los Angeles </li></ul></ul><ul><ul><li>Boston </li></ul></ul>
  61. 63. SELECT DISTINCT <ul><li>If we only want to select each distinct element? We have to do, is to add DISTINCT after SELECT . The syntax is as follows : </li></ul><ul><li>SELECT DISTINCT &quot;column_name&quot;FROM &quot;table_name &quot; </li></ul><ul><li>For example, to select all distinct stores in Table Store_Information , we key in, </li></ul><ul><li>SELECT DISTINCT store_name FROM Store_Information </li></ul><ul><li>Result: </li></ul><ul><ul><ul><li>store_name </li></ul></ul></ul><ul><ul><ul><li>Los Angeles </li></ul></ul></ul><ul><ul><ul><li>San Diego </li></ul></ul></ul><ul><ul><ul><li>Boston </li></ul></ul></ul>
  62. 64. WHERE <ul><li>Next, we might want to conditionally select the data from a table.. To do this, we use the WHERE keyword. The syntax is as follows: </li></ul><ul><ul><li>SELECT &quot;column_name“ FROM &quot;table_name“ WHERE &quot;condition “ </li></ul></ul><ul><li>For example, we may want to only retrieve stores with sales above $1,000 </li></ul><ul><li>we key in, </li></ul><ul><li>SELECT store_name FROM Store_Information WHERE Sales > 1000 Result: </li></ul><ul><li>store_name </li></ul><ul><li>Los Angeles </li></ul>
  63. 66. ORDER BY <ul><li>We want to list the output in a particular order. This could be in ascending order, in descending order, or could be based on either numerical value or text value. In such cases, we can use the ORDER BY keyword. </li></ul><ul><ul><li>The syntax for an ORDER BY statement is as follows: </li></ul></ul><ul><ul><li>SELECT &quot;column_name“ FROM &quot;table_name&quot; [WHERE &quot;condition&quot;] ORDER BY &quot;column_name&quot; [ASC, DESC] </li></ul></ul>
  64. 67. ORDER BY <ul><li>we may wish to list the contents of Table Store_Information by dollar amount, in descending order: </li></ul><ul><li>we key in, </li></ul><ul><ul><li>SELECT store_name, Sales, Date FROM Store_Information ORDER BY Sales DESC Result: </li></ul></ul><ul><ul><li>   </li></ul></ul>
  65. 68. INDEX <ul><li>With the proper index in place, the database system can first go through the index to find out where to retrieve the data, and then go to these locations directly to get the needed data. </li></ul><ul><li>The general syntax for creating an index is: </li></ul><ul><ul><li>CREATE INDEX &quot;INDEX_NAME&quot; ON &quot;TABLE_NAME&quot; (COLUMN_NAME) </li></ul></ul><ul><li>If we want to create an index on the column Last_Name, we would type in, </li></ul><ul><ul><li>CREATE INDEX IDX_CUSTOMER_LAST_NAME on CUSTOMER (Last_Name) </li></ul></ul><ul><li>If we want to create an index on both City and Country, we would type in, </li></ul><ul><ul><li>CREATE INDEX IDX_CUSTOMER_LOCATION on CUSTOMER (City, Country ) </li></ul></ul>
  66. 69. Primary key <ul><li>Primary keys can be specified either when the table is created using CREATE TABLE or by changing the existing table structure using ALTER TABLE </li></ul>Specifying a primary key when creating a table: CREATE TABLE Customer (SID integer, Last_Name varchar(30), First_Name varchar(30), PRIMARY KEY (SID));
  67. 70. Contd… <ul><li>For specifying a primary key by altering a table: </li></ul><ul><li>ALTER TABLE Customer ADD PRIMARY KEY (SID); </li></ul>
  68. 71. ALIASE <ul><li>There are two types of aliases that are used most frequently: column alias and table alias. </li></ul><ul><li>The syntax for both the column and table aliases: </li></ul><ul><ul><li>SELECT &quot;table_alias&quot;.&quot;column_name1&quot; &quot;column_alias“ </li></ul></ul><ul><li>FROM &quot;table_name&quot; &quot;table_alias&quot; </li></ul><ul><li>Using the same example </li></ul><ul><li>SELECT A1.store_name Store, SUM(A1.Sales) &quot;Total Sales&quot; FROM Store_Information A1 GROUP BY A1.store_name </li></ul><ul><li>Result: </li></ul><ul><li>Store   Total Sales </li></ul><ul><li>Los Angeles  $1800 </li></ul><ul><li>San Diego  $250 </li></ul><ul><li>Boston  $700 </li></ul>
  69. 72. JOIN <ul><li>If we want to find out sales by region. We see that table Geography includes information on regions and stores, and table Store_Information contains sales information for each store. To get the sales information by region, we have to combine the information from the two tables. </li></ul><ul><li>SELECT A1.region_name REGION, SUM(A2.Sales) SALES FROM Geography A1, Store_Information A2 WHERE A1.store_name = A2.store_name GROUP BY A1.region_name </li></ul>
  70. 73. JOIN <ul><li>Result: </li></ul><ul><li>REGION   SALES </li></ul><ul><li>East  $70 </li></ul><ul><li>West  $2050 </li></ul>
  71. 74. JOIN <ul><li>Result: </li></ul><ul><li>REGION   SALES </li></ul><ul><li>East  $70 </li></ul><ul><li>West  $2050 </li></ul>
  72. 75. <ul><li>Thank You </li></ul>