Loading…

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

Like this presentation? Why not share!

2 rdbms

on

  • 1,024 views

suresh presentation on RDBMS concepts

suresh presentation on RDBMS concepts

Statistics

Views

Total Views
1,024
Views on SlideShare
1,024
Embed Views
0

Actions

Likes
0
Downloads
42
Comments
1

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
  • thanks
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • Presenter: Kingshuk Chakravarti
  • Presenter: Kingshuk Chakravarti
  • Presenter: Kingshuk Chakravarti
  • Presenter: Kingshuk Chakravarti
  • Presenter: Kingshuk Chakravarti
  • Presenter: Kingshuk Chakravarti
  • Presenter: Kingshuk Chakravarti
  • Presenter: Kingshuk Chakravarti
  • Presenter: Kingshuk Chakravarti
  • Presenter: Kingshuk Chakravarti
  • Presenter: Kingshuk Chakravarti
  • Presenter: Kingshuk Chakravarti
  • Presenter: Kingshuk Chakravarti
  • Presenter: Kingshuk Chakravarti
  • Presenter: Kingshuk Chakravarti
  • Presenter: Kingshuk Chakravarti
  • Presenter: Kingshuk Chakravarti
  • Presenter: Kingshuk Chakravarti
  • Presenter: Kingshuk Chakravarti
  • Presenter: Kingshuk Chakravarti
  • Presenter: Kingshuk Chakravarti
  • Presenter: Kingshuk Chakravarti
  • Presenter: Kingshuk Chakravarti The code on this slide will produce identical output to the code on the previous slide. HAVING must be used with aggregate expressions. Any fields in the field list not using aggregate expressions must be in the GROUP BY clause.
  • Presenter: Kingshuk Chakravarti
  • Presenter: Kingshuk Chakravarti

2   rdbms 2 rdbms Presentation Transcript

  • Date: 17 th December, 2009 Location: Kolkata Basic RDBMS Concepts
  • Index
    • Introduction to RDBMS
    • Table Keys
    • Normalization
    • SQL
    • Transaction
  • Introduction to RDBMS
    • Relational Database Management System is the most preferred system for Storing and managing information.
    • Data is stored in the form of tables and the relationship among the data is also stored in the form of tables.
    • Must adhere to Codd’s rules
  • Architecture
  • Codd’s Rules Rule 1 – Information Rule :- All information is explicitly and logically represented in exactly one way – by data values in tables. If an item of data does not reside somewhere in a table in the database, then it does not exist. Rule 2 – Rule of Guaranteed Access :- Every item of data must be logically addressable by resorting to a combination of table name, primary key value and a column name.
  • Codd’s Rules Rule 3 – The Systematic Treatment of Null Values :- The RDBMS handles records that have unknown or inapplicable values in a pre-defined fashion. The RDBMS distinguishes between zeros, blanks and nulls in the records hand handles such values in a consistent manner that produces correct answers, comparisons and calculations. Through the set of rules for handling nulls, users can distinguish results of the queries that involve nulls, zeros and blanks. Rule 4 – The Database Description Rule :- The description of a database and in its contents are database tables and therefore can be queried on-line via the data manipulation language. There must be a Data Dictionary within the RDBMS that is constructed of tables and/or views that can be examined using SQL.
  • Codd’s Rules
    • Rule 5 – The Comprehensive Sub-language rule :-
    • A RDBMS may support several languages. But at least one of them should allow user to do all of the following:
    • Define tables and views
    • Query and update the data
    • Set integrity constraints
    • Set authorizations
    • Define transactions.
    • RDBMS must be completely manageable through its own dialect of SQL.
  • Codd’s Rules Rule 6 – The View Updating Rule :- All views that can be updated in theory, can also be updated by the system. Data consistency is ensured since the changes made in the view are transmitted to the base table and vice-versa. . Rule 7 – High Level Insert, Update and Delete Rule The RDBMS supports insertions, updation and deletion at a table level. This means that data can be retrieved from a relational database in sets constructed of data from multiple rows and/or multiple tables. This rule states that insert, update, and delete operations should be supported for any retrievable set rather than just for a single row in a single table.
  • Codd’s Rules Rule 8 – The Physical Independence Rule :- The execution of adhoc requests and application programs is not affected by changes in the physical data access and storage methods. Database administrators can make changes to the physical access and storage method which improve performance and do not require changes in the application programs or requests. Here the user specified what he wants an need not worry about how the data is obtained. Rule 9 – Logical Data Interdependence Rule:- Logical changes in tables and views such adding/deleting columns or changing fields lengths need not necessitate modifications in the programs or in the format of adhoc requests. The database can change and grow to reflect changes in reality without requiring the user intervention or changes in the applications. For example, adding attribute or column to the base table should not disrupt the programs or the interactive command that have no use for the new attribute.
  • Codd’s Rules
    • Rule 10 – Integrity Independence Rule :-
    • Integrity constraints must be specified separately from application programs and stored in the catalog. It must be possible to change such constraints as and when appropriate without unnecessarily affecting existing applications.
    • The following Integrity rules(Constraints) should apply to every RDBMS :-
      • No component of a primary key can have missing values – this is the basic rule of Entity Integrity.
      • For each distinct foreign key value there must exist a matching primary key value in the same domain. Conformation to this rule ensures what is called Referential integrity .
  • Codd’s Rules Rule 11 – Distribution Rule :- Application programs and adhoc requests are not affected by change in the distribution of physical data. Improved systems  reliability since application programs will work even if the programs and data are moved in different sites. Rule 12 – No Subversion Rule :- If the RDBMS has a language that accesses the information of a record at a time, this language should not be used to bypass the integrity constraints.
  • Index
    • Introduction to RDBMS
    • Table Keys
    • Normalization
    • SQL
    • Transaction
  • Table Keys Unique Key : Contains one or more columns with non-repeating values in a table . Might consider null values. Primary Key : Contains one/more columns with non-repeating values in a table. Does not consider null values. Composite Key : A key formed by combining at least two or more columns is called composite key .
  • Table Keys Foreign Key : A foreign key is a field in a relational table that matches the primary key column of another table. The foreign key can be used to cross-reference tables.
  • Index
    • Introduction to RDBMS
    • Table Keys
    • Normalization
    • SQL
    • Transaction
  • Normalization Systematic way of ensuring that a database structure is suitable for general-purpose querying and free of certain undesirable characteristics—insertion, update, and deletion anomalies—that could lead to a loss of data integrity .
    • First Normal Form(1NF)
    • Second Normal Form(2NF)
    • Third Normal Form(3NF)
    • Byce-Code Normal Form(BCNF)
    • Forth Normal Form(4NF)
    • Fifth Normal Form(5NF)
    • Sixth Normal Form(6NF)
  • First Normal Form ( 1NF) An entity is in First Normal Form (1NF) when all tables are two-dimensional with no repeating groups.
    • Eliminate duplicative columns from the same table.
    • Create separate tables for each group of related data and identify each row with a unique column or set of columns (the primary key).
    • The only attribute values permitted by 1 NF are single atomic (or indivisible) values. If there is no value present for the column, then it should be denoted as null.
  • Second Normal Form ( 2NF) A row is in second normal form if, and only if, it is in first normal form and every non-key attribute is fully dependent on the key.
  • Third Normal Form ( 3NF) A row is in third normal form if, and only if, it is in second normal form and every non-key attribute is non-transitively dependent on the primary key.
  • Fourth Normal Form ( 4NF) An entity is in fourth normal form if, and only if, it is in third normal form and no entity can have more than a single one-to-many relationship within an entity if the one-to-many attributes are independent of each other
  • Fifth Normal Form ( 5NF) A table is in fifth normal form (5NF) or Project-Join Normal Form (PJNF) if it is in 4NF and it cannot have a lossless decomposition into any number of smaller tables.
  • Index
    • Introduction to RDBMS
    • Table Keys
    • Normalization
    • SQL
    • Transaction
  • Structured Query Language(SQL)
    • Common language to
    • almost any RDBMS.
    • Used to create tables,
    • inserting and updating records, deleting records,creating view,
    • Maintaining database tables etc.
  • Data Definition Language(DDL):- create table,view etc. Data Query Language(DQL):- selection of records Data Manipulation Language(DML):- Updation, deletion of records Features of SQL:-
  • Data Definition Statement – CREATE TABLE create table employee_history ( employee_id number(6) not null, salary number(8,2), hire_date date default sysdate, termination_date date, termination_desc varchar2(4000), constraint emphistory_pk primary key (employee_id, hire_date) ); Create table with Primary key:-
  • Data Definition Statement – CREATE TABLE create table employee_master ( employee_id number(6) not null, empname varchar2(50) not null, age number(2) not null , sex varchar2(1) not null ) ; Alter table employee_master Add constraint pk_emp Primary key(employee_id) ; Create table and then add Primary key:-
  • Data Definition Statement – CREATE TABLE create  table another_dept  as  select  *   from  employee; Create table Selecting from other table :-
  • Data Manipulation Statement – Insert Records into table INSERT INTO tbl1(col1,col2,col3,col4) VALUES(val1,val2,val3,val4), (val11,val12,val13,val14); Inserting Multiple Records:- INSERT into california_authors (au_id, au_lname, au_fname) SELECT au_id, au_lname, au_fname FROM authors WHERE State = 'CA' Inserting using SELECT :-
  • SELECTION OF RECORDS
  • SELECT COL1,COL2,..,.., FROM tbl1……… WHERE …………….. AND …………….. OR ……………… GROUP BY ……….. HAVING ……. The Red syntaxes are compulsory. Blue are used as and when required. Basic Syntax :-
  • Select * from tbl1 Where col1 = “ABC” And ………… Contains selection criteria Type of Selection:- Select all Records :- SELECT * FROM TABL1 ; SELECT COL1 , COL2 FROM TABL1; Selecting Few records :-
  • Selection of few columns:- Select emp_code,emp_name from emp_mast ; Renaming Columns:- Select emp_code, name=emp_name from emp_mast; Arithmetic Calculations in Selection:- Select basic, da=1.2*basic from salary_mast; SELECT…continued
  • OPERATORS
    • AND
    • OR
    • IN
    • BETWEEN
    • NOT IN
    • DISTINCT
    • LIKE
  • AND : Used to incorporate more than one selection criteria Select emp_code, city_code FROM emp_dtl WHERE city_code=‘C01’ AND desig_code=‘A03’; OR:- SELECT emp_code FROM emp_dtl WHERE city_code=‘C01’ OR city_code=‘C02’;
  • IN : Used to put more than one value for a column SELECT emp_code FROM emp_dtl WHERE city_code in (‘C01’,’C02’); BETWEEN: Used to specify a range in selection criteria SELECT emp_code, dep_code from emp_joining WHERE doj BETWEEN ‘1/1/2009’ AND 31/12/2009’;
  • NOT IN: Used to exclude some criteria from selection Select emp_code from emp_dtl where city_code not in (‘C01’,’C02’); DISTINCT: To select single occurrence of some value in columns select distinct city_code from emp_dtl; LIKE: Used for pattern matching select empname from emp_mast where name like ‘S%’;
  • AGGREGATE FUNCTIONS
    • SUM
    • AVG
    • MAX
    • MIN
    • COUNT
    • Group By clause is used with aggregate functions
    • Where selection from more than one columns are made
  • SUM: Totals numeric,float and money values SELECT SUM(bonus) FROM performance WHERE year=2008; SELECT emp_code, sum(bonus) from performance WHERE year=2008 GROUP BY emp_code;
  • Having Clause Syntax/Example SELECT material , Totamt = sum(storage_amt) from store_dtl GROUP BY material HAVING SUM( storage_amt ) > 9000 .
    • Basic form ... HAVING condition.
    • Used in a SELECT command, it allows you to use a logical condition for the groups in a GROUP BY clause.
  • AVG: Finds out average value in a column of selected records select avg(bonus) from performance where emp_code=‘E01’; select month, year, bonus=avg(bonus) from performance group by month,year;
  • MAX and MIN: Max returns maximum of the values in a column of selected records and MIN returns the minimum select max(bonus) from performance; select emp_code, min(bonus) from performance where year=2008 group by emp_code; COUNT:- Count no of values in table or column. select emp_code, count(*) from performance where year=2008 Group by emp_code;
  • Select count(name) from emp_mast Where emp_name like ‘S%’; Select count(*) from emp_dtl; Select count(emp_code) from emp_dtl Where city_code=‘C01’;
  • Sorting records Sorting By Primary Key : To sort the selection set in ascending order by the primary key, use the following: SELECT <lines> * ... ORDER BY PRIMARY KEY. This sorting method is only possible if asterisk (*) in the SELECT clause is used to select all columns. Sorting By Any Number of Columns SELECT ... ... ORDER BY <s1> [ASCENDING|DESCENDING] <s2> [ASCENDING|DESCENDING] ...
    • Used to retrieve records from more than one table using matching conditions.
    • Equi join(Inner join)
    • Self Join
    • Outer join(left and right join)
    Using JOINS
  • Join Between Two Tables EQUI JOIN SELECT a.ename , b.designation, b.salary from emp_mast a , emp_dept b where a.emp_code = b.emp_code ;
  • Between more than two tables EQUI JOIN…continued SELECT a.ename , b.dept_name, c.designation, c.salary from emp_mast a , dept_mast b, emp_dept c where c.emp_code = a.emp_code and c.dept_code = b.dept_code;
  • SELF JOIN Sometimes the records to be selected remains in a single table,but it cannot be viewed by simple selection.For that, a record need to be broken into more than one fragments.In that case, a single table is hypothetically broken into more than one fragments, and each fragment is treated as a single table and joins are established between them. Need information on Employee Name and Manager Name
  • SELF JOIN SELECT employee = w.ename , manager = m.ename FROM emp_manager w, emp_manager m WHERE w.manager_id = m.empno;
  • Outer Join Left Outer Join
  • Outer Join Right Outer Join
  • Outer Join Full Outer Join
  • SUBQUERY Query involving subqueries contain more than one query where output of one query becomes input of other query. select * from emp_dtl where desig_code in ( select desig_code from salary_mast where total>10000);
    • Updating a table can be as following:-
    • Update the table with input values from outside.
    • Update a table by its own.
    • 3. Update a table by another table.
    Updating Table Entries
  • Explicit Update :- UPDATE table tblname SET colname = value, …………… WHERE search conditions; Example:- UPDATE emp_dtl SET qual = ‘HIGHER SECONDARY’ WHERE emp_code = ‘E17’;
  • Implicit Update:- Update salary_mast Set basic=1.2*basic, special=1.2 * special, conveyance=1.2 * conveyance, medical=1.2* medical, total=1.2* total WHERE desig_code in (‘A04’,’A05’);
  • Updation with Reference to Other Table :- UPDATE emp_sal a FROM desig_mast b SET salary=b.total WHERE a.desig_code=b.desig_code; UPDATE emp_sal a FROM performance b SET performance=b.bonus WHERE a.emp_code=b.emp_code AND a.month_code=b.month_code AND a.year_code=b.year_code AND a.month_code=12 AND a.year_code=2000
  • Deletion of Records :- DELETE FROM tablename WHERE search_conditions; Example:- DELETE FROM performance WHERE emp_code=‘E01’ AND month_code=12 AND year_code=2000;
  • Index
    • Introduction to RDBMS
    • Table Keys
    • Normalization
    • SQL
    • Transaction
  • Transactions A database transaction is a sequence of SQL statements that the database system treats as a unit. A transaction brings the database from one consistent state to another.
  • Transactions
    • A transaction is always completed by a COMMIT or ROLLBACK.
    • When a transaction is successfully concluded with a COMMIT, all of the data changes are retained.
    • If a transaction is ended with a ROLLBACK or terminated in any other way, the database system reverses all the data changes made during the transaction.
  • Thank You