WEEK 1 Day 1 Day 2 Day 3

Size: px
Start display at page:

Download "WEEK 1 Day 1 Day 2 Day 3"

Transcription

1 Introduction to RDBMS & SQL Course Map WEEK 1 Day 1 Day 2 Day 3 9:00-9:15 Morning Review Morning Review 9:15-9:30 M1: Introduction 1.1 School Opening (1:00) 9:30-9:45 9:45-10:00 10:00-10:15 10:15-10:30 10:30-10:45 10:45-11:00 11:00-11:15 11:15-11:30 11:30-11:45 11:45-12:00 12:00-12:15 12:15-12:30 12:30-12:45 12:45-1:00 M2 : Introduction to RDBMS (1:00) M3 : The E-R Model of the Database ( 1:45) Activity (0:15) M6: Data Definition Language (1:00) Activity 3(0:45) M7 : Data Manipulation Language (2:00) M8: Constraints (0:15) Activity 5 (0:45) M9: Aggregate Functions, Joins and Sub queries (2:30) Activity (0:15) 1:00-2:00 LUNCH LUNCH LUNCH 2:00-2:15 2:15-2:30 Knowledge Check 1 & 2 2:30-2:45 2:45-3:00 3:00-3:15 3:15-3:30 M4 : Database Design Techniques (0:45) Activity 2 (0:15) M7 : Data Manipulation Language (continued) Activity 4 (2:30) M9: Aggregate Functions, Joins and Sub queries (continued) Activity (2:15) 3:30-3:45 3:45-4:00 M5: Introduction to SQL (1:00) 4:00-4:15 4:15-4:30 4:30-4:45 Knowledge Check 3 & 4 Knowledge Check 5 & 6 4:45-5:00 M10: Views (0:45) 5:00-5:15 5:15-5:30 Team Buliding Activity M8: Constraints (0:45) Knowledge Check 7, 8 & 9 5:30-5:45 5:45-6:00 Day 1 Summary Day 2 Summary Day 3 Summary CourseMap.doc

2 1_Course Overview.ppt Introduction to RDBMS and SQL Module 1: Course Overview. Accenture, its logo, and Accenture High Performance Delivered are trademarks of Accenture. Agenda Welcome Objectives Introductions Expectations of Participants Ground Rules Course Objectives Course Approach and Outline. 2 1

3 1_Course Overview.ppt Welcome Welcome to RDBMS Course The purpose of this 3 day Course is to provide programmers with the tools necessary to understand database and write SQL queries. This Course will cover the following topics: Introduction to RDBMS Introduction to SQL Introduction to execute records using different Queries Introduction to commonly used concepts in programming like DDL DML DCL etc.. 3 Objectives At the end of this presentation, you should be able to: Understand the expectations and ground rules Understand the training approach and evaluation process. Understand how to access the school resources, including: the online book, online support, team members and faculty.. 4 2

4 1_Course Overview.ppt Introductions Name Your self assessment based on: Why I m here. I am a programmer (using a different programming language). I am familiar with Programming concepts. I know how to program using C. I am a C Programmer and practice Best programming Techniques. One interesting note about yourself (e.g., a hobby or talent) Your expectations from the course. 5 Expectations of participants You will work as a team to complete the deliverables of the course. You should be resourceful and creative. Utilize the tools and materials that have been provided. Participate in discussions, ask questions to clarify if necessary.. 6 3

5 1_Course Overview.ppt Course Objectives Participants who have completed this school, will be able to: List the types of data used in a Oracle database and explain about E-R model of the Database. Describe database design techniques and its features List the advantages of working on a database in application development Describe the different types of SQL commands Explain Data Definition Language, Data Manipulation Language Describe the database constraints Describe Aggregate functions, joins and sub queries, Views. 7 Course Approach Learn by Doing Hands-on programming Activity-based Learning Activities are designed to be difficult but doable Activities have time limits to encourage wise use of your time Activities will force you to research on the required knowledge Resource-rich Environment Use available resources (i.e., online/offline materials, human resources, etc ) Encourage research and learning on your own. 8 4

6 1_Course Overview.ppt Course Approach (Cont.) Teaching Method This is not a lecture course! Lessons serve only as guideposts and reminders, and are not expected to be complete classes on these topics Instructors serve mainly as facilitators and knowledge coaches Performance Evaluation Each participant will be evaluated Participate i t Don t just listen to discussions, interact! If in doubt, ask questions to clarify. Spot problems and suggest alternatives or workarounds.. 9 Course Approach (Cont.) Teamwork Cooperate, coordinate, collaborate! Work together to complete the deliverables for the course. Be resourceful Don t ask for answers or solutions, find them! The course environment provides all the necessary tools and materials to learn, utilize them well

7 1_Course Overview.ppt Course Approach - Learn By Doing One of the tenets of the school is that the best way to learn is to take a more active, hands-on approach. The majority of the activities consist of participants working to complete the appropriate deliverables. The faculty will act as knowledge coaches and technical consultants. This course encourages participants to be resourceful and inquisitive.. 11 Course Approach - Tiers of Support Level 1 You Try to resolve the problem on your own. Read documentation, try sample codes, surf the web Level 2 Teammates Try to resolve the problem with your teammates. Consult entire team, investigate, work together to solve the problem. Level 3 Other Teams Try to resolve problem with other teams. Share tips, guides, resolutions, workarounds Level 4 Faculty Try to resolve problem with your faculty members

8 1_Course Overview.ppt Course Map Day 1 Day 2 Day 3 Course Introduction Module 1: School Opening Module 2: Introduction to RDBMS Module 3: Database Design Techniques M6: Data Definition Language M7:Constraints M9: Aggregate Functions, Joins and Subqueries Lunch Lunch Lunch Module 4:The E-R Model of the Database M7: Constraints (cont) M9: Aggregate Functions, Joins and Sub queries (cont) M8: Data Manipulation Language Module 5: Introduction to SQL Module 10: Views. 13 Ground Rules Observe proper professional behavior at all times. Core hours are from 9:00 a.m. to 6:00 p.m. Inform your supervisors when you will be late or absent. Set phones (or beepers) to silent/vibrate mode or turn them off. The Accenture Code of Ethics is enforced at all times. Observe proper use of Accenture resources and facilities. No unauthorized software (especially games) installed on workstations. Landline is strictly for business purposes or emergency calls only. Turn off your machines when you leave for the day. Downloading of non-training related materials is strictly prohibited

9 1_Course Overview.ppt Ground Rules (Cont.) No unauthorized software especially games should be installed in workstations Landline is strictly for business purposes or emergency calls only Observe proper dress code Proper use of Accenture resources and facilities (e.g. desktops, training room, pantry) Maintain confidentiality of company and client-related matters. 15 Training Resources Be aware there will be Knowledge Checks (quizzes) to test your understanding of the information presented. You may use the Internet, as long as you use it responsibly to access or research Programming technique related resources. We recommend self study. Get to know your fellow students and the resources they offer. Tell your fellow students about your strengths and the resources you bring

10 1_Course Overview.ppt Questions/ Comments What questions or comments do you have?. 17 9

11 2_IntroductionToRDBMS.ppt Introduction to RDBMS and SQL Module 2: Introduction to RDBMS. Accenture, its logo, and Accenture High Performance Delivered are trademarks of Accenture.Course Code #IDCGF002 Agenda Data and Storage. Drawbacks with File Systems. Introduction to DBMS and its benefits. Multi-tier Architecture Data Models Hierarchical Model. Network Model. Relational Data Model. Relational Data Model concepts. Codd s 12 rules. Accenture 2009 All Rights Reserved 2 10

12 2_IntroductionToRDBMS.ppt Learning Objectives Understand the purpose of storing data. Understand drawbacks of file systems. Understand the meaning of Database. Compare Databases with traditional methods. Understand the Multi-Tier Architecture. Understand Data Models. Understand Codd s Rules. Accenture 2009 All Rights Reserved 3 Data and its storage We require reliable data to work with and hence it becomes essential to store the data. We often have to store the data as it is crucial in business decisions. There are 2 ways to store data in computer: Traditional Approach (File Systems). Database Management Systems (DBMS). A File System is described by a very simple data storage model In this, all the information is stored in a plain text file, one record per line. Each record is divided into fields using delimiters or are delimited using fixed column positions. Accenture 2009 All Rights Reserved 4 11

13 2_IntroductionToRDBMS.ppt Drawbacks with File Systems Drawbacks Data Dependency Redundancy Sharing Security Transaction Control Description Data dependency means that the application program is dependant on the data. So any modifications made on the data affects the application program using it, forcing it to be rewritten. Redundancy is the repetition of data. Data duplication was allowed in the traditional approach. Data redundancy caused data inconsistency to occur in the data. Data Sharing was difficult or impossible with traditional systems. Data stored on the computer must be secured. It was difficult to enforce independent information security in traditional approach. Transaction is unit of work. If one is performing some work ( for e.g. inserting some records) other persons should not be able to use that particular data. There was no way to isolate independent units of work in traditional approach. Accenture 2009 All Rights Reserved 5 Introduction to DBMS DBMS is Data Base Management System. It is a program that lets one or more computer users create and access data in a database. It allows data definition, storage, and management of data in the centralized pool that can be shared by many users. Accenture 2009 All Rights Reserved 6 12

14 2_IntroductionToRDBMS.ppt Data Concurrency Databases allow multiple users to access the same database simultaneously. Data Redundancy A properly set-up database minimizes data redundancy. It will avoid data repetition in the databases. Data Validity Databases allow you to set up rules that ensure that data remains consistent when add or modify data. Data Sharing Sharing data is also much easier using a database. You can share data among a number of users on the same computer or among users on different computers linked via a network or the Internet. Databases also allow more than one person to access the database at the same time and change the data stored; the database management system handles simultaneous changes. Data Security One final advantage of databases is security. Most database management systems allow you to create users in order to indicate various levels of security. Before someone accesses the database, he or she must log on as a specific user. Each user has various rights and limits. Someone who maintains the database has full ability to edit data, modify the database s structure, add and delete users, and so on. Other users may only have the ability to view data but not change it, or you may even want to limit what data they can view. Many database management systems provide a granular level of security, that is, they are very specific as to what a user can do. 13

15 2_IntroductionToRDBMS.ppt This diagram shows how application programs interact with the DBMS. DBMS actually is a repository of data which provide information to the application programs as well as storing information from the application programs. This is a typical example of a client-server system, where different application programs will access the DBMS via network. All the applications will access only one database. The DBMS is physically stored as Files in the Hard Disk of the system. 14

16 2_IntroductionToRDBMS.ppt 15

17 2_IntroductionToRDBMS.ppt Two tier architecture Two tier architectures consist of three components distributed in two layers: client (requester of services) and server (provider of services). The three components are User System Interface (such as session, text input, dialog, and display management services) Processing Management (such as process development, process enactment, process monitoring, and process resource services) Database Management (such as data and file services) The two tier design allocates the user system interface exclusively to the client. It places database management on the server and splits the processing management between client and server, creating two layers. In general, the user system interface client invokes services from the database management server. In many two tier designs, most of the application portion of processing is in the client environment. The database management server usually provides the portion of the processing related to accessing data (often implemented in store procedures). Clients commonly communicate with the server through SQL statements or a call-level interface. It should be noted that connectivity between tiers can be dynamically changed depending upon the user's request for data and services. 16

18 2_IntroductionToRDBMS.ppt Hierarchical Model : This data model explicitly makes use of the hierarchies by providing a tree by which all data are accessible. The network model allows each record to have multiple parent and child records, forming a lattice structure. Relational Model : Each table represents some real-world person, place, thing, or event about which information is collected. A relational database is a collection of two-dimensional tables. The relational database is built around the Relational Model designed by E. F. Codd at IBM in We will explore Relational Model in detail in the coming slides. 17

19 2_IntroductionToRDBMS.ppt In practice, many database products (for e.g. Oracle, Sybase etc..) are considered 'relational' even if they do not strictly adhere to all 12 rules. 18

20 2_IntroductionToRDBMS.ppt Network Data Model Accenture 2009 All Rights Reserved 13 Relational Data Model It is based on Relational algebra i. e. mathematical theory of relations. It was first described by E.F. Codd in 1970 and then modified by IBM. It presents data in form of tables. Rules of Relational Data Model It defines tables which contains Rows and Columns. It presents a set of rules to ensure the integrity of the database. In Relational model a table is also a relation. Row is known as a tuple. Column is known as an attribute. Dr. Codd modified his model by defining 12 rules (Codd s Rules), that a DBMS must meet in order to be considered a relational database. Accenture 2009 All Rights Reserved 14 19

21 2_IntroductionToRDBMS.ppt Basic Terms and Definitions The term 'database' has many interpretations - one definition is that database is a 'collection of persistent data. A relational database is one in which the data consists of a 'collection of tables related to each other through common values. A relational database management system (RDBMS) uses matching values in multiple tables to relate the information in one table with the information in the other table. The presentation of data as tables is a logical construct - it is independent of the way the data is physically stored on disk. Accenture 2009 All Rights Reserved 15 Basic Terms and Definitions (Contd ) The two most prominent characteristics of a relational database are Data stored in tables. Relationships between tables. A table (entity or relation) is a collection of rows and columns. A row (record or tuple) represents a collection of information about a separate item (e.g., a customer). A column (field or attribute) represents ese the characteristics acte cs of an item (e.g., the customer's name or phone number). A relationship (join) is a logical link between two tables. Accenture 2009 All Rights Reserved 16 20

22 2_IntroductionToRDBMS.ppt Codd s 12 rules Rule No. Rule Description # 1 Information rule Database must consist of tables related to each other and data should be stored in the form of tables only. # 2 Guaranteed access Rule # 3 Systematic treatment of null values The data can be accessed by specifying the table name and the columns that define the primary key. Primary key ensures that each value is unique and accessible. A Null is an unknown value and every database must have a provision for storing NULL values. # 4 Dynamic on-line In addition to user data, a relational database contains data about itself, catalog based on the there are 2 types of tables. relational lmodel User tables - that contain the 'working' data and system tables contain data about the database structure. Metadata that describes the structure of the database itself and includes object definitions (tables, indexes, stored procedures, etc.) and how they relate to each other. The collection of system tables is also referred to as the system catalog or data dictionary. Accenture 2009 All Rights Reserved 17 Codd s 12 rules (Contd ) Rule No. Rule Description # 5 Comprehensive Data Sublanguage Rule There must be a single language that handles all communication with the database management system. The language must support relational operations with respect to: data modification, data definition and administration. # 6 View Updating Rule Database must allow for presenting data to the user in different combinations through views. Views are nothing but virtual tables which contains extraction of data from the source tables. Views allows to create customized snapshot of data to suit specific needs. If a view is a simple view then it can provide update and delete operations on views. Accenture 2009 All Rights Reserved 18 21

23 2_IntroductionToRDBMS.ppt Codd s 12 rules (Contd ) Rule No. Rule Description #7 High-level l insert, Rows are treated t as sets for data manipulation operations. update and delete A relational database should support basic operations like subqueries, join, operators and set operations like union, intersection and minus. Set operations and relational operators are used to operate on 'relations' (tables) to produce other relations (tables). # 8 Physical Data Independence Any changes in the data storage should not affect the application that accesses it. # 9 Logical Data Independence # 10 Integrity Independence Data is logically stored in tables and physically in files. For any change in the structure of tables and relationships, the application need not be re-created. In order to be considered relational, data integrity must be an internal function of the DBMS; not the application program. Data integrity means the consistency and accuracy of the data in the database (i.e., keeping the garbage out of the database). Accenture 2009 All Rights Reserved 19 22

24 2_IntroductionToRDBMS.ppt 0. Foundation Rule Interestingly Codd defined a Rule 0 for relational database systems. "For any system that is advertised as, or claimed to be, a relational database management system, that system must be able to manage databases entirely through its relational capabilities, no matter what additional capabilities the system may support." (Codd, 1990) That means, no matter what additional features a relational database might support, in order to be truly called relational it must comply with the 12 rules. Codd added this rule in Also he expanded this 12 rules to 18 to include rules on catalogs, data types (domains), authorization and other. Codd himself had to admit the fact that based on the above rules there is no fully relational database system available. This has not changed since To be more specific rules 6, 9, 10, 11 and 12 seem to be difficult to satisfy. 23

25 2_IntroductionToRDBMS.ppt Key Points Databases are an efficient way to store large amounts of data. Relational Databases contain tables and fields. It ensures that any data entered is valid and doesn t corrupt the database. Databases are part of a larger software application called a database management system (DBMS). A database to be called as RDBMS, should adhere to Codd s Rules. Accenture 2009 All Rights Reserved 21 Questions and Comments What questions or comments do you have? Accenture 2009 All Rights Reserved 22 24

26 3_DatabaseDesignTechniques.ppt Introduction to RDBMS and SQL Module 3: Database Design Techniques. Accenture, its logo, and Accenture High Performance Delivered are trademarks of Course Accenture. Code #IDCGF002 Agenda Normalization. Types of Normal forms. First Normal Form. Functional Dependency. Full Functional Dependence and Partial Functional Dependence. Second Normal Form. Transitive Dependency. Third Normal Form. Denormalization

27 3_DatabaseDesignTechniques.ppt Learning Objectives Understand Database design techniques. Understand d the need for normalization. at o Understand different types of normalization. Understand Functional dependencies. Understand Denormalization.. 3 Normalization Normalization is the process of efficiently organizing data in a database. It is a design technique that is widely used as a guide in designing relational databases. Normalization is essentially a two step process It puts data into tabular form by removing repeating groups. It removes duplicated data from the relational tables. Normalization theory is based on the concepts of normal forms

28 3_DatabaseDesignTechniques.ppt Normal Forms A relational table is said to be in a normal form if it satisfies a certain set of constraints. They are special properties and constraints that a table schema should possess in order to achieve certain desired goals like minimizing redundancy of data. There are six normal forms that have been defined First Normal Form (1NF) Second Normal Form (2NF) Third Normal Form (3NF) Boyce Codd Normal Form (BCNF) Fourth Normal Form (4NF) Fifth Normal Form (5NF) The Third Normal Form is quite sufficient for most business database design purposes.. 5 Example of Normalization Normalize the following Data item_ no item_desc price manufacturer_id manufacturer _name distributor_ id distributor _name order_id date_entered Qty 1 Watches 3000 M1001 Aqua Marine D1001 Marine World May Water Pens 1000 M1002 Magnum D1002 World May Mobiles 4000 M1003 Coral D1003 Alpha Company May

29 3_DatabaseDesignTechniques.ppt A design is in the first normal form if: There are no repeating groups All the key attributes are defined All attributes are dependent on the primary key A table is said to be in the 1NF when each cell of the table contains precisely one value. Consider the following project Table. ECODE DEPT Projecode Hours E101 System p27 90 p p20 60 E305 Sales p p22 98 E508 Admin p51 null p27 72 The data in the table is not normalized because cell in ProjCode and Hours has more than one value. 28

30 3_DatabaseDesignTechniques.ppt Content continued: By applying the 1NF definition to the Project table, you arrive at the following table. ECODE DEPT Projecode Hours E101 Systems p27 90 E101 Systems p E101 Systems p20 60 E305 Sales p E305 Sales p22 98 E508 Admin p51 Null E508 Admin p

31 3_DatabaseDesignTechniques.ppt 30

32 3_DatabaseDesignTechniques.ppt Consider the example: EmployeeID EmpName Loc E100 Reshma MDC E101 Kshitij DDC E102 Asha PDC E103 Shivraj HDC E104 Neeta CDC E105 Naveen BDC In the example, Employee Name has a functional dependency on Employee ID, because a particular Employee ID value corresponds to one and only one Employee Name value. The reverse is not true because there could be several employees having the same name and hence one Employee name value could correspond to more than one Employee ID. Employee ID is therefore not functionally dependent on Employee Address. 31

33 3_DatabaseDesignTechniques.ppt Content Continued: Find the functional dependency between the attributes. CourseCode CourseName Duration C_101 Unix 16 C_102 Oracle SQL 24 C_103 Oracle-PLSQL 32 C_104 C 24 C_105 C

34 3_DatabaseDesignTechniques.ppt 33

35 3_DatabaseDesignTechniques.ppt 34

36 3_DatabaseDesignTechniques.ppt Let us take another example to understand Full functional dependence and Partial functional dependence. Suppose we have a transaction relation as shown here. For the Transaction relation, we may now say that: Cname is fully functionally dependent on C# Ccity is fully functionally dependent on C# Cphone is fully functionally dependent on C# Qnt is fully functionally dependent on (C#, P#, Date composite key) Cname is not fully functionally dependent d on (C#, P#, Date), it is only partially dependent on it (and similarly for Ccity and Cphone). 35

37 3_DatabaseDesignTechniques.ppt A relation is in 2NF if and only if it is in 1NF and every non-key attribute is irreducibly dependent on the primary key or A table to be in 2NF, the non key attributes must be fully functionally dependent on the Whole Key and not part of a Key. The example discussed before is in first normal form. To convert into Second Normal form, apply functional dependency on the attributes of the table. Two tables are created out of the above example. 1 st table Items and 2 nd table Orders. 36

38 3_DatabaseDesignTechniques.ppt Example : Let s take an example in which a project manager manages a number of projects. Now the relation Project has a candidate key ProjectNum. The ProjectNum field determines the values for all other fields ProjectTitle, ProjectMgr and Phone. For a particular projectnum, there will always be a unique value in these other fields. So ProjectTitle, ProjectMgr and Phone are fully functionally dependent on ProjectNum. Now consider the attribute Phone. The phone number is dependent on the manager and manager is dependent on the project number. This is transitive dependency. Note that project manager is not a candidate key since the same manager manages more than one project. 37

39 3_DatabaseDesignTechniques.ppt Boyce-Codd normal form (BCNF) is a more rigorous version of the 3NF deal with relational tables that had (a) multiple candidate keys (b) composite candidate keys and (c) candidate keys that overlapped. Fourth Normal Form A relational table is in the fourth normal form (4NF) if it is in BCNF and all multivalued dependencies are also functional dependencies. Fifth Normal Form A table is in the fifth normal form (5NF) if it cannot have a lossless decomposition into any number of smaller tables. 38

40 3_DatabaseDesignTechniques.ppt 39

41 3_DatabaseDesignTechniques.ppt 40

42 3_DatabaseDesignTechniques.ppt In the example the relation Item, item_id is the primary key. The item_id determines the values for all the other fields Item_Desc, Price, manufacturer_id, Distributor_id.Manufacturer name is dependent on manufacturer_id which is not a candidate key. The attribute manufacturer_name is dependent on the manufacturer_id and manufacturer_id is dependent on the item_id. This is transitive dependency. The manufacturer_id is not a candidate key since the same manufacturer can supply many items. Same is the case with Distributor_id and Distributor_name. The attribute distributor_name is dependent on the Distributor_id and Distributor_id is dependent on the item_id. This is transitive dependency. The Distributor_id is not a candidate key since the same distributor can supply many items. 41

43 3_DatabaseDesignTechniques.ppt DENORMALIZATION What is DENORMALIZATION? Denormalization is a technique which is the opposite of normalization. In order to speed up the database access, it suggests to move from higher level of normalization to lower normal forms of database modeling. NEED FOR DENORMALIZATION Consider 2 tables Orders and OrderItems which stores the order and items to be ordered respectively. As per your analysis, you have created a view called Order_Item_View. This is one of the most heavily used views in the database. To read data from Order and the OrderItems table will require a join statement and access to many physical pages. To write data will require several update statements. Moreover 90 percent of Orders have no more than 5 positions. To avoid joins, you can merge the two tables into 1 table. Data is normalized to avoid maximum redundancy. They are not optimized for minimum access time. In the case of denormalization process, time does not play a role. The only reason why denormalization is done is to enhance the performance.. 21 Denormalization (Contd )

44 3_DatabaseDesignTechniques.ppt 3: Database Design Techniques Activity Input documents: Activity_1.0_Module3_Datab asedesigntechniques.doc Output document: Activity_1.0_Module3_Datab asedesigntechniquesoutput.doc 60 Minutes. 23 3: Database Design Techniques Key Points Normalization is the process of efficiently organizing data in a database. Normalization is designed to logically address potential problems with information stored in a database. There are six normal forms. Typically a database will be in Third Normal Form

45 3_DatabaseDesignTechniques.ppt 3: Database Design Techniques Key Points (Contd ) A design is said to be in first normal form(1nf) when there are no repeating groups and all attributes are dependent on the primary key. An entity type is in second normal form (2NF) if it is in 1NF and all its attributes are dependent on the primary key. A transitive dependency is a type of functional dependency in which the value in a non-key field is determined by the value in another non-key field and that field is not a candidate key : Database Design Techniques Questions and Comments What questions or comments do you have?

46 4_ERModel.ppt Introduction to RDBMS and SQL Module 4: ER Model of Database. Accenture, its logo, and Accenture High Performance Delivered are trademarks of Course Accenture. Code #IDCGF002 Agenda Introduction to Entity Relationship (ER) Model. Entity Relationship Diagram (ERD). Entities, Attributes and Relationships. Mapping cardinalities One to one. One to many. Many to one. Many to many. Keys Primary Key. Candidate Keys. Alternate Key. Foreign Key. Composite key

47 4_ERModel.ppt Learning Objectives Understand the Entity-Relationship (ER) model Understand Entity Relationship diagram Understand Entities, Attributes and Relationships Understand different types of cardinalities Creating Entity Relationship Diagram Understand Different types of Keys. 3 E-R Model E-R model means Entity Relationship Model. It describes basic objects called entities as understood in real world and relationships among the objects It is a way of graphically representing the logical relationships of entities (or objects) in order to create a database E-R model helps to develop the logical database design of the System E-R model facilitates easy design of the database to represent the logical structure of the database. 4 46

48 4_ERModel.ppt Entity Relationship Diagram (ERD) Based on the perception of the real world, an E-R diagram is prepared as shown below Real world ERD Definition Symbol Object Entity An entity is an any object or activity which an enterprise records. Property Attribute Instantiated from an object. Relationship Relationship Association between two dependent objects.. 5 Entity An Entity is an object in the real world about which we want or need to maintain information. Examples: Persons: - information stored about people. Ex: Customers, Employees, Authors, Things: Companies, Assets Employee. 6 47

49 4_ERModel.ppt Attributes Attributes are the significant properties or characteristics of an entity that help in describing the entity and provide the information needed to interact with it or use it. Birth date First Middle Last Name Employee Age SSN Projects. 7 Relationship Relationships are the associations between entities. They can involve one or more entities and belong to particular relationship types. Dept Assigned DeptHead Where Dept and DeptHead are Dependent Entity. Assigned is Relationship

50 4_ERModel.ppt Mapping cardinalities Cardinality is a quantity relationship between elements. The number of rows in the table is called as cardinality. Mapping cardinalities or cardinality ratio, expresses the number of entities to which another entity can be associated via a relationship set. The following are the different mapping cardinalities One to one. One to many. Many to one. Many to Many.. 9 One to one (1:1) An entity in A is related to at most one entity in B, and an entity in B is related to at most one entity in A. Example 1: EMPLOYEE WORKSTATION Entity A Represents 1 Entity B Every Employee is assigned to One Workstation. Example 2: One Customer can hold one Salary Account in a bank

51 4_ERModel.ppt Few more examples of Schematic Relationship: Each DEPARTMENT has many LECTURERS, one of whom is. head of the DEPARTMENT; A LECTURER belongs to only one DEPARTMENT; Each DEPARTMENT offers many different COURSES; Each COURSE is taught by a single LECTURER; A STUDENT may enroll for many COURSES offered by..... different DEPARTMENTS. 50

52 4_ERModel.ppt Many to One (N : 1) An entity in A is related to at most one entity in B, but an entity in B is related to any number of entities in A. Example 1: State City Entity A Entity B A city exists in only one state. However each state will have many cities. Example 2: Many Customers can hold different Accounts in one bank.. 12 Many to Many (M:N) An entity in A is related to any number of entities in B, similarly an entity in B is related to any number of entities in A Example 1: STUDENT COURSE Entity A Entity B A Student can enroll for more than one course. And each course will contain more than one student Example 2: Many products purchased by many customers

53 4_ERModel.ppt Relationships of College DB : 1:1 relationship N:1 relationship between LECTURER & DEPARTMENT; between LECTURER & DEPARTMENT 1:N relationship between DEPARTMENT & COURSE; M:N relationship between STUDENT & COURSE 1:N relationship between LECTURER & COURSE 1:1 relationship HEAD_OF between LECTURER & DEPARTMENT; N:1 relationship IS_IN between LECTURER & DEPARTMENT 1:N relationship OFFERS between DEPARTMENT & COURSE; M:N relationship ENROLLS between STUDENT & COURSE 1N 1:N relationship TEACHES between LECTURER & COURSE. 52

54 4_ERModel.ppt Keys Keys are used to validate the data that is being entered into a database Keys play a vital role in Maintaining data accuracy in a Database There are Four types of keys Primary Key Candidate Key Alternate Key Composite key. 15 Primary Key Primary key enforces integrity of the data by uniquely identifying records. A table can have only 1 primary key Primary Key Emp No Name Designation 1000 Venkat SSE 2000 Ramesh Team Leader 3000 Poornima ASE

55 4_ERModel.ppt Candidate key Candidate key is a Key that helps to uniquely identify row in a table It could potentially serve as the primary Key. Primary Key The example shows the columns that either EmpNo or WS# can be identified as candidates to become a primary key since choosing any one of them will make a row unique. In these cases we have to choose voluntarily one column as primary key. Emp No WS# PrjName 4561 WS.A.1 Greenfield 4562 WS.B.2 Am Express 4563 WS.C.3 Avanande Candidate Key (All rows are Unique). 17 Candidate Key (Contd...) Overlapping candidate key: Two candidate keys overlap if they involve two or more attributes each (composite candidate key) and have one or more attribute in common. Emp No WS# PrjName 4561 WS.A.1 Greenfield 4562 WS.B.2 Am Express 4563 WS.C.3 Avanande First Candidate Key Second Candidate Key In this example you can choose EmpNo and WS# to unique identify the row or WS# and PrjName, in which the WS# is common

56 4_ERModel.ppt Alternate Key Non-key attribute: Attribute that is not identified as a candidate key Alternate Key: Any of the candidate keys that is not the primary key is called an alternate key. 19 Foreign Key Foreign key :It provides relationship between table in the database In relational database, a foreign key of a table is a set of Column/Columns that references the primary key of another table The enforcement of this Constraint is Known as Referential Integrity

57 4_ERModel.ppt Composite Key A key composed of more then one column is called composite key or concatenated Key EmpNo WS# Start date End date Hours single 4561 AS12 12/11/ /3/ AS13 12/11/ /11/ AS14 13/11/ /11/ Primary key is a combination of Emp No. and WS#. 21 Activity Input documents: Activity_2.0_Module4_ER Model.doc Output document: Activity_2.0_Module4_ER ModelOutput.doc 60 Minutes

58 4_ERModel.ppt Key Points E R model is the building block of any database. E R Model is essential for any good database design. Keys play a vital role in Maintaining data accuracy in a Database Primary key enforce entity integrity by uniquely identifying entity instances. Candidate key is a Key that uniquely identifies row in a table. Key Composed more then one column is called composite key or concatenated Key. 23 Questions/ Comments What questions or comments do you have?

59 5_IntroductionToSQL.ppt Introduction to RDBMS and SQL Module 5: Introduction to SQL. Accenture, its logo, and Accenture High Performance Delivered are trademarks of Accenture. Agenda What is SQL. The SQL sublanguages. Data Definition Language. Data Manipulation Language. Data Control Language Transaction Control

60 5_IntroductionToSQL.ppt Objectives Understand SQL. Understand the Sublanguages of SQL. Understand basic SQL queries.. 3 Structured Query Language (SQL) SQL is Structured Query Language. It is a special-purpose, nonprocedural language that supports the definition, iti manipulation, and control of data in relational database management systems. SQL is used to manipulate and retrieve data stored in a database. SQL is the most commonly used query language available. SQL was designed by IBM during 1970 s. Word SQL is derived from Sequel

61 5_IntroductionToSQL.ppt Structured Query Language (SQL) (Contd ) Depending on the functionality SQL is classified as follows: Data Definition Language age (DDL) Data modification Language (DML) Data Control Language (DCL Transaction Control Language (TCL). 5 Sub-languages of SQL SQL is segregated into DDL,DML, DCL and TCL. Data retrieval : SELECT DDL DML DCL TCL CREATE INSERT GRANT COMMIT ALTER UPDATE REVOKE ROLLBACK DROP DELETE SAVEPOINT TRUNCATE. 6 60

62 5_IntroductionToSQL.ppt Data Definition Language : It is a method of data definition and storage. The Data Definition Language is used to create object (e.g. Table), alter the structure of an object and also to drop the object created.the concept Relating to Data Definition Language are explained in paragraph. DDL is a language used by a database management system which allows users to define the database and its objects, specifying data types, structures and constraints on the data It allows the Specification like: structure for each relation and integrity constraints set of indices to be maintained for each relation (Indexes) security and authorization information for each relation The physical storage of each relation on disk It is a language that enables users to access or manipulate data as organized by the appropriate data model DML Manipulation commands are the most frequently used SQL commands. They are used to query and Manipulate existing objects like tables 61

63 5_IntroductionToSQL.ppt Data Manipulation Language (DML) It is a language that enables users to access or manipulate data as organized by the appropriate data model. DML Manipulation commands are the most frequently used SQL commands.. They are used to query and manipulate existing objects like tables.. 8 Data Control Language (DCL) It is a language which provides users with privilege commands. DCL is the segment of SQL used for controlling access to data in a database. DCL allows protecting the tables and other objects created by a user from accidental manipulation by another user. Granting privileges (insert, select) to others, allows them to perform operations within their scope. Privileges determines whether or not a particular user can perform a command. Using DCL we can control the privileges

64 5_IntroductionToSQL.ppt Transaction Control Language (TCL) We can use SQL to control transactions. Transactions: Collections of operations that form a single logical unit of work. It ensures that all changes made are either committed to the database or if there is a failure at any point of time then none of the changes are committed in the database. Transaction changes can be made permanent to a database only if they are committed. Transactions operations are executed between the begin and end of the Transaction.. 10 Key Points Define and understand Query Languages that are vital in extracting information from a database SQL is the most commonly used query language SQL is a declarative programming language SQL contains 3 sub languages DDL DML DCL Transaction Control

65 5_IntroductionToSQL.ppt Questions/ Comments What questions or comments do you have?

66 6_DataDefinitionLanguage.ppt Introduction to RDBMS and SQL Module 6: Data Definition Language. Accenture, its logo, and Accenture High Performance Delivered are trademarks of AccentureĊourse Code #IDCGF002 Learning Objectives At the end of this presentation, you should be able to: Understand basic datatypes of SQL. Understand how to create/alter and drop a user. Understand basic user operations such as creating and assigning privileges to a user. Understand basic schema operations such as creating, altering and deleting a table. Accenture 2009 All Rights Reserved 2 65

67 6_DataDefinitionLanguage.ppt Agenda Understanding Data Types Creating/Altering/Dropping a User Assigning and Revoking permissions on user Creating a Table Altering a Table Truncate Table Dropping a Table Accenture 2009 All Rights Reserved 3 66

68 6_DataDefinitionLanguage.ppt Oracle database makes use it own format to store date in fixed length of 7 bytes each of century, month, day, year, hour, minutes and second. To view system date and time sysdate () can be used. Using varchar2 saves disk space when compared to char. 67

69 6_DataDefinitionLanguage.ppt Data types Data Type Description Max.Size BLOB Binary Large Objects. It stores Binary 4 GB Data like storing Images CLOB BFILE Character Large Object. It stores Character Data like large documents in any character set. Binary data stored in an external file outside of oracle database 4 GB 4 GB ROWID Is a 64 base number system representing the unique address of a row in its table. -N/A (as it is internally managed by the oracle system). Accenture 2009 All Rights Reserved 5 Creating a new User A new user can be created by the command-create user. The user can log in the oracle system just as you login using scott. Syntax to create the user: Create user <username> identified by <password>; Note: To create a new user, you should have the DBA or create user privilege. il You can also do this by logging in as System or sys. Ex: Create user sam identified by admin; Accenture 2009 All Rights Reserved 6 68

70 6_DataDefinitionLanguage.ppt Altering the User A user can change his own password. Syntax : alter user <username> identified by <newpassword>; Note: This can be done by the user or the DBA, incase the user forgets or loses his password. Example : alter user sam identified by admin; Accenture 2009 All Rights Reserved 7 Dropping a User The DBA can drop or remove the user from the oracle database. Syntax: Example: Drop user <username>; drop user sam; The user is dropped from the oracle database. Accenture 2009 All Rights Reserved 8 69

71 6_DataDefinitionLanguage.ppt Assigning privileges to a user Once a user is created, the DBA has to assign privilege to the user depending on the type of access the user would require on the database. Syntax to grant privilege: grant connect, resource to <username>; Note: Grant is a DCL command used to grant the privilege to a user. Accenture 2009 All Rights Reserved 9 Assigning privileges to a user (Contd ) Privileges: Connect - user is able to connect to the database. Resource user is able to create objects. Eg: tables, views, procedures, index, functions etc. Database Administrator user gets the rights of the super user or administrator with DBA privilege. He can do the task what a System or Sys user can do. Example: SQL>grant connect, resource to SAM; Accenture 2009 All Rights Reserved 10 70

72 6_DataDefinitionLanguage.ppt Revoking the Privileges: A privilege can be revoked by using Revoke. It is a DCL command. Syntax: revoke <privilege> from <username>; Example: revoke resource from sam; Note: to revoke the privilege the user should be a dba or have dba privilege. Accenture 2009 All Rights Reserved 11 6: Data Definition Language Activity (1 of 3) Work in groups of 4 or 5 With your group, try to identify the role and responsibilities of a Database Administrator (DBA) Share your thoughts with the class 10 Minutes Accenture 2009 All Rights Reserved 12 71

73 6_DataDefinitionLanguage.ppt Creating Table Syntax CREATE TABLE table_name ( name_of_column column_datatype, [name_of_column column_datatype,] ) Example CREATE TABLE dept_info ( Deptno Number(2), Dname Varchar2(20), Loc Varchar2(20), ); Accenture 2009 All Rights Reserved 13 6: Data Definition Language Activity (2 of 3) Input documents: Activity_3.0_Module6_DataDefi nationlanguage.doc Output documents: Activity_3.0_Module6_DataDefi nationlanguageoutput.doc 60 Minutes Accenture 2009 All Rights Reserved 14 72

74 6_DataDefinitionLanguage.ppt Alter Table Statement Alter command is used to add, modify and drop columns It is used To add constraints To add a new column Syntax: y Example: ALTER TABLE table_name ADD name_of_field field data_type; type; ALTER TABLE dept_info ADD state varchar2(2); Accenture 2009 All Rights Reserved 15 Alter Table Statement Syntax to Modify Column : ALTER TABLE table_name MODIFY name_of_field data_type; Example: ALTER TABLE dept_info MODIFY dname varchar2(25); Syntax to Drop column Example: ALTER TABLE table_name DROP COLUMN name_of_field; field; ALTER TABLE Train_times DROP COLUMN state; Accenture 2009 All Rights Reserved 16 73

75 6_DataDefinitionLanguage.ppt 6: Data Definition Language Activity (3 of 3) Input documents: Activity_3.1_Module6_DataDefi nationlanguage.doc Output documents: Activity_3.1_Module6_DataDefi nationlanguageoutput.doc 45 Minutes Accenture 2009 All Rights Reserved 17 Truncate table Truncate table is used to remove all data from a table, without disturbing the structure. Syntax : Truncate table <table_name>; Example: Truncate table dept_info; The truncate command deletes all rows from specified table By adding a reuse storage clause to the same command the space that is used for the storage can be reclaimed Accenture 2009 All Rights Reserved 18 74

76 6_DataDefinitionLanguage.ppt To Remove Table DROP is used to remove a table. Syntax DROP TABLE table_name Example: DROP TABLE dept_info Accenture 2009 All Rights Reserved 19 6: Data Definition Language Question: What is the difference between truncate and the delete command? Accenture 2009 All Rights Reserved 20 75

77 6_DataDefinitionLanguage.ppt 6: Data Definition Language Key Points Integer, long varchar2 are few of the data types used in SQL. To design the schema or modifying it we have to use datatypes. To create a Table use CREATE TABLE command. Alter command is used to add, modify and drop columns. Truncate command is used for deleting the rows from a specified table. DROP is used to drop of a Table. Accenture 2009 All Rights Reserved 21 6: Data Definition Language Key Points (Contd ) A user can be created by the dba or by the user having dba privilege. To create the user use the create user command. A user can modify the password by using the alter command. To assign the privilege use the grant command. To revoke the privilege use the revoke command. Accenture 2009 All Rights Reserved 22 76

78 6_DataDefinitionLanguage.ppt Questions/ Comments What questions or comments do you have? Accenture 2009 All Rights Reserved 23 77

79 7_Constraints.ppt Introduction to RDBMS and SQL Module 7: Constraints. Accenture, its logo, and Accenture High Performance Delivered are trademarks of Accenture. Objectives At the end of this presentation, you should be able to: Understand the need of constraints Understand different types of constraints Understand how to add constraints in the schema design Understand how to remove constraints Understand how to add default value to a column. 2 78

80 7_Constraints.ppt Agenda Constraints Primary Key Constraint Foreign Key Constraint UNIQUE constraint CHECK constraint NOT NULL Constraint Default. 3 Constraints Constraint is a rule or set of rules that are applied to a column or combination of columns. It help in preventing data corruption. It help in preventing human errors while entering data into the database. Database constraints help to achieve data integrity without the need to write an external program

81 7_Constraints.ppt Types of Constraints Different Types of Constraints are as below Primary key Foreign key Check Unique Not null Constraints can be created at the time of creating the table using CREATE TABLE or after creating the table using ALTER TABLE.. 5 Primary Key Constraint Primary key Constraints avoid the duplication of data. A table can have only one primary key constraint but can have several UNIQUE constraints. Example- Create the EMP_INFO table by adding a primary key constraint PK_EMPNO on the column EMPNO. CREATE TABLE EMP_INFO (EMPNO NUMBER(4) CONSTRAINT PK_EMPNO PRIMARY KEY, ENAME VARCHAR2(20),DEPTNO NUMBER (2)) The above example creates the EMP_INFO table by adding a primary key constraint PK_EMPNO on the column EMPNO

82 7_Constraints.ppt Primary Key Constraint (Contd ) Example- Create and modify the EMP_INFO1 table by adding a primary key constraint PK_EMPNO1 on the column EMPNO. Example The example creates and modifies the EMP_INFO1 table by adding a primary key constraint PK_EMPNO1 on the column EMPNO. It also modifies the DEPT_INFO table with the primary key PK_DEPTNO on the deptno column. CREATE TABLE EMP_INFO1 (EMPNO NUMBER(4), ENAME VARCHAR2(20), DEPTNO NUMBER (2)) ALTER TABLE EMP_INFO1 ADD CONSTRAINT PK_EMPNO1 PRIMARY KEY (EmpNo); ALTER TABLE DEPT_INFO ADD CONSTRAINT PK_DEPTNO PRIMARY KEY (DEPTNO);. 7 Foreign Key Constraint When a column in one table refers to the Primary Key of another table, that column is referred as Foreign Key. It is also known as Referential Integrity and implemented through Foreign Key constraint. Example- create a table EMP_INFO2 to add a foreign key constraint: CREATE TABLE EMP_INFO2 (EMPNO NUMBER(4) CONSTRAINT PK_EMPNO2 PRIMARY KEY, ENAME VARCHAR2(20), DEPTNO CONSTRAINT FK_DEPTNO1 REFERENCES DEPT_INFO (DEPTNO)) The example adds a foreign key constraint FK_DEPTNO1 to the EMP_INFO2 table on the deptno column which references DEPTNO -the primary key of the DEPT_INFO Table

83 7_Constraints.ppt Foreign Key Constraint (Contd ) Example- Modify the EMP_INFO1 table by adding a foreign key constraint FK_DEPTNO1 on the column DEPTNO: Example : ALTER TABLE EMP_INFO1 ADD CONSTRAINT FK_DEPTNO2 FOREIGN KEY(DEPTNO) REFERENCES DEPT_INFO(DEPTNO); The above example adds a foreign key constraint FK_DEPTNO2 to the EMP_INFO1 table on the DEPTNO column which references the primary key of the DEPT_INFO Table.. 9 Unique Constraint Unique Key Constraints are used to enforce the uniqueness of a column. If a column has a Unique Constraint on it, duplicate values cannot be inserted on that column. Unique key allows Null value to be stored. Example: Create a table emp_sal to add the unique constraint. CREATE TABLE EMP_SAL The example adds a (EMPNO NUMBER(4), unique key ENAME VARCHAR2(20), constraint UK_ACTNO on the ACTNO ACTNO NUMBER (8) CONSTRAINT columns of the UK_ACTNO UNIQUE, EMP_SAL table. JOB VARCHAR2(20), HIREDATE DATE)

84 7_Constraints.ppt Unique Constraint Example: Modify the table emp_sal to add the unique constraint. ALTER TABLE EMP_SAL ADD CONSTRAINT UK_JOB_HDATE UNIQUE (job, hiredate); The above example adds a unique key constraint UK_JOB_HDATE on the job and hiredate columns of the EMP_SAL table.. 11 CHECK constraint Check Constraints are the most elementary form of integrity constraints. Check constraint is also known as Domain Integrity. This powerful feature allows to establish range for data. Check Constraints are created by specifying a domain (Range) for a column. If we specify a domain constraint for a particular column, that column will contain only values specified in that domain

85 7_Constraints.ppt Example Check Constraint Example: Create a table emp_sal1 to add the unique constraint. CREATE TABLE EMP_SAL1 (EMPNO NUMBER(4), ENAME VARCHAR2(20), ACTNO NUMBER(8),JOB VARCHAR2(20) CONSTRAINT CHK_JOB CHECK (job IN ('ANALYST','CLERK')), HIREDATE DATE) The above example adds a check constraint CHK_JOB on the JOB column of the EMP_SAL1 table. ALTER TABLE EMP_SAL add CONSTRAINT CHK_JOB CHECK (job IN ('ANALYST', 'CLERK')) The example adds a check constraint CHK_JOB on the job column of the EMP_SAL table.. 13 NOT NULL Constraint A NOT NULL constraint specifies that a column must not assume the NULL value. A NOT NULL constraint is always written as a column constraint. Example : CREATE TABLE PRODUCTS (PRODUCT_NO NUMBER(2) CONSTRAINT NN_PROFNO NOT NULL, NAME VARCHAR2(40) CONSTRAINT NN_PROD_NAME NOT NULL) The above example creates a table called products with two columns product_no and name. Both have a constraint NOT NULL

86 7_Constraints.ppt Removing Constraints A constraint can be removed as shown below Example : ALTER TABLE EMP_INFO DROP CONSTRAINT PK_EMPNO The above example removes a constraint named PK_EMPNO from EMP_INFO table.. 15 Default The default keyword is assigned to a column of a table at the time of creating a table or altering it. The value in the default keyword is applied when no value is inserted in the table using the INSERT statement. Example: Create a table products1 to create default CREATE TABLE PRODUCTS1 (PRODUCT_NO NUMBER(2) NOT NULL, NAME VARCHAR2(40) NOT NULL, STATE VARCHAR2(2) DEFAULT 'MH') INSERT INTO PRODUCTS1 (PRODUCT_NO,NAME) NAME) VALUES(1, 'PENS') The above example adds a default value of MH into the state field as no explicit value is provided while inserting

87 7_Constraints.ppt 7: Constraints Activity Input documents: Activity_4.0_Module7_Constr aints.doc Output : Activity_4.0_Module7_Constr aintsoutput.doc 45 Minutes. 17 Key Points Constraint is a rule or set of rules that apply to a column or combination of columns Constraints ensure data integrity Important constraints are Primary Key Foreign Key CHECK UNIQUE NOT NULL

88 7_Constraints.ppt Questions/ Comments What questions or comments do you have?

89 8_DataManipulationLanguage.ppt Introduction to RDBMS and SQL Module 8: Data Manipulation Language. Accenture, its logo, and Accenture High Performance Delivered are trademarks of Accenture. Learning Objectives At the end of this presentation, you should be able to: Insert new data into the table Update existing data Delete existing data Retrieve data from the table using SELECT Filter rows using WHERE clause Sort the results retrieved from the table Char, Number and Date Functions Handling NULL data using NVL Understanding DECODE function Understand the use of ESCAPE sequence and SPOOL option. 2 88

90 8_DataManipulationLanguage.ppt Module 8: Agenda Inserting New Data Updating Existing Data Deleting Existing Data Retrieving data using SELECT Basic SELECT statement Filtering rows using WHERE clause Operators and Operator Precedence Introducing NULL Data Using Aliases Sorting Information TO_CHAR, TO_NUMBER, TO_DATE functions NVL function DECODE function ESCAPE sequence and SPOOL option. 3 89

91 8_DataManipulationLanguage.ppt Table Structure for Dept table is given below: DeptNo Number(2), DNAME VARCHAR2(25), Loc Varchar2(20), State varchar2(2); 90

92 8_DataManipulationLanguage.ppt Sometimes changes to the database become imminent. For example DEPT table, to reflect such changes to the existing record in a DEPT table the update command is used. With the update command we can update rows in the Table. A single column may be updated or more than one column could be updated. Specific rows could be updated based on a specific condition. UPDATE Dept SET state= MH ; It will update all the state as KANPUR from the dept table. UPDATE Dept SET state= MH WHERE DeptNo=1; It will update the state as a MH where DEPTNO is 1 91

93 8_DataManipulationLanguage.ppt 92

94 8_DataManipulationLanguage.ppt One or More rows could be deleted using delete command. Alternatively, all rows of DEPT table could also be deleted while structure remains unaltered. To delete specific rows from a table the where clause is used in combination with the delete command. To delete several rows From a table, select the rows with appropriate condition in a where clause. The where clause can also include a query. The Delete command consists of a From clause followed by an optional where clause. Example 1: DELETE FROM DEPT; It Will delete all the rows from the DEPT table. Example 2: DELETE FROM DEPT WHERE DEPTNO=1; It will delete all the rows from DEPT table where DEPTNO = 1. 93

95 8_DataManipulationLanguage.ppt Deleting Existing Data (Contd ) Syntax for deleting all the rows DELETE FROM <table_name> Example: DELETE FROM DEPT;. 8 8: Data Manipulation Language Activity (1 of 2) Input documents: Activity_5.0_Module8_DataM anipulationlanguage.doc C:\RDBMS\Day2\createSche ma.sql Output : Execute the sql file mentioned above 15 Minutes. 9 94

96 8_DataManipulationLanguage.ppt Retrieving Columns SELECT statement is used to retrieve data from the table It can be used to retrieve a column or multiple columns from a table. Example: To get the names of all the departments SELECT DNAME FROM DEPT; List the names of the columns separated by a comma to retrieve multiple columns SELECT DNAME, LOC FROM DEPT; * is used to retrieve all columns from the table SELECT * from DEPT;. 10 Using ALL ALL is used with SELECT statement to retrieve all the dept names. The ALL keyword is optional. Example: To retrieve all dept name from table DEPT SELECT ALL DName from DEPT; By-default all the values will be retrieved from the column though ALL is not specified

97 8_DataManipulationLanguage.ppt Using DISTINCT DISTINCT keyword is used with SELECT statement to retrieve unique values from a column Example : To retrieve unique location from the table DEPT SELECT DISTINCT LOC FROM DEPT;. 12 Filtering Rows It is common to filter the results to get only the information required than selecting all the records in a table. We can use WHERE clause with SELECT statements to filter results to get only the data which is required. Syntax : Example: SELECT COL1,COL2,...FROM TABLE_NAME WHERE < SEARCH CONDITION>; SELECT EMPNO,ENAME,DEPTNO FROM EMP WHERE JOB= ANALYST ; Sample output EMPNO ENAME SAL DEPTNO =================================== 7788 SCOTT FORD

98 8_DataManipulationLanguage.ppt Operators in WHERE Clause Operators can be used with WHERE clause Operator Description <,>,<=,>=,=,<> It is used to compare values or!= IN It selects from a list of values BETWEEN Selects from a range of values NULL LIKE Compares with Null values Compares with the pattern. 14 Comparison Operators Comparison operators are used to compare the values from the left hand side of a relational operator with that on the right hand side Relational Operators are: =, <, >, <=, >=,!= or < > Example: To retrieve all the EMPNO,ENAME columns which belong to the DEPTNO 10 : Sample output SELECT EMPNO,ENAME FROM EMP WHERE DEPTNO = 10; EMPNO ENAME ===================== 7782 CLARK 7839 KING 7934 MILLER

99 8_DataManipulationLanguage.ppt Using IN Operator The IN operator is generally used to retrieve values from a list of values called as inclusive list. Inclusive liti list is a lit list which hihcontains ti multiple ltil values to be retrieved for the same column. The IN operator checks the database to see if the specified column matches one or more of the values listed inside the list. Example : To get the list of Employees working as MANAGER and ANALYST: SELECT EMPNO,ENAME FROM EMP WHERE JOB IN ( MANAGER, ANALYST ); Sample Output EMPNO ENAME ================ 7566 JONES 7698 BLAKE 7782 CLARK 7788 SCOTT 7902 FORD. 16 Using BETWEEN Operator The BETWEEN operator allows to specify a range of values. Where the range consists of lower range and a higher range. It eliminates the use of >= and <= Relational operators BETWEEN operator can be modified using AND Example: To get EMPNO,ENAME,JOB,SAL where salary is in the range 1000 to 2000 (inclusive) : Sample output SELECT EMPNO,ENAME,JOB,SAL FROM EMP WHERE SAL BETWEEN 1000 AND 2000; EMPNO ENAME JOB SAL ==================================== 7499 ALLEN SALESMAN WARD SALESMAN MARTIN SALESMAN TURNER SALESMAN ADAMS CLERK MILLER CLERK

100 8_DataManipulationLanguage.ppt Using LIKE Operator The LIKE operator allows you to use wildcard characters when searching a character field. A wildcard character matches any one or more characters in a string. 2 Types of Wildcards % : This wildcard matches multiple characters. _ : This wildcard matches exactly one character.. 18 Using LIKE Operator (Contd ) Examples : A% indicates matching data starting with A and having any number of characters. %S indicates matching data ending with S and having any number of characters. A_R%S indicates matching data starting with A, having r as the third character ending with S. S_A indicates matching data having S as the third character and A as the fifth character. This data should be of 5 characters only

101 8_DataManipulationLanguage.ppt Using LIKE Operator (Contd ) Example: To get details of employees whose name begin with letter S : SELECT EMPNO, ENAME, JOB,SAL FROM EMP WHERE ENAME LIKE S% ; EMPNO ENAME JOB SAL ================================= 7369 SMITH CLERK SCOTT ANALYST 3000 Example: To get details of employees whose name starts with J, and the fourth letter as E and the remaining can be anything. SELECT EMPNO, ENAME, JOB,SAL FROM EMP WHERE ENAME LIKE J E%' EMPNO ENAME JOB SAL ==================================== 7566 JONES MANAGER JAMES CLERK Using Logical operators In WHERE statement AND and OR logical operators is used to test more than one condition Operator AND OR NOT Description Both the condition on the left-hand side of the operator and the condition on the right-hand side must evaluate to true Either condition must evaluate to true. If the condition on the left-hand side of the operator evaluates to true, the next condition is not evaluated. Negates the condition. It can be used with IN, BETWEEN and LIKE operator

102 8_DataManipulationLanguage.ppt Using Logical operators (Contd ) Example: To get EMPNO, ENAME, JOB, SAL of all employees having salary a more than 2000 and working in DEPTNO 20. SELECT EMPNO, ENAME, SAL, DEPTNO FROM EMP WHERE SAL >2000 AND DEPTNO=20 EMPNO ENAME SAL DEPTNO ============================== 7566 JONES SCOTT FORD Example: To get EMPNO, ENAME, JOB of all employees working as SALESMAN S or those employees whose names start with A. SELECT EMPNO,ENAME, JOB FROM EMP WHERE JOB= 'SALESMAN' OR ENAME LIKE 'A%' EMPNO ENAME JOB ============================== 7499 ALLEN SALESMAN 7521 WARD SALESMAN 7654 MARTIN SALESMAN 7844 TURNER SALESMAN 7876 ADAMS CLERK Using Logical operators (Contd ) Example: To get EMPNO, ENAME, JOB, SAL of all employees whose names do not start with A. SELECT EMPNO, ENAME,JOB FROM EMP WHERE ENAME NOT LIKE 'A%' EMPNO ENAME JOB ============================== 7369 SMITH CLERK 7521 WARD SALESMAN 7566 JONES MANAGER 7654 MARTIN SALESMAN 7698 BLAKE MANAGER 7782 CLARK MANAGER 7788 SCOTT ANALYST 7839 KING PRESIDENT 7844 TURNER SALESMAN 7900 JAMES CLERK 7902 FORD ANALYST 7934 MILLER CLERK

103 8_DataManipulationLanguage.ppt Using NULL Operator NULL values are also known as unknown values. In RDBMS, inapplicable or missing information is known as NULL. The IS NULL condition tests for nulls. Sample output Example: To get EMPNO, ENAME and SAL from EMP who do not receive a commission. SELECT EMPNO, ENAME, SAL FROM EMP WHERE COMM IS NULL; EMPNO ENAME SAL COMM =================================== 7369 SMITH JONES BLAKE CLARK SCOTT KING ADAMS JAMES FORD MILLER Using NOT NULL Operator NOT NULL is used to check whether a particular column contains a value We can use NOT NULL to select a column which contain values Example: To get EMPNO, Sample output ENAME and SAL from EMP who do not receive a commission. SELECT EMPNO, ENAME, SAL FROM EMP WHERE COMM IS NOT NULL; EMPNO ENAME SAL COMM ================================= 7499 ALLEN WARD MARTIN TURNER

104 8_DataManipulationLanguage.ppt Using Arithmetic Operators Arithmetic operators along with the column names can be used to retrieve values Arithmetic operations can be performed on a single column or multiple columns The Arithmetic operators normally used are: +, -, / and * Example: To get EMPNO and TOTALSAL of all employees SELECT EMPNO,SAL+ COMM TOTALSAL FROM EMP WHERE COMM IS NOT NULL; Sample output : EMPNO TOTALSAL =================

105 8_DataManipulationLanguage.ppt String values can be used to give more clarity to the result set. Example: To get EMPNO and TOTALSAL for all EMPLOYEES: SELECT EMPNO AS EmployeeNum, SAL+COMM AS Total Sal FROM EMP; 104

106 8_DataManipulationLanguage.ppt Column standing position is the position of the column in the select statement. The column standing position comes handy when we are applying some aggregate functions on a column name and that column has to be used in the order by clause Example : SELECT ENAME,JOB FROM P WHERE DEPTNO IN (10,20) ORDER BY 1 DESC, 2; 105

107 8_DataManipulationLanguage.ppt 106

108 8_DataManipulationLanguage.ppt Try out different combinations for date. 1) Display month 2) Display only year 3) Display day 4) Display hour, min and seconds 107

109 8_DataManipulationLanguage.ppt To_number It converts a char value which contains digits to a numeric value. Sample Output : SELECT TO_NUMBER(TO_CHAR(HIREDATE,'MM')) AS MONTHNUMBER FROM EMP MONTHNUMBER ============== Date Functions: MONTHS_BETWEEN: It finds the number of months between two dates. Syntax : MONTHS_BETWEEN(date1, date2) Example : SELECT MONTHS_BETWEEN(SYSDATE,'1-OCT-08')From dual Sample Output : MONTHSBETWEEN ==================

110 8_DataManipulationLanguage.ppt NVL Function Converts a null value to a non-null value. Syntax : NVL(arg1, arg2) If argument1 is not null, then it displays its value. If argument 1 is null, then it displays arg2. Example: SELECT NVL(COMM,0) FROM EMP. 33 NVL Function (Contd...) SELECT NVL(COMM,0) AS COMMISION FROM EMP COMMISION ============ Sample Output t SELECT NVL(TO_CHAR (COMM),'NO COMMISION') AS COMMISION FROM EMP COMMISION ============ NO COMMISION NO COMMISION 1400 NO COMMISION NO COMMISION NO COMMISION NO COMMISION 0 NO COMMISION NO COMMISION NO COMMISION NO COMMISION

111 8_DataManipulationLanguage.ppt DECODE The DECODE function behaves like the IF..THEN..ELSE statement. Syntax: DECODE (expression, search1, result1 [, search2, result2]... [, default] ) If the value of expression is equivalent to search1 then result1 is returned, else expression is compared to search2 and if found equal returns result2 and so on. If no match found, then default is returned.. 35 DECODE (Contd...) Example: SELECT DECODE(JOB,'ANALYST','A,'CLERK','C', 'MANAGER','M','PRESIDENT',' P','SALESMAN','S') AS JOB FROM EMP; Sample Output : JOB ===== C S S M S M M A P S C C A C

112 8_DataManipulationLanguage.ppt ESCAPE option Escape option is used when you use special characters in the string and the actual meaning of these characters should be ignored when % and _ are used for pattern matching. The option specifies what the escape character is when you want to search for strings that contains Sr_ Example: If job contains: Sr_MAN Sr_Exec Sr_Asst Sr_Clerk SQL> SELECT * FROM EMP WHERE JOB Output: LIKE Sr\_% ESCAPE \ ; SA_MAN SA_REP SA_REP SA_REP. 37 Printing the SQL Output The SQL output can be redirected using SPOOL command. By default the redirection is on the screen, but it can be changed to file or printer as required. SPOOL ON SELECT * FROM EMP; Redirection IS ON SCREEN SPOOL PRN; SELECT * FROM EMP; Redirection IS ON PRINTER SPOOL OFF

113 8_DataManipulationLanguage.ppt Printing the SQL Output (Contd...) TO FILE: SPOOL FILE1 SELECT * FROM EMP; Redirected TO FILE1.LST [c:\oracle\bin ] SPOOL OFF. 39 8: Data Manipulation Language Activity (2 of 2) Input documents: Activity_5.1_Module8_DataM anipulationlanguage.doc Output documents: Activity_5.1_Module8_DataM anipulationlanguageoutput.d oc 120 Minutes

114 8_DataManipulationLanguage.ppt Key Points RDBMS allow to view tables and the records they hold. It allows to add, modify and delete the data. SELECT statement is used to retrieve data from a table. SELECT statement along with WHERE clause can be used to filter the rows from a table. The logical operators AND, OR and NOT can be used to combine conditions for a WHERE clause. ORDER BY can be used to sort the results from a SELECT statement : Data Manipulation Language Key Points (Contd ) TO_Char converts a date or a number to a character value. To_number converts a char. string which contains digits to a numeric value. Months_Between finds the number of months between date1 and date2. NVL Converts a null value to an NON-NULL value. The DECODE function behaves like the IF..THEN..ELSE statement SQL output can be redirected by using SPOOL command

115 8_DataManipulationLanguage.ppt Questions/ Comments What questions or comments do you have?

116 9_AggregateFunctions_Joins_Subquries.ppt Introduction to RDBMS and SQL Module 9: Aggregate Functions, Joins and Sub queries. Accenture, its logo, and Accenture High Performance Delivered are trademarks of Accenture. Learning Objectives Understand aggregate functions Work with Group By and Having By Clause. Work with Set Operators. Work with Sub queries and Correlated sub queries Work with EXISTS and NOT EXISTS Work with different types of joins Understand the difference between joins and subqueries

117 9_AggregateFunctions_Joins_Subquries.ppt Module 9: Agenda Aggregate Functions Retrieval Using GROUP BY and HAVING Clause Set Operators Union. Intersect. Minus. Subqueries Non-Corelated Subqueries. Correlated Subqueries. Joins Inner Join Self Join Outer Join Use of EXISTS 3. Aggregate functions Aggregate functions are functions that take a collection (a set or multiset) of values as input and return a single value. Each of these functions perform an action that draws data from a set of rows instead of a single row. Aggregate functions are used along with the column names in the SELECT statement. Aggregate functions ignore null values. Aggregate functions cannot be used with the WHERE clause

118 9_AggregateFunctions_Joins_Subquries.ppt Aggregate functions (Contd..) Function Name SUM() AVG() MAX() MIN() COUNT(Qty) COUNT(*) Description Adds up the values in the specified column of numeric data type. Value of the sum must be within the range of that data type. Returns the average of all the values in the specified column. Column must be numeric data type. Returns the largest value that occurs in the specified column. Column need not be numeric data type. Returns the smallest value that occurs in the specified column. Column need not be numeric data type. Returns the number of rows that do not have NULL Value in the column Qty. Returns the number of rows in the table

119 9_AggregateFunctions_Joins_Subqueries.ppt The aggregate functions ignore the null values while applying aggregation. Example: SELECT AVG(COMM) FROM EMP will return 550, however SELECT AVG(NVL(COMM,0)) FROM EMP will return The difference in result is due to the null values ignored in the earlier example. With the use of NVL function, the null values are converted to 0 and hence they are used while performing the average function. 118

120 9_AggregateFunctions_Joins_Subquries.ppt Using GROUP BY Any column on which the aggregate function is used is called an aggregate column and a column on which an aggregate function is not applied is called a non-aggregate column. GROUP BY clause works on rows which can be grouped on the basis of non-aggregate columns. The GROUP By clause cannot work on its own, it has to be used with aggregate functions. GROUP BY allows to group identical data into one subset rather than listing each record and sorts the data on the grouped column. The GROUP BY clause must include all the non-aggregate columns mentioned in the SELECT statement. Example: Find the number of Employees belonging to a particular department Total salary for each job. 7 Example - GROUP BY Clause Example: Display JOB, TOTALSAL of each employee. SELECT JOB, SUM(SAL) TOTALSAL FROM EMP GROUP BY JOB; JOB TOTALSAL Sample Output : =================== ANALYST 6000 CLERK 4150 MANAGER 8275 PRESIDENT 5000 SALESMAN

121 9_AggregateFunctions_Joins_Subquries.ppt Using HAVING Clause HAVING Clause is used to filter data and is used only with GROUP BY clause Aggregate functions can be used with the HAVING clause. Both the WHERE and HAVING clause are used for filtering the data. However, the WHERE clause is applied before the GROUP BY whereas the HAVING clause is applied after GROUP BY. HAVING clause is used in situations ti where the filtering i is required on the aggregate columns. Syntax: SELECT column_list FROM table GROUP BY column HAVING condition

122 9_AggregateFunctions_Joins_Subqueries.ppt To display the total number of employees in each dept, the query is: SELECT DEPTNO,COUNT(*) FROM EMP GROUP BY DEPTNO However, if the total number of employees working in each dept should be more than 3 then the query is: SELECT DEPTNO,COUNT(*) FROM EMP GROUP BY DEPTNO HAVING COUNT(*)>3; 121

123 9_AggregateFunctions_Joins_Subquries.ppt 9: Aggregate Functions, Joins and Sub queries Activity (1 of 4) Input documents: Activity_6.0_Module9_Aggregate.d oc Output documents: Activity_6.0_Module9_AggregateO utput.doc 60 Minutes. 11 SET Operators The SET operators are used to work on multiple tables and return information that is either Common as well as unique in all the tables Common in all the tables Unique in the table There are 3 sets of operators UNION/UNION ALL INTERSECT MINUS For the above operators to work correctly, same number of columns must be specified in each SELECT statement and the data types should also match. The order by clause can be used at the end of the last select statement and can be sorted only on the columns specified in the first SELECT statement

124 9_AggregateFunctions_Joins_Subquries.ppt Using UNION Union operator is used to combine the result of two or more SELECT statements into one result set. It returns all distinct rows selected by the queries. Duplicates are removed unless UNION ALL is used. Syntax: SELECT column-list list FROM table UNION SELECT column-list FROM table. 13 Using UNION (Contd ) Example: To get a list of all the deptno where the employees are working along with the list of those deptno where no employees are working in it. SELECT DEPTNO FROM DEPT UNION SELECT DEPTNO FROM EMP Sample Output : DEPTNO =================

125 9_AggregateFunctions_Joins_Subquries.ppt Using INTERSECT INTERSECT operator returns only rows that are common in all the tables. Syntax: SELECT column-list FROM table1 INTERSECT SELECT column-list FROM table2. 15 Using INTERSECT (Contd ) Example: To get a list of all deptno which has employees working in it. SELECT DEPTNO FROM DEPT INTERSECT SELECT DEPTNO FROM EMP DEPTNO Sample Output t : =================

126 9_AggregateFunctions_Joins_Subquries.ppt Using Minus MINUS operator returns only rows that are unique in the first table. Syntax: SELECT column-list FROM table1 MINUS SELECT column-list li FROM table2. 17 Using Minus (Contd ) Example: To get a list of all deptno which does not have any employees working in it. SELECT DEPTNO FROM DEPT MINUS SELECT DEPTNO FROM EMP DEPTNO Sample Output t : =================

127 9_AggregateFunctions_Joins_Subquries.ppt 9: Aggregate Functions, Joins and Sub queries Activity (2 of 4) Input documents: Activity_6.1_Module9_Union_ Intersect_Minus.doc Output documents: Activity_6.1_Module9_Union_ Intersect_Minus.doc 45 Minutes. 19 Subqueries Subqueries are also called as Nested queries which means SELECT statement can be nested inside id another SELECT statement. t t The subquery is placed in the WHERE clause of a SELECT statement. It allows to group multiple SELECT statements together. There are 2 types of Sub queries: Independent/Non-correlated sub queries and Correlated sub queries Subqueries can return either a single row or multiple rows

128 9_AggregateFunctions_Joins_Subquries.ppt Independent/Non-Correlated Sub queries A subquery is also called as an inner query. The query which is placed before the inner query is called as the Outer query or Parent Query In Independent Sub queries Inner query is executed independent of outer query. The inner query executes only once. Inner query is executed first and the results replace the inner SELECT statement. Outer query then executes based on the results provided by the inner query.. 21 Operators used in Sub queries Operator Description Comparison (=<><><=>=) (=,<>,<,>,<=,>=). Usedwhensubquery subquery returns Operator a single value. IN It is used to select rows that match the value in a list. Used when subquery returns multiple rows. ANY or SOME It compares a value to either each value ALL returned ed by a sub query or all values returned ed by the subquery. Used when subquery returns multiple rows along with comparison operators. EXISTS It always returns data in terms of TRUE or False value. Used with co-related subqueries

129 9_AggregateFunctions_Joins_Subqueries.ppt Contents: If the option of subquery was not available then to solve the query of finding the employees who are receiving the salary less than the average salary, 2 separate queries will be required as shown below: 1) Find the average salary SELECT AVG(SAL) FROM EMP 2) Get the average salary and find the employee names. SELECT ENAME FROM EMP WHERE SAL < Instead of executing these two queries separately, you can execute it through a subquery. The advantage here is that if there are any change in the EMP table, i,e new record is added in emp table or the salary is updated or a record is deleted, then the second query will not give the correct result since the average is changed. So, for every change in the EMP table, the first query has to be run first, the average has to be noted and then execute the second query. To avoid this situatuion subquery can be used as shown below: SELECT ENAME FROM EMP WHERE SAL < (SELECT AVG(SAL) FROM EMP); 128

130 9_AggregateFunctions_Joins_Subquries.ppt Non-Corelated Sub queries (Contd ) Subqueries returning multiple rows. Example: To display the names of the employees working in dept ACCOUNTING and SALES. Sample Output : SELECT ENAME,JOB,SAL FROM EMP WHERE DEPTNO IN (SELECT DEPTNO FROM DEPT WHERE DNAME IN ('ACCOUNTING','SALES')) ENAME JOB SAL ============================ ALLEN SALESMAN 1600 WARD SALESMAN 1250 MARTIN SALESMAN 1250 BLAKE MANAGER 2850 CLARK MANAGER 2450 KING PRESIDENT 5000 TURNER SALESMAN 1500 JAMES CLERK 950 MILLER CLERK Non-Corelated Sub queries (Contd ) Subqueries with ANY/ALL operators Example: To find the names of Example: To find the names of the the employees who receive employees who receive salary less salary less than every average than either of average salary for salary for each type of job. each type of job. SELECT ENAME,JOB, SAL FROM EMP WHERE SAL <ALL (SELECT AVG(SAL)FROM EMP GROUP BY JOB) Sample Output : ENAME JOB SAL ======================== SMITH CLERK 800 JAMES CLERK 950. SELECT ENAME,JOB, SAL FROM EMP WHERE SAL <ANY (SELECT AVG(SAL)FROM EMP GROUP BY JOB) Sample Output : ENAME JOB SAL =========================== SMITH CLERK 800 ALLEN SALESMAN

131 9_AggregateFunctions_Joins_Subquries.ppt Correlated Sub queries Correlated subquery is a subquery that references the outer query. For Correlated Subqueries Inner query is dependent upon the outer query The inner query is executed as many times as the outer query executes.. 26 Example Correlated sub query To get the employee details who earn salary greater than the average salary of their department. SELECT EMPNO,ENAME,SAL,DEPTNO FROM EMP E WHERE SAL >(SELECT AVG(SAL) FROM EMP E2 WHERE E1.DEPTNO=E2.DEPTNO); EMPNO ENAME SAL DEPTNO Sample Output : ============================ 7499 ALLEN JONES BLAKE SCOTT KING FORD

132 9_AggregateFunctions_Joins_Subquries.ppt Example Correlated sub query To get employee names who have a reporting authority. Sample Output : SELECT ENAME FROM EMP E1 WHERE MGR =(SELECT EMPNO FROM EMP E2 WHERE E1.MGR MGR=E2.EMPNO); EMPNO); ENAME ========= SMITH ALLEN WARD JONES MARTIN BLAKE CLARK SCOTT TURNER ADAMS JAMES FORD MILLER. 28 Using EXISTS Exists clause checks for the existence of rows and does not compare columns or its values. It is used to check the existence of data rows according to the condition specified in the inner query and passes the existence status to the outer query to produce the result set. EXISTS clause, always returns data in terms of a TRUE or FALSE value. EXISTS clause can also be used with the not operator. The inner query need not specify any columns in the select statement

133 9_AggregateFunctions_Joins_Subquries.ppt Example using Exists Example To list the employee details who directly report to manager KING. SELECT ENAME FROM EMP E1 WHERE EXISTS (SELECT * FROM EMP E2 WHERE E1.MGR=E2.EMPNO AND E2.ENAME= KING ); Sample Output : ENAME ======= JONES BLAKE CLARK. 30 9: Aggregate Functions, Joins and Sub queries Activity (3 of 4) Input documents: Activity_6.2_Module9_Subqueries. doc Output documents: Activity_6.2_Module9_Subqueries. doc 100 Minutes

134 9_AggregateFunctions_Joins_Subquries.ppt JOINS Joins are normally used to retrieve data from more than one table. The JOIN keyword joins one or more tables together in a results set To perform a join there must be a common key that defines how the rows in the table correspond to each other. All subqueries can be converted to joins but all joins cannot be converted to subqueries.. 32 Types of Joins Different types of joins are Inner join Outer join Left-outer join Right-outer join Full outer join Self join

135 9_AggregateFunctions_Joins_Subquries.ppt Inner Join The inner join joins two or more tables returning only matched rows Inner Join requires that both tables involved in the join must have a primary-foreign key relationship. 34 Inner Join (contd...) Example: To display the ename, job, sal and dname in which the employees are working SELECT ENAME, JOB,SAL, DNAME FROM DEPT D,EMP E WHERE D.DEPTNO=E.DEPTNO; DEPTNO=E DEPTNO; Sample Output ENAME JOB SAL DNAME ===================================== SMITH CLERK 800 RESEARCH ALLEN SALESMAN 1600 SALES WARD SALESMAN 1250 SALES JONES MANAGER 2975 RESEARCH MARTIN SALESMAN 1250 SALES BLAKE MANAGER 2850 SALES CLARK MANAGER 2450 ACCOUNTING SCOTT ANALYST 3000 RESEARCH KING PRESIDENT 5000 ACCOUNTING TURNER SALESMAN 1500 SALES ADAMS CLERK 1100 RESEARCH JAMES CLERK 950 SALES FORD ANALYST 3000 RESEARCH MILLER CLERK 1300 ACCOUNTING

136 9_AggregateFunctions_Joins_Subquries.ppt Outer Join Outer Join returns not only the common rows from the tables but also returns the rows that are unique in the tables In Outer Join, rows are returned even if the rows from one table is not matching with those of another table There are three types of Outer Joins Left outer join Right outer join Full outer join. 36 Left Outer Join In left outer join, all the records from the table on the left of the OUTER JOIN statement are returned Syntax SELECT column_list FROM left_table LEFT [OUTER] JOIN right_table ON condition SELECT column_list FROM table t1,table t2 where t1.column_name=t2.column_name (+)

137 9_AggregateFunctions_Joins_Subquries.ppt Left Outer Join (contd ) Example: To display the ename, job, sal and dname in which the employees are working along with the dname in which no employees are working. SELECT ENAME, JOB,SAL, DNAME FROM DEPT D LEFT JOIN EMP E ON D.DEPTNO = E.DEPTNO; Sample Output ENAME JOB SAL DNAME ===================================== SMITH CLERK 800 RESEARCH ALLEN SALESMAN 1600 SALES WARD SALESMAN 1250 SALES JONES MANAGER 2975 RESEARCH MARTIN SALESMAN 1250 SALES BLAKE MANAGER 2850 SALES CLARK MANAGER 2450 ACCOUNTING SCOTT ANALYST 3000 RESEARCH KING PRESIDENT 5000 ACCOUNTING TURNER SALESMAN 1500 SALES ADAMS CLERK 1100 RESEARCH JAMES CLERK 950 SALES FORD ANALYST 3000 RESEARCH MILLER CLERK 1300 ACCOUNTING

138 9_AggregateFunctions_Joins_Subqueries.ppt The above example will retrieve rows from order_master table which do not have any matching records in the order_detail table.such a retrieval is due to the presence of an outer join(+). 137

139 9_AggregateFunctions_Joins_Subquries.ppt Right Outer Join (contd ) Example: To display the ename, job, sal and dname in which the employees are working along with the dname in which no employees are working. SELECT ENAME, JOB,SAL, DNAME FROM EMP E RIGHT JOIN DEPT D ON E.DEPTNO = D.DEPTNO; Sample Output. ENAME JOB SAL DNAME ===================================== SMITH CLERK 800 RESEARCH ALLEN SALESMAN 1600 SALES WARD SALESMAN 1250 SALES JONES MANAGER 2975 RESEARCH MARTIN SALESMAN 1250 SALES BLAKE MANAGER 2850 SALES CLARK MANAGER 2450 ACCOUNTING SCOTT ANALYST 3000 RESEARCH KING PRESIDENT 5000 ACCOUNTING TURNER SALESMAN 1500 SALES ADAMS CLERK 1100 RESEARCH JAMES CLERK 950 SALES FORD ANALYST 3000 RESEARCH MILLER CLERK 1300 ACCOUNTING OPERATIONS 40 Full Outer Join A full outer join is essentially a combination of left and right outer joins i.e.., The records from the table on left are included even if there are no matching records on the right The records from the table on the right are included even if there are no matching records on the left. Syntax: SELECT column_list FROM left_table FULL [OUTER] JOIN right_table ON condition

140 9_AggregateFunctions_Joins_Subquries.ppt Full Outer Join (contd...) Example: Sample Output : SELECT ENAME, JOB,SAL, DNAME FROM EMP E FULL JOIN DEPT D ON E.DEPTNO = D.DEPTNO;. ENAME JOB SAL DNAME ===================================== SMITH CLERK 800 RESEARCH ALLEN SALESMAN 1600 SALES WARD SALESMAN 1250 SALES JONES MANAGER 2975 RESEARCH MARTIN SALESMAN 1250 SALES BLAKE MANAGER 2850 SALES CLARK MANAGER 2450 ACCOUNTING SCOTT ANALYST 3000 RESEARCH KING PRESIDENT 5000 ACCOUNTING TURNER SALESMAN 1500 SALES ADAMS CLERK 1100 RESEARCH JAMES CLERK 950 SALES FORD ANALYST 3000 RESEARCH MILLER CLERK 1300 ACCOUNTING OPERATIONS 42 Self Join A self-join is a query in which a table is joined (compared) to itself. It is used to compare values in a column with other values in the same column in the same table. Self-joins are also very useful in conjunction with sub queries

141 9_AggregateFunctions_Joins_Subquries.ppt Self Join (Contd ) Example: To find out the manager names for each of the employee Sample Output t : SELECT E1.ENAME ' REPORTS TO ' E2.ENAME AS REPORTS FROM EMP E1, EMP E2 WHERE E1.MGR=E2.EMPNO; Sample Output :. REPORTS ============== SMITH REPORTS TO FORD ALLEN REPORTS TO BLAKE WARD REPORTS TO BLAKE JONES REPORTS TO KING MARTIN REPORTS TO BLAKE BLAKE REPORTS TO KING CLARK REPORTS TO KING SCOTT REPORTS TO JONES TURNER REPORTS TO BLAKE ADAMS REPORTS TO SCOTT JAMES REPORTS TO BLAKE FORD REPORTS TO JONES MILLER REPORTS TO CLARK 44 9: Aggregate Functions, Joins and Sub queries Activity (4 of 4) Input documents: Activity_6.3_Module9_Joins.doc Output documents: Activity_6.3_Module9_JoinsOutput. doc 150 Minutes

142 9_AggregateFunctions_Joins_Subquries.ppt Key Points Aggregate Functions are applied on rows and return single value. GROUP BY clause works on rows which can be grouped on the basis of non-aggregate columns. SUBQUERIES are SQL statements within SQL statement. SUBQUERIES can be independent or correlated. Joins are used to retrieve data from more than one table. Different types of JOINS Inner Join. Outer Join (Left Outer Join, Right Outer Join and Full Outer Join). Self Join.. 46 Questions/ Comments What questions or comments do you have?

143 10_Views.ppt Introduction to RDBMS and SQL Module 10: Views. Accenture, its logo, and Accenture High Performance Delivered are trademarks of Accenture. Learning Objectives Understand the concept of Views Understand why views are required in a database Understand how to create and work with the views

144 10_Views.ppt Agenda Introduction to Views Creating Views Complex Views Read Only view View with Check Option. 3 Introduction to Views Views are virtual tables (tables which don t occupy memory) whose contents are taken or derived from other tables. Just like other tables, a view consists of rows with columns, and you can retrieve data from a view. Views can be used to join two tables in database and present the data as if the data were coming from a single table Views can be used as a security mechanism to restrict the data available to end users Views can also be used to aggregate data

145 10_Views.ppt This example shows creating a view called EmpView from the EMP table. This view contains two columns EmpNo and Empname which are taken from EMP table. The actual data will be in the EMP table, which can be manipulated from the EmpView. The EmpView will not occupy memory. But those who are using this view can see only EmpNo and Empname columns. They won t be able to see the entire EMP table. 144

146 10_Views.ppt This example shows how to create a view from an existing table. Ask the participants to create a table Supplier with columns supp_no, supp-name, city, state, postal_code. Ask the participants to enter few data. The example creates a view called v_supp which is derived from the Supplier table. It contains supp_no, supp_name and supp_city columns from the Supplier table. Second example creates a v_supp_city View from Supplier table. But this view contains rows which belong to the MUM city. 145

147 10_Views.ppt 146

148 10_Views.ppt The syntax of Complex view is similar to Create View Complex view is a view which contains normally GROUP BY functions as well as joins. The above example creates a complex view v_dept_emp which selects the dname column, maximum sal, minimum sal and average sal. The example uses three Aggregate functions and it joins two tables Dept and Emp. 147

149 10_Views.ppt 148

150 10_Views.ppt Faculty Notes: The With Check option clause specifies that Inserts and Updates performed through the View are not allowed to create rows which the view cannot select, and therefore allows integrity constraints and data validation checks to be enforced on data begin Inserted or Updated. 149

151 10_Views.ppt Activity Input documents: Activity_7.0_Module10_Views.doc Output documents: Activity_7.0_Module10_ViewsOutp ut.doc 45 Minutes. 11 Key Points Views are virtual tables. Views provide security of data. Views conceal complexity of queries which contain complicated queries or sub queries. Normally a complex view will contain joins, subqueries and aggregate functions

152 10_Views.ppt Questions/ Comments What questions or comments do you have?

Database Management System 9

Database Management System 9 Database Management System 9 School of Computer Engineering, KIIT University 9.1 Relational data model is the primary data model for commercial data- processing applications A relational database consists

More information

Creating and Managing Tables Schedule: Timing Topic

Creating and Managing Tables Schedule: Timing Topic 9 Creating and Managing Tables Schedule: Timing Topic 30 minutes Lecture 20 minutes Practice 50 minutes Total Objectives After completing this lesson, you should be able to do the following: Describe the

More information

Data about data is database Select correct option: True False Partially True None of the Above

Data about data is database Select correct option: True False Partially True None of the Above Within a table, each primary key value. is a minimal super key is always the first field in each table must be numeric must be unique Foreign Key is A field in a table that matches a key field in another

More information

Techno India Batanagar Computer Science and Engineering. Model Questions. Subject Name: Database Management System Subject Code: CS 601

Techno India Batanagar Computer Science and Engineering. Model Questions. Subject Name: Database Management System Subject Code: CS 601 Techno India Batanagar Computer Science and Engineering Model Questions Subject Name: Database Management System Subject Code: CS 601 Multiple Choice Type Questions 1. Data structure or the data stored

More information

SQL Interview Questions

SQL Interview Questions SQL Interview Questions SQL stands for Structured Query Language. It is used as a programming language for querying Relational Database Management Systems. In this tutorial, we shall go through the basic

More information

1 Prepared By Heena Patel (Asst. Prof)

1 Prepared By Heena Patel (Asst. Prof) Topic 1 1. What is difference between Physical and logical data 3 independence? 2. Define the term RDBMS. List out codd s law. Explain any three in detail. ( times) 3. What is RDBMS? Explain any tow Codd

More information

B.H.GARDI COLLEGE OF MASTER OF COMPUTER APPLICATION. Ch. 1 :- Introduction Database Management System - 1

B.H.GARDI COLLEGE OF MASTER OF COMPUTER APPLICATION. Ch. 1 :- Introduction Database Management System - 1 Basic Concepts :- 1. What is Data? Data is a collection of facts from which conclusion may be drawn. In computer science, data is anything in a form suitable for use with a computer. Data is often distinguished

More information

Chapter 1 SQL and Data

Chapter 1 SQL and Data Chapter 1 SQL and Data What is SQL? Structured Query Language An industry-standard language used to access & manipulate data stored in a relational database E. F. Codd, 1970 s IBM 2 What is Oracle? A relational

More information

Solved MCQ on fundamental of DBMS. Set-1

Solved MCQ on fundamental of DBMS. Set-1 Solved MCQ on fundamental of DBMS Set-1 1) Which of the following is not a characteristic of a relational database model? A. Table B. Tree like structure C. Complex logical relationship D. Records 2) Field

More information

Sample Question Paper

Sample Question Paper Sample Question Paper Marks : 70 Time:3 Hour Q.1) Attempt any FIVE of the following. a) List any four applications of DBMS. b) State the four database users. c) Define normalization. Enlist its type. d)

More information

II B.Sc(IT) [ BATCH] IV SEMESTER CORE: RELATIONAL DATABASE MANAGEMENT SYSTEM - 412A Multiple Choice Questions.

II B.Sc(IT) [ BATCH] IV SEMESTER CORE: RELATIONAL DATABASE MANAGEMENT SYSTEM - 412A Multiple Choice Questions. Dr.G.R.Damodaran College of Science (Autonomous, affiliated to the Bharathiar University, recognized by the UGC)Re-accredited at the 'A' Grade Level by the NAAC and ISO 9001:2008 Certified CRISL rated

More information

DATABASE MANAGEMENT SYSTEM

DATABASE MANAGEMENT SYSTEM DATABASE MANAGEMENT SYSTEM For COMPUTER SCIENCE DATABASE MANAGEMENT. SYSTEM SYLLABUS ER model. Relational model: relational algebra, tuple calculus, SQL. Integrity constraints, normal forms. File organization,

More information

Introduction to Computer Science and Business

Introduction to Computer Science and Business Introduction to Computer Science and Business This is the second portion of the Database Design and Programming with SQL course. In this portion, students implement their database design by creating a

More information

Chapter 2. DB2 concepts

Chapter 2. DB2 concepts 4960ch02qxd 10/6/2000 7:20 AM Page 37 DB2 concepts Chapter 2 Structured query language 38 DB2 data structures 40 Enforcing business rules 49 DB2 system structures 52 Application processes and transactions

More information

CS6302 DBMS 2MARK & 16 MARK UNIT II SQL & QUERY ORTIMIZATION 1. Define Aggregate Functions in SQL? Aggregate function are functions that take a collection of values as input and return a single value.

More information

Course Outline Faculty of Computing and Information Technology

Course Outline Faculty of Computing and Information Technology Course Outline Faculty of Computing and Information Technology Title Code Instructor Name Credit Hours Prerequisite Prerequisite Skill/Knowledge/Understanding Category Course Goals Statement of Course

More information

Database Management Systems Paper Solution

Database Management Systems Paper Solution Database Management Systems Paper Solution Following questions have been asked in GATE CS exam. 1. Given the relations employee (name, salary, deptno) and department (deptno, deptname, address) Which of

More information

CS403- Database Management Systems Solved MCQS From Midterm Papers. CS403- Database Management Systems MIDTERM EXAMINATION - Spring 2010

CS403- Database Management Systems Solved MCQS From Midterm Papers. CS403- Database Management Systems MIDTERM EXAMINATION - Spring 2010 CS403- Database Management Systems Solved MCQS From Midterm Papers April 29,2012 MC100401285 Moaaz.pk@gmail.com Mc100401285@gmail.com PSMD01 CS403- Database Management Systems MIDTERM EXAMINATION - Spring

More information

8) A top-to-bottom relationship among the items in a database is established by a

8) A top-to-bottom relationship among the items in a database is established by a MULTIPLE CHOICE QUESTIONS IN DBMS (unit-1 to unit-4) 1) ER model is used in phase a) conceptual database b) schema refinement c) physical refinement d) applications and security 2) The ER model is relevant

More information

Sankalchand Patel College of Engineering, Visnagar B.E. Semester III (CE/IT) Database Management System Question Bank / Assignment

Sankalchand Patel College of Engineering, Visnagar B.E. Semester III (CE/IT) Database Management System Question Bank / Assignment Sankalchand Patel College of Engineering, Visnagar B.E. Semester III (CE/IT) Database Management System Question Bank / Assignment Introductory concepts of DBMS 1. Explain detailed 3-level architecture

More information

Normalization in DBMS

Normalization in DBMS Unit 4: Normalization 4.1. Need of Normalization (Consequences of Bad Design-Insert, Update & Delete Anomalies) 4.2. Normalization 4.2.1. First Normal Form 4.2.2. Second Normal Form 4.2.3. Third Normal

More information

DATABASE MANAGEMENT SYSTEM SHORT QUESTIONS. QUESTION 1: What is database?

DATABASE MANAGEMENT SYSTEM SHORT QUESTIONS. QUESTION 1: What is database? DATABASE MANAGEMENT SYSTEM SHORT QUESTIONS Complete book short Answer Question.. QUESTION 1: What is database? A database is a logically coherent collection of data with some inherent meaning, representing

More information

Schema And Draw The Dependency Diagram

Schema And Draw The Dependency Diagram Given That Information Write The Relational Schema And Draw The Dependency Diagram below, write the relational schema, draw its dependency diagram, and identify all You can assume that any given product

More information

Relational Database Management Systems Oct I. Section-A: 5 X 4 =20 Marks

Relational Database Management Systems Oct I. Section-A: 5 X 4 =20 Marks Relational Database Management Systems Oct 2015 1 I. Section-A: 5 X 4 =20 Marks 1. Data Consistency Files and application programs are created by different programmers over a long period of time, the files

More information

B.C.A DATA BASE MANAGEMENT SYSTEM MODULE SPECIFICATION SHEET. Course Outline

B.C.A DATA BASE MANAGEMENT SYSTEM MODULE SPECIFICATION SHEET. Course Outline B.C.A 2017-18 DATA BASE MANAGEMENT SYSTEM Course Outline MODULE SPECIFICATION SHEET This course introduces the fundamental concepts necessary for designing, using and implementing database systems and

More information

Course Outline and Objectives: Database Programming with SQL

Course Outline and Objectives: Database Programming with SQL Introduction to Computer Science and Business Course Outline and Objectives: Database Programming with SQL This is the second portion of the Database Design and Programming with SQL course. In this portion,

More information

DBMS. Relational Model. Module Title?

DBMS. Relational Model. Module Title? Relational Model Why Study the Relational Model? Most widely used model currently. DB2,, MySQL, Oracle, PostgreSQL, SQLServer, Note: some Legacy systems use older models e.g., IBM s IMS Object-oriented

More information

INTRODUCTION TO DATABASE

INTRODUCTION TO DATABASE 1 INTRODUCTION TO DATABASE DATA: Data is a collection of raw facts and figures and is represented in alphabets, digits and special characters format. It is not significant to a business. Data are atomic

More information

ADVANCED DATABASES ; Spring 2015 Prof. Sang-goo Lee (11:00pm: Mon & Wed: Room ) Advanced DB Copyright by S.-g.

ADVANCED DATABASES ; Spring 2015 Prof. Sang-goo Lee (11:00pm: Mon & Wed: Room ) Advanced DB Copyright by S.-g. 4541.564; Spring 2015 Prof. Sang-goo Lee (11:00pm: Mon & Wed: Room 301-203) ADVANCED DATABASES Copyright by S.-g. Lee Review - 1 General Info. Text Book Database System Concepts, 6 th Ed., Silberschatz,

More information

Assignment Session : July-March

Assignment Session : July-March Faculty Name Class/Section Subject Name Assignment Session : July-March 2018-19 MR.RAMESHWAR BASEDIA B.Com II Year RDBMS Assignment THEORY ASSIGNMENT II (A) Objective Question 1. Software that defines

More information

CS403- Database Management Systems Solved Objective Midterm Papers For Preparation of Midterm Exam

CS403- Database Management Systems Solved Objective Midterm Papers For Preparation of Midterm Exam CS403- Database Management Systems Solved Objective Midterm Papers For Preparation of Midterm Exam Question No: 1 ( Marks: 1 ) - Please choose one Which of the following is NOT a feature of Context DFD?

More information

Review -Chapter 4. Review -Chapter 5

Review -Chapter 4. Review -Chapter 5 Review -Chapter 4 Entity relationship (ER) model Steps for building a formal ERD Uses ER diagrams to represent conceptual database as viewed by the end user Three main components Entities Relationships

More information

DATABASE MANAGEMENT SYSTEMS

DATABASE MANAGEMENT SYSTEMS www..com Code No: N0321/R07 Set No. 1 1. a) What is a Superkey? With an example, describe the difference between a candidate key and the primary key for a given relation? b) With an example, briefly describe

More information

Database Foundations. 6-3 Data Definition Language (DDL) Copyright 2015, Oracle and/or its affiliates. All rights reserved.

Database Foundations. 6-3 Data Definition Language (DDL) Copyright 2015, Oracle and/or its affiliates. All rights reserved. Database Foundations 6-3 Roadmap You are here Introduction to Oracle Application Express Structured Query Language (SQL) Data Definition Language (DDL) Data Manipulation Language (DML) Transaction Control

More information

The Entity-Relationship Model (ER Model) - Part 2

The Entity-Relationship Model (ER Model) - Part 2 Lecture 4 The Entity-Relationship Model (ER Model) - Part 2 By Michael Hahsler Based on slides for CS145 Introduction to Databases (Stanford) Lecture 4 > Section 2 What you will learn about in this section

More information

Oracle Database 10g: Introduction to SQL

Oracle Database 10g: Introduction to SQL ORACLE UNIVERSITY CONTACT US: 00 9714 390 9000 Oracle Database 10g: Introduction to SQL Duration: 5 Days What you will learn This course offers students an introduction to Oracle Database 10g database

More information

Basant Group of Institution

Basant Group of Institution Basant Group of Institution Visual Basic 6.0 Objective Question Q.1 In the relational modes, cardinality is termed as: (A) Number of tuples. (B) Number of attributes. (C) Number of tables. (D) Number of

More information

Distributed Database Systems By Syed Bakhtawar Shah Abid Lecturer in Computer Science

Distributed Database Systems By Syed Bakhtawar Shah Abid Lecturer in Computer Science Distributed Database Systems By Syed Bakhtawar Shah Abid Lecturer in Computer Science 1 Distributed Database Systems Basic concepts and Definitions Data Collection of facts and figures concerning an object

More information

The DBMS accepts requests for data from the application program and instructs the operating system to transfer the appropriate data.

The DBMS accepts requests for data from the application program and instructs the operating system to transfer the appropriate data. Managing Data Data storage tool must provide the following features: Data definition (data structuring) Data entry (to add new data) Data editing (to change existing data) Querying (a means of extracting

More information

RDBMS-Day3. SQL Basic DDL statements DML statements Aggregate functions

RDBMS-Day3. SQL Basic DDL statements DML statements Aggregate functions RDBMS-Day3 SQL Basic DDL statements DML statements Aggregate functions SQL SQL is used to make a request to retrieve data from a Database. The DBMS processes the SQL request, retrieves the requested data

More information

Relational Database Management Systems Mar/Apr I. Section-A: 5 X 4 =20 Marks

Relational Database Management Systems Mar/Apr I. Section-A: 5 X 4 =20 Marks Relational Database Management Systems Mar/Apr 2015 1 I. Section-A: 5 X 4 =20 Marks 1. Database Database: Database is a collection of inter-related data which contains the information of an enterprise.

More information

Vendor: CIW. Exam Code: 1D Exam Name: CIW v5 Database Design Specialist. Version: Demo

Vendor: CIW. Exam Code: 1D Exam Name: CIW v5 Database Design Specialist. Version: Demo Vendor: CIW Exam Code: 1D0-541 Exam Name: CIW v5 Database Design Specialist Version: Demo QUESTION: 1 With regard to databases, what is normalization? A. The process of reducing the cardinality of a relation

More information

Database Technology Introduction. Heiko Paulheim

Database Technology Introduction. Heiko Paulheim Database Technology Introduction Outline The Need for Databases Data Models Relational Databases Database Design Storage Manager Query Processing Transaction Manager Introduction to the Relational Model

More information

Relational Data Structure and Concepts. Structured Query Language (Part 1) The Entity Integrity Rules. Relational Data Structure and Concepts

Relational Data Structure and Concepts. Structured Query Language (Part 1) The Entity Integrity Rules. Relational Data Structure and Concepts Relational Data Structure and Concepts Structured Query Language (Part 1) Two-dimensional tables whose attributes values are atomic. At every row-and-column position within the table, there always exists

More information

Unit I. By Prof.Sushila Aghav MIT

Unit I. By Prof.Sushila Aghav MIT Unit I By Prof.Sushila Aghav MIT Introduction The Need for Databases Data Models Relational Databases Database Design Storage Manager Query Processing Transaction Manager DBMS Applications DBMS contains

More information

A7-R3: INTRODUCTION TO DATABASE MANAGEMENT SYSTEMS

A7-R3: INTRODUCTION TO DATABASE MANAGEMENT SYSTEMS A7-R3: INTRODUCTION TO DATABASE MANAGEMENT SYSTEMS NOTE: 1. There are TWO PARTS in this Module/Paper. PART ONE contains FOUR questions and PART TWO contains FIVE questions. 2. PART ONE is to be answered

More information

D.K.M COLLEGE FOR WOMEN(AUTONOMOUS),VELLORE DATABASE MANAGEMENT SYSTEM QUESTION BANK

D.K.M COLLEGE FOR WOMEN(AUTONOMOUS),VELLORE DATABASE MANAGEMENT SYSTEM QUESTION BANK D.K.M COLLEGE FOR WOMEN(AUTONOMOUS),VELLORE DATABASE MANAGEMENT SYSTEM QUESTION BANK UNIT I SECTION-A 2 MARKS 1. What is meant by DBMs? 2. Who is a DBA? 3. What is a data model?list its types. 4. Define

More information

Relational Database Systems Part 01. Karine Reis Ferreira

Relational Database Systems Part 01. Karine Reis Ferreira Relational Database Systems Part 01 Karine Reis Ferreira karine@dpi.inpe.br Aula da disciplina Computação Aplicada I (CAP 241) 2016 Database System Database: is a collection of related data. represents

More information

CS6312 DATABASE MANAGEMENT SYSTEMS LABORATORY L T P C

CS6312 DATABASE MANAGEMENT SYSTEMS LABORATORY L T P C CS6312 DATABASE MANAGEMENT SYSTEMS LABORATORY L T P C 0 0 3 2 LIST OF EXPERIMENTS: 1. Creation of a database and writing SQL queries to retrieve information from the database. 2. Performing Insertion,

More information

normalization are being violated o Apply the rule of Third Normal Form to resolve a violation in the model

normalization are being violated o Apply the rule of Third Normal Form to resolve a violation in the model Database Design Section1 - Introduction 1-1 Introduction to the Oracle Academy o Give examples of jobs, salaries, and opportunities that are possible by participating in the Academy. o Explain how your

More information

Interview Questions on DBMS and SQL [Compiled by M V Kamal, Associate Professor, CSE Dept]

Interview Questions on DBMS and SQL [Compiled by M V Kamal, Associate Professor, CSE Dept] Interview Questions on DBMS and SQL [Compiled by M V Kamal, Associate Professor, CSE Dept] 1. What is DBMS? A Database Management System (DBMS) is a program that controls creation, maintenance and use

More information

Lab # 4. Data Definition Language (DDL)

Lab # 4. Data Definition Language (DDL) Islamic University of Gaza Faculty of Engineering Department of Computer Engineering ECOM 4113: Lab # 4 Data Definition Language (DDL) Eng. Haneen El-Masry November, 2014 2 Objective To be familiar with

More information

ROEVER ENGINEERING COLLEGE

ROEVER ENGINEERING COLLEGE ROEVER ENGINEERING COLLEGE ELAMBALUR, PERAMBALUR- 621 212 DEPARTMENT OF INFORMATION TECHNOLOGY DATABASE MANAGEMENT SYSTEMS UNIT-1 Questions And Answers----Two Marks 1. Define database management systems?

More information

1. Considering functional dependency, one in which removal from some attributes must affect dependency is called

1. Considering functional dependency, one in which removal from some attributes must affect dependency is called Q.1 Short Questions Marks 1. Considering functional dependency, one in which removal from some attributes must affect dependency is called 01 A. full functional dependency B. partial dependency C. prime

More information

Mahathma Gandhi University

Mahathma Gandhi University Mahathma Gandhi University BSc Computer science III Semester BCS 303 OBJECTIVE TYPE QUESTIONS Choose the correct or best alternative in the following: Q.1 In the relational modes, cardinality is termed

More information

Database Applications (15-415)

Database Applications (15-415) Database Applications (15-415) The Relational Model Lecture 3, January 18, 2015 Mohammad Hammoud Today Last Session: The entity relationship (ER) model Today s Session: ER model (Cont d): conceptual design

More information

The Relational Model. Outline. Why Study the Relational Model? Faloutsos SCS object-relational model

The Relational Model. Outline. Why Study the Relational Model? Faloutsos SCS object-relational model The Relational Model CMU SCS 15-415 C. Faloutsos Lecture #3 R & G, Chap. 3 Outline Introduction Integrity constraints (IC) Enforcing IC Querying Relational Data ER to tables Intro to Views Destroying/altering

More information

Lab # 2. Data Definition Language (DDL) Eng. Alaa O Shama

Lab # 2. Data Definition Language (DDL) Eng. Alaa O Shama The Islamic University of Gaza Faculty of Engineering Department of Computer Engineering ECOM 4113: Database Lab Lab # 2 Data Definition Language (DDL) Eng. Alaa O Shama October, 2015 Objective To be familiar

More information

Brief History of SQL. Relational Database Management System. Popular Databases

Brief History of SQL. Relational Database Management System. Popular Databases Brief History of SQL In 1970, Dr. E.F. Codd published "A Relational Model of Data for Large Shared Data Banks," an article that outlined a model for storing and manipulating data using tables. Shortly

More information

0. Database Systems 1.1 Introduction to DBMS Information is one of the most valuable resources in this information age! How do we effectively and efficiently manage this information? - How does Wal-Mart

More information

1 Overview of Database Management

1 Overview of Database Management 1 Overview of Database Management 1.1 Data, information and knowledge 1.1.1 Data Data is/are the facts of the World. For example, take yourself. You may be 5ft tall, have brown hair and blue eyes. All

More information

Course Logistics & Chapter 1 Introduction

Course Logistics & Chapter 1 Introduction CMSC 461, Database Management Systems Spring 2018 Course Logistics & Chapter 1 Introduction These slides are based on Database System Concepts book th edition, and the 2009 CMSC 461 slides by Dr. Kalpakis

More information

VU Mobile Powered by S NO Group All Rights Reserved S NO Group 2013

VU Mobile Powered by S NO Group All Rights Reserved S NO Group 2013 1 CS403 Final Term Solved MCQs & Papers Mega File (Latest All in One) Question # 1 of 10 ( Start time: 09:32:20 PM ) Total Marks: 1 Each table must have a key. primary (Correct) secondary logical foreign

More information

Database Management Systems

Database Management Systems S.Y. B.Sc. (IT) : Sem. III Database Management Systems Time : 2½ Hrs.] Prelim Question Paper Solution [Marks : 75 Q.1 Attempt the following (any THREE) [15] Q.1 (a) Explain database system and give its

More information

Database Management System Dr. S. Srinath Department of Computer Science & Engineering Indian Institute of Technology, Madras Lecture No.

Database Management System Dr. S. Srinath Department of Computer Science & Engineering Indian Institute of Technology, Madras Lecture No. Database Management System Dr. S. Srinath Department of Computer Science & Engineering Indian Institute of Technology, Madras Lecture No. # 5 Structured Query Language Hello and greetings. In the ongoing

More information

GUJARAT TECHNOLOGICAL UNIVERSITY

GUJARAT TECHNOLOGICAL UNIVERSITY Seat No.: Enrolment No. GUJARAT TECHNOLOGICAL UNIVERSITY BE - SEMESTER III (NEW) - EXAMINATION SUMMER 2017 Subject Code: 21303 Date: 02/06/2017 Subject Name: Database Management Systems Time: 10:30 AM

More information

The Relational Model. Roadmap. Relational Database: Definitions. Why Study the Relational Model? Relational database: a set of relations

The Relational Model. Roadmap. Relational Database: Definitions. Why Study the Relational Model? Relational database: a set of relations The Relational Model CMU SCS 15-415/615 C. Faloutsos A. Pavlo Lecture #3 R & G, Chap. 3 Roadmap Introduction Integrity constraints (IC) Enforcing IC Querying Relational Data ER to tables Intro to Views

More information

Chapter 1 Chapter-1

Chapter 1 Chapter-1 Chapter 1 Chapter-1 Data: Data are the raw facts that can be obtained after some experiments or observations. Raw data is of no use until and unless we process it to find some useful information form it.

More information

IS 263 Database Concepts

IS 263 Database Concepts IS 263 Database Concepts Lecture 4: Normalization Instructor: Henry Kalisti 1 Department of Computer Science and Engineering Limitations of E- R Designs Provides a set of guidelines, does not result in

More information

Mobile MOUSe MTA DATABASE ADMINISTRATOR FUNDAMENTALS ONLINE COURSE OUTLINE

Mobile MOUSe MTA DATABASE ADMINISTRATOR FUNDAMENTALS ONLINE COURSE OUTLINE Mobile MOUSe MTA DATABASE ADMINISTRATOR FUNDAMENTALS ONLINE COURSE OUTLINE COURSE TITLE MTA DATABASE ADMINISTRATOR FUNDAMENTALS COURSE DURATION 10 Hour(s) of Self-Paced Interactive Training COURSE OVERVIEW

More information

DC62 Database management system JUNE 2013

DC62 Database management system JUNE 2013 Q2 (a) Explain the differences between conceptual & external schema. Ans2 a. Page Number 24 of textbook. Q2 (b) Describe the four components of a database system. A database system is composed of four

More information

CT13 DATABASE MANAGEMENT SYSTEMS DEC 2015

CT13 DATABASE MANAGEMENT SYSTEMS DEC 2015 Q.1 a. Explain the role of concurrency control software in DBMS with an example. Answer: Concurrency control software in DBMS ensures that several users trying to update the same data do so in a controlled

More information

Relation Databases. By- Neha Tyagi PGT CS KV 5 Jaipur II Shift Jaipur Region. Based on CBSE Curriculum Class -11. Neha Tyagi, PGT CS II Shift Jaipur

Relation Databases. By- Neha Tyagi PGT CS KV 5 Jaipur II Shift Jaipur Region. Based on CBSE Curriculum Class -11. Neha Tyagi, PGT CS II Shift Jaipur Relation Databases Based on CBSE Curriculum Class -11 By- Neha Tyagi PGT CS KV 5 Jaipur II Shift Jaipur Region Neha Tyagi, PGT CS II Shift Jaipur Introduction A Database System is basically a record keeping

More information

Chapter. Relational Database Concepts COPYRIGHTED MATERIAL

Chapter. Relational Database Concepts COPYRIGHTED MATERIAL Chapter Relational Database Concepts 1 COPYRIGHTED MATERIAL Every organization has data that needs to be collected, managed, and analyzed. A relational database fulfills these needs. Along with the powerful

More information

Database Management System Prof. Partha Pratim Das Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur

Database Management System Prof. Partha Pratim Das Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur Database Management System Prof. Partha Pratim Das Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur Lecture - 19 Relational Database Design (Contd.) Welcome to module

More information

Chapter 11 Database Concepts

Chapter 11 Database Concepts Chapter 11 Database Concepts INTRODUCTION Database is collection of interrelated data and database system is basically a computer based record keeping system. It contains the information about one particular

More information

Database Management System Dr. S. Srinath Department of Computer Science & Engineering Indian Institute of Technology, Madras Lecture No.

Database Management System Dr. S. Srinath Department of Computer Science & Engineering Indian Institute of Technology, Madras Lecture No. Database Management System Dr. S. Srinath Department of Computer Science & Engineering Indian Institute of Technology, Madras Lecture No. # 13 Constraints & Triggers Hello and welcome to another session

More information

COMP Instructor: Dimitris Papadias WWW page:

COMP Instructor: Dimitris Papadias WWW page: COMP 5311 Instructor: Dimitris Papadias WWW page: http://www.cse.ust.hk/~dimitris/5311/5311.html Textbook Database System Concepts, A. Silberschatz, H. Korth, and S. Sudarshan. Reference Database Management

More information

MTA Database Administrator Fundamentals Course

MTA Database Administrator Fundamentals Course MTA Database Administrator Fundamentals Course Session 1 Section A: Database Tables Tables Representing Data with Tables SQL Server Management Studio Section B: Database Relationships Flat File Databases

More information

Chapter 1: Introduction

Chapter 1: Introduction Chapter 1: Introduction Chapter 2: Intro. To the Relational Model Database System Concepts, 6 th Ed. See www.db-book.com for conditions on re-use Database Management System (DBMS) DBMS is Collection of

More information

Relational Databases BORROWED WITH MINOR ADAPTATION FROM PROF. CHRISTOS FALOUTSOS, CMU /615

Relational Databases BORROWED WITH MINOR ADAPTATION FROM PROF. CHRISTOS FALOUTSOS, CMU /615 Relational Databases BORROWED WITH MINOR ADAPTATION FROM PROF. CHRISTOS FALOUTSOS, CMU 15-415/615 Roadmap 3 Introduction Integrity constraints (IC) Enforcing IC Querying Relational Data ER to tables Intro

More information

Databases 1. Daniel POP

Databases 1. Daniel POP Databases 1 Daniel POP Week 4 Agenda The Relational Model 1. Origins and history 2. Key concepts 3. Relational integrity 4. Relational algebra 5. 12+1 Codd rules for a relational DBMSes 7. SQL implementation

More information

UNIT I. Introduction

UNIT I. Introduction UNIT I Introduction Objective To know the need for database system. To study about various data models. To understand the architecture of database system. To introduce Relational database system. Introduction

More information

Introduction. Introduction to Oracle: SQL and PL/SQL

Introduction. Introduction to Oracle: SQL and PL/SQL Introduction Introduction to Oracle: SQL and PL/SQL 1 Objectives After completing this lesson, you should be able to do the following: Discuss the theoretical and physical aspects of a relational database

More information

CMP-3440 Database Systems

CMP-3440 Database Systems CMP-3440 Database Systems Logical Design Lecture 03 zain 1 Database Design Process Application 1 Conceptual requirements Application 1 External Model Application 2 Application 3 Application 4 External

More information

CPS510 Database System Design Primitive SYSTEM STRUCTURE

CPS510 Database System Design Primitive SYSTEM STRUCTURE CPS510 Database System Design Primitive SYSTEM STRUCTURE Naïve Users Application Programmers Sophisticated Users Database Administrator DBA Users Application Interfaces Application Programs Query Data

More information

(ADVANCED) DATABASE SYSTEMS (DATABASE MANAGEMENTS) PROF. DR. HASAN HÜSEYİN BALIK (6 TH WEEK)

(ADVANCED) DATABASE SYSTEMS (DATABASE MANAGEMENTS) PROF. DR. HASAN HÜSEYİN BALIK (6 TH WEEK) (ADVANCED) DATABASE SYSTEMS (DATABASE MANAGEMENTS) PROF. DR. HASAN HÜSEYİN BALIK (6 TH WEEK) 4. OUTLINE 4. Implementation 4.1 Introduction to SQL 4.2 Advanced SQL 4.3 Database Application Development 4.4

More information

- Database: Shared collection of logically related data and a description of it, designed to meet the information needs of an organization.

- Database: Shared collection of logically related data and a description of it, designed to meet the information needs of an organization. أساسيات قواعد بيانات 220) DataBase fundamentals (IS Lecture 1: Ch1 -Principles of DataBases- File-Based Systems: Collection of application programs that perform services for the end users. (e.g: reports).

More information

COMP 3400 Mainframe Administration 1

COMP 3400 Mainframe Administration 1 COMP 3400 Mainframe Administration 1 Christian Grothoff christian@grothoff.org http://grothoff.org/christian/ 1 These slides are based in part on materials provided by IBM s Academic Initiative. 1 Databases

More information

Introduction to Database Management Systems

Introduction to Database Management Systems Relational Data Model Relational Data Model 1 o Relations o Attributes o Tuples o Relations o Primary Keys o Objectives o Comparison to other models o Components o Relation Properties o Kinds of Relations

More information

Relational Model: History

Relational Model: History Relational Model: History Objectives of Relational Model: 1. Promote high degree of data independence 2. Eliminate redundancy, consistency, etc. problems 3. Enable proliferation of non-procedural DML s

More information

Database Applications (15-415)

Database Applications (15-415) Database Applications (15-415) ER to Relational & Relational Algebra Lecture 4, January 20, 2015 Mohammad Hammoud Today Last Session: The relational model Today s Session: ER to relational Relational algebra

More information

1D0-541_formatted. Number: Passing Score: 800 Time Limit: 120 min File Version: 1.

1D0-541_formatted.  Number: Passing Score: 800 Time Limit: 120 min File Version: 1. 1D0-541_formatted Number: 000-000 Passing Score: 800 Time Limit: 120 min File Version: 1.0 http://www.gratisexam.com/ 1D0-541 1D0-541 CIW v5 Database Design Specialist Version 1.7 Exam A QUESTION 1 With

More information

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe CHAPTER 6 Basic SQL Slide 6-2 Chapter 6 Outline SQL Data Definition and Data Types Specifying Constraints in SQL Basic Retrieval Queries in SQL INSERT, DELETE, and UPDATE Statements in SQL Additional Features

More information

CS425 Fall 2016 Boris Glavic Chapter 1: Introduction

CS425 Fall 2016 Boris Glavic Chapter 1: Introduction CS425 Fall 2016 Boris Glavic Chapter 1: Introduction Modified from: Database System Concepts, 6 th Ed. See www.db-book.com for conditions on re-use Textbook: Chapter 1 1.2 Database Management System (DBMS)

More information

Today Learning outcomes LO2

Today Learning outcomes LO2 2015 2016 Phil Smith Today Learning outcomes LO2 On successful completion of this unit you will: 1. Be able to design and implement relational database systems. 2. Requirements. 3. User Interface. I am

More information

Table of Contents. Oracle SQL PL/SQL Training Courses

Table of Contents. Oracle SQL PL/SQL Training Courses Table of Contents Overview... 7 About DBA University, Inc.... 7 Eligibility... 8 Pricing... 8 Course Topics... 8 Relational database design... 8 1.1. Computer Database Concepts... 9 1.2. Relational Database

More information

CS317 File and Database Systems

CS317 File and Database Systems CS317 File and Database Systems http://dilbert.com/strips/comic/1995-10-11/ Lecture 5 More SQL and Intro to Stored Procedures September 24, 2017 Sam Siewert SQL Theory and Standards Completion of SQL in

More information

Prepared by Manash Deb website: 1

Prepared by Manash Deb website:  1 S.Q.L. SQL means Structured Query Language. SQL is a database computer language designed for managing data in relational database management systems (RDBMS). RDBMS technology is based on the concept of

More information

U1. Data Base Management System (DBMS) Unit -1. MCA 203, Data Base Management System

U1. Data Base Management System (DBMS) Unit -1. MCA 203, Data Base Management System Data Base Management System (DBMS) Unit -1 New Delhi-63,By Vaibhav Singhal, Asst. Professor U2.1 1 Data Base Management System Data: Data is the basic raw,fact and figures Ex: a name, a digit, a picture

More information