Escolar Documentos
Profissional Documentos
Cultura Documentos
--------
Overview of DBMS
----------------------
--> DBMS = Database Management System
--> It's a software, which offers to store, maintain and manage the databases.
--> There may be some links (references) between one table and another table.
--> Table: It's a collection of some data in the form of rows and columns.
--> To store this kind of data, we require a software. That software is "DBMS"
software.
====================================
Classification of Software
------------------------------
1) Languages
2) Packages
1) Languages
----------------
--> These are known as "Programming Languages", where the programmer can
development some "Computer programs".
Ex: Pascal, Cobol, C, C++, VB, ASP, VC++, Java, .NET etc.
--> The overall target of any programming language is to develop some "Software
applications".
--> Whenever that application is used by any company / organization, then that can
be called as "Project".
2) Packages
--------------
--> The ready-made software could be called as "Package".
--> This can be directly used by the user.
Classification of Packages
------------------------------
1) Word Processing Packages
2) Presentation and Designing Packages
3) WorkSheet Packages
4) DBMS Packages
5) Accounting Packages
6) Utility Packages
====================================
2) Presentation Packages
------------------------------
--> It offers to create better-looking presentations with multi-media features.
3) WorkSheet Packages
---------------------------
--> Offers to develop work sheets, work books.
4) DBMS Packages
----------------------
--> Contains necessary features to create, store, manipulate and manage the
databases.
Ex: dBase, FoxPro, Visual FoxPro, MS Access, Sybase, DB2, Oracle, MS Sql Server
etc.
5) Accounting Packages
----------------------------
--> Used for all purposes of "Financial Accounting" in any Ltd., Pvt Ltd.
Organizations.
6) Utlity Packages
---------------------
--> These are the useful softwares, which can be used by any type of user with
general purpose.
=====================================
Types of DataBases
-----------------------
1) File DataBases
2) Server DataBases
=====================================
1) Backend
--------------
--> A DBMS software could be called as "Backend" tool.
--> It's major activities are to store, maintain and manage the large scale
databases.
--> To offer the UI for the application, we require another tool known as
"Frontend" tool.
2) Frontend
--------------
--> It's a programming language, which is used to develop the UI.
--> This application can be connected with the backend storage mechanism, as per
necessity.
Ex: VB, VC++, D2K (Developer 2000), .NET, Java
====================================
Database Architectures:
----------------------------
The db architecture specifies type of backend and type of frontend being used.
There are four db architures are available.
A) One-Tier Architecture
B) Two-Tier Architecture
C) Three-Tier Architecture
D) Multi-Tier Architecture
A) One-Tier Architecture:
------------------------------
--> It contains one tool that acts as both backend and frontend.
Ex:
MS Access
Visual FoxPro
etc.
Limitation of One-Tier
--------------------------
--> The tool may not support better backend features / better frontend features.
B) Two-Tier Architecture:
-----------------------------
--> "One tool acts as backend and another tool acts as frontend".
--> It overcomes the limitations of One-Tier architecture.
Ex:
Oracle / Developer 2000
MS Access / VB
MS Access / VC++
FoxPro / VB
FoxPro / VC++
Limitation of Two-Tier:
---------------------------
--> Both these backend and frontend tools must be released by the same company.
C) Three-Tier Architecture
-------------------------------
--> It is an extension of Two-Tier architecture.
--> It contains backend and frontend tools seperately and also contains "Driver"
software.
--> The "driver" software can also be called as "Provider" / "Interface" software.
--> It acts as mediator between backend and frontend.
--> It's small logical software, which can't be opened individually.
--> Using this driver software only, Three-Tier architecture is possible.
--> This driver software may be released by the backend company or frontend
company.
Advantage of Three-Tier:
-----------------------------
--> The backend and frontend tools may be released by two different companies.
Limitation of Three-Tier:
-----------------------------
--> It does't supports "online db communications".
D) Multi-Tier Architecture:
-------------------------------
--> It can also be called as "N-Tier architecture".
--> It is meant for "Online db communications".
--> It is applicable for "WWW" (World Wide Web)
--> It is an extension of Three-Tier.
--> It is implemented by "Web development languages" only. Ex: J2EE, ASP, ASP.NET,
PHP.
====================================
Models of DBMS
-------------------
=====================================
1) Oracle
-----------
--> It acts as backend tool.
2) D2K
---------
--> It acts as frontend tool.
--> It contains internal link with oracle db.
====================================
Oracle
--------
1) SQL (Structured Query Language)
2) PL/SQL (Procedural Language extensions for SQL)
====================================
Versions of Oracle
---------------------
i) Oracle 2.0
--------------
--> Released in 1979.
--> Supports minimum SQL functionality with db storage mechanism.
--> It is the single user dbms.
v) Oracle 6.0
---------------
--> Released in 1988.
--> Contains better security features and backup features.
vi) Oracle 7.0
----------------
--> Released in 1992.
--> Contains new features like "Referential integrity" and "triggers" etc.
--> PL/SQL was introduced.
viii) Oracle 8i
-----------------
--> Released in 1999.
--> Supports "online db transactions" on Internet.
--> The letter "i" stands for "Internet"
viii) Oracle 9i
-----------------
--> Released in 2001.
--> Contains few misclaneous additional features, when compared with 8i.
--> Support of XML documents in db.
x) Oracle 11g
----------------
--> Relased in 2005.
--> The letter "g" stands for "grid-computing" technology.
====================================
====================================
=====================================
1) NUMBER
--------------
--> To hold any type of numerical values.
--> It can hold positive or negetive values also.
--> It can hold integer values / floating point values.
Syn: NUMBER(width)
NUMBER(width,dec)
2) CHAR
----------
--> To store the character type of values.
--> It can hold single / multiple characters also.
--> Use single quotes ( 'xxxx' ) while specifying the string values.
Syn: CHAR(width)
Ex: CHAR(20)
3) VARCHAR / VARCHAR2
------------------------------
--> This is also used to hold string type values.
--> It is preferrable, when compared with CHAR.
--> It overcomes the limitation of CHAR type.
--> Use single quotes ( 'xxxx' ) while specifying the string values.
Syn: VARCHAR2(width)
4) DATE
----------
--> To hold date type of values
--> Use single quotes ( 'xxxx' ) while specifying the date values.
--> Date format: 'dd-mon-yy'
--> Ex Date : '2-apr-08'
Syn: DATE
5) LONG
----------
--> It can hold OLE objects.
--> One table able to contain exactly one LONG column. More than one long columns
are not allowed in the table.
--> Max capacity: 2 GB
Syn: LONG
====================================
=====================================
I) "DDL" Commands:
------------------------
1) CREATE
2) DROP
3) RENAME
4) ALTER
1) INSERT
2) DELETE
3) UPDATE
To make changes / modifications in table data.
4) SELECT
===================================
Command: INSERT(DML)
Note: While speciying the values, copulsory use single quotes for
CHAR / VARCHAR2 / DATE types of values.
Command: SELECT(DML)
Command: SELECT(DML)
F) Renaming a table:
------------------------
====================================
OPERATORS
--------------
1) Arithmatical op
+, -, *, /
2) Relational op
3) Logical op
4) Special op
IN,
NOT IN,
BETWEEN
NOT BETWEEN
LIKE
NOT LIKE
IS NULL
IS NOT NULL
===================================
1) IN
-------
--> This operator contains specific possibilities for a specific column.
--> Whenever the column data is matched with any one of the specified values, then
that data can be received.
2) NOT IN
------------
--> It is exactly reverse to IN operator.
--> It retrieves the data except the given data values.
3) BETWEEN
---------------
--> It displays the data, whenever it is in the specified boundaries (with min and
max values).
4) NOT BETWEEN
--------------------
--> It displays the data, whenever it is not in the specified boundaries (with min
and max values).
5) LIKE
---------
--> It offers to specify a format for the value.
--> It retrieves the data, which is matched with that format.
--> In order to specify the "format", we require to use "format specification
characters".
7) IS NULL
-------------
--> It retrieves only NULL values in the table.
8) IS NOT NULL
------------------
--> It retrieves the data except NULL values in the table.
===================================
Types of deletion
--------------------
a) Un-conditional deletion
b) Conditional deletion
====================================
a) Un-conditional deletion
-------------------------------
--> This includes with deleting the rows, without any condition.
--> This leads to deletion of all the rows in the table.
b) Conditional deletion
---------------------------
--> This is to delete specific no. of rows in the table, based on the given
condition.
==================================
Updating the table data
----------------------------
--> This is used to update one / more row(s) in the table.
Types of updation
--------------------
a) Un-conditional updation
b) Conditional updation
a) Un-Conditional updation
--------------------------------
Syn: UPDATE TableName SET ColName = value;
b) Conditional updation
----------------------------
Syn: UPDATE TableName SET ColName = value WHERE condition;
===================================
===================================
Ex:
====================================
Rule to follow: The given column should be "empty", to change its data type.
Rule to follow: The given column should be "empty", to decrease the column
width. But it may / may not be empty to increase the column width.
===================================
Integrity Constraints
------------------------
--> Integrity constraints are the rules that can be applied to a specific column
in the table.
--> The main purpose of applying these rules is to maintain perfect data in the
tables, without having any mistakes.
--> According to this the db manager creates the tables along with some rules.
--> While inserting / updating the data of the table, db storage mechanism
automatically checks the given condition(s). Whenever the given rules are
satisfied, then only it allows the data to be inserted into the table. Otherwise,
it won't allow the data to the stored.
--> But the rules are various types. In order to implement different rules, Oracle
offers several constraints.
Constraints
--------------
1) NOT NULL
2) UNIQUE
3) PRIMARY KEY
4) CHECK
5) REFERENCES
====================================
1) NOT NULL
---------------
2) UNIQUE
-------------
3) PRIMARY KEY
--------------------
--> Generally, "ID" columns are most suitable for primary key columns.
4) CHECK
-----------
--> Here, the developer gives a condition. The column can contain the data, which
satisfies the given condition.
5) REFERENCES
-------------------
--> It is the most important constraint, using which it is possible to implement
"Referential Integrity".
--> The "Referential Integrity" concept discussed in the next chapter.
====================================
Referential Integrity
------------------------
--> According to this Referential Integrity, two kinds of tables are maintained.
1) Master Table
2) Detailed Table
1) Master Table
------------------
--> It contains the master (main) information.
--> Depending on master table of "detailed table" can be created.
--> In other words, the master table contains the "independent" data.
--> It should be defined along with "primary key" column.
2) Detailed Table
---------------------
--> It contains the "dependent" data, which depends on master table data.
--> It contains a reference to master table.
--> It should be defined along with "reference key" column.
=====================================
=====================================
IMP rules for Implementation of Referential Integrity
-------------------------------------------------------------
--> The master table should contain primary key col and detailed table should
contain reference key col. The reference key can also be called as "foreign key".
--> The names of primary key col and foreign key col generally will be same, but
those may be same or may not be same. That means there is no such restriction to
maintain same name for primary key and reference key columns.
--> One table can be the master table for multiple detailed tables also.
--> The detailed table may contain primary key, and can act as master table for
another detailed table.
--> The foreign key can be created along with "ON DELETE CASCADE" option, if
needed.
--> While inserting the data into master table, any duplicate and NULL values are
not allowed into primary key column.
--> While inserting the data into detailed table, the value to be inserted to into
the reference key column should be already exist in the primary key column at
master table.
--> The data at master table can't be deleted directly, whenever its respective
"child rows" are existed in the detailed table.
--> The datatype and width for primary key and foreign key should be same.
====================================
ON DELETE CASCADE
-------------------------
--> It is the additional option that could be used while the implementation of
detailed table.
--> Whenever the referential integrity has been implemented with this option, the
master table data directly can be deleted even though corresponding child records
are existed in the detailed table. At the time of this kind of deletion, the
respective child records automatically get deleted.
====================================
Constraint Naming:
/
-----------------------
1) System-defined Naming
2) User-defined Naming
====================================
===================================
i) Primary key:
ii) Unique
------------
iv) Check
-----------
Syn: ALTER TABLE TableName ADD CONSTRAINT ConstraintName
CHECK(Condition);
iv) References
-----------------
===================================
Joins
------
--> The process of retrieving the data from two or more tables is called as
"Joins"
Types of Joins:
------------------
1) Simple Join
2) Equi Join
3) Non-Equi Join
4) Outer Join
===================================
1) Simple Join
-----------------
Note: It retrives the correct data and wrong data also. Actually it merges the
each row detailed table with each row of master table.
2) Equi Join
--------------
--> It contains a condition with a relational operator, other than "=" operator.
4) Outer Join
----------------
--> It retrives the data from master table, which not having the respective child
records also.
Ex:
====================================
Functions in Oracle
----------------------
--> Function: A function is just like a small program that performs a certain
process.
--> A function contains a name and it can be called with its name.
====================================
I) Pre-defined Functions
-----------------------------
--> A ready-made function is called as "Pre-defined" / "System-defined" function.
--> Those function can be called by the programmer.
II) User-defined Functions
-------------------------------
--> A function i.e. created by the programmer is called as "User-defined"
function.
====================================
i) Aggregate Functions
--------------------------
--> These are also known as single row functions.
--> Generally, these functions can be called with "DUAL" table.
Note: DUAL is a system-defined table, which contains only one row and one
column. It is used to offer table representation for general purpose values.
-------------------------------------------------------------------
A) Numeric Functions
==============
1) SQRT(N)
2) ABS(N)
3) FLOOR(N)
4) CEIL(N)
5) ROUND(N)
6) ROUND(N,dec)
Returns the rounded floating point value of N, based on the given no. of
decimals.
7) POWER(M,N)
8) SIN(N)
9) COS(N)
10) TAN(N)
11) GREATEST(N1,N2,...)
13) LN(N)
14) LOG(M,N)
===================================
B) String Functions
----------------------
1) UPPER('string')
2) LOWER('string')
3) INITCAP('string')
4) ASCII('chr')
5) CHR(n)
6) CONCAT(Val1,Val2)
7) LENGTH('string')
8) LPAD('string',length)
Adds "spaces" at the left side of given string, to maintain the given string
length.
9) RPAD('string',length)
Adds "spaces" at the right side of given string, to maintain the given
string length.
10) LTRIM('string')
Removes the extra "spaces" at left side of given string.
11) RTRIM('string')
12) TRIM('string')
13) INSTR('string','chr')
Searches the string for the given character. If the given character is found
in the string, then it returns its corresponding character index. If it is not
found then it returns 0. The character index starts from 1.
14) INSTR('string','chr',startindex)
Same as above, but searching starts from given starting index and findouts
the index of 'n'th occurance.
17) REVERSE('string')
18) SUBSTR('string',startindex)
Returns the part of the string, starting from specific character upto end of
the string. (including the specific character).
19) SUBSTR('string',startindex,length)
Same as above, but returns the sub string with specific string length only.
====================================
C) Convertion Functions
-----------------------------
1) TO_CHAR(N)
2) TO_NUMBER('string')
Converts the given into oracle supporting date, based on the given format.
===================================
D) Date Functions
----------------------
1) SYSDATE
2) TO_CHAR('Date','Format')
DD
MM
YY
DAY
MON
MONTH
YEAR
HH
MI
SS
AM
W
DY
3) LAST_DAY('Date')
4) ADD_MONTHS('Date',N)
==================================
--> The group functions are meant for performing logics on the entire of column of
a table.
--> The aggregate functions take the each value in the column individually and
gets called once per each value. But whereas the group functions treats all the
column values as a group and gets called only once per entire column.
1) SUM()
2) AVG()
3) MAX()
4) MIN()
5) COUNT()
1) SUM(ColName)
2) AVG(ColName)
3) MAX(ColName)
4) MIN(ColName)
5) COUNT(*)
6) COUNT(ColName)
Returns the total no. of values in the specified column. (Except NULL
values)
=====================================
Clauses
---------
--> A clause is a part of the "query", which can produce some meaning.
--> It can produce some meaning in the query, but not the complete meaning.
--> For example, WHERE is a clause that can produce a "conditional" expression.
But it can't executed individually.
1) WHERE
------------
--> This is the most frequently used clause in SQL, which offers to provide a
condition in the query.
2) DISTINCT
---------------
3) ORDER BY
---------------
--> That means it sortouts the table data in ascending / descending order.
--> In addition to this, it applies a GROUP FUNCTION on another column in the same
table.
In the above example, the list of all designations and respective total
amount of salaries will be displayed.
5) HAVING
-------------
--> It is used to produce a condition, based on the group function result used in
the GROUP BY statement.
===================================
====================================
Sub Queries
--------------
--> But in a single query, another query can be integrated as a part. That
integrated query is called as "Sub Query".
--> Here, two kinds of queries are there in the "Sub Queries".
1) Outer Query
2) Inner Query
Syn: SELECT * FROM TableName WHERE ColName = (SELECT ColName FROM TableName);
Ex:
--> SELECT * FROM EMP WHERE SAL = (SELECT MAX(SAL) FROM EMP);
--> SELECT NAME FROM EMP WHERE SAL = (SELECT MIN(SAL) FROM EMP);
--> SELECT * FROM EMP WHERE SAL < (SELECT AVG(SAL) FROM EMP);
--> SELECT MAX(SAL) FROM EMP WHERE SAL < (SELECT MAX(SAL) FROM EMP);
--> SELECT MIN(SAL) FROM EMP WHERE SAL > (SELECT MIN(SAL) FROM EMP);
--> SELECT * FROM EMP WHERE SAL=(SELECT MIN(SAL) FROM EMP WHERE SAL > (SELECT
MIN(SAL) FROM EMP));
====================================
Set Operators
----------------
--> The set operators are meant for retrieving the data from more than one table
at-a-time.
--> In other words, one query can retrieve the data from two or more tables.
--> Ofcourse, the "Joins" are also available with similar purpose. But the "set
operators" and "joins" functionality is different in this case.
--> Joins depends on the concept of "Referential integrity" but "Set operators"
doesn't need "Referential integrity".
--> Join operation displays the records from table1 and table2 simultaneously. But
set operator displays the records from table1 and table2 one after another.
====================================
1) UNION ALL
-----------------
--> It is just like UNION concept in maths.
--> It retrieves the data from table1 first and then table2.
2) UNION
-----------
--> It is almost all similar to UNION ALL command.
--> It also retrieves the data from table1 first and then table2.
Note: The main difference between UNION ALL and UNION is, "UNION" command avoids
to print duplicate records if any.
3) INTERSECT
----------------
--> It is same as "Intersection" in maths.
--> This command retrieves only common (duplicate) records among the two tables.
4) MINUS
-----------
--> It is reverse to INTERSECT.
--> It retrieves the records from table1 which doesn't exist in table2.
Views
-------
=====================================
--> The TCL commands are used to control the DML transactions.
1) ROLLBACK
2) COMMIT
3) SAVEPOINT