3. Amity School of Engineering & Technology
SQL
SQL is a query language for relational databases.
Contains:
Data Definition Language to define databases
Data Manipulation Language to manipulate Databases.
SQL is widely accepted and is used by most relational
DBMSs.
4. Amity School of Engineering & Technology
The Importance of SQL
Since SQL is used in almost all relational databases,
once you know SQL you can probably construct and
manipulate databases in all RDBMs.
Knowing SQL makes you a (beginning) ORACLE,
Informix, SyBase, AdaBas, Postgres and so on
programmer!
5. Amity School of Engineering & Technology
Functionalities of SQL
SQL provides
On-line and embedded use.
Precompilation of embedded queries.
Dynamic database definition and alteration.
Maintenance of indexes
View mechanism
Authorization mechanism
Automatic concurrency control
Logging and database recovery
Report formatting
6. Amity School of Engineering & Technology
Tables in SQL
• SQL recognizes
Base Tables
Real tables that physically exist in the
database. There are physically stored records
and possibly physically stored indexes
directly corresponding to the table
• Views
Virtual tables that do not physically exist but look to the user
as if they do
7. Amity School of Engineering & Technology
Languages in SQL
• DDL - Data Defination Languages
Create ,Alter, Drop ,Truncate Commands
• DML - Data Manipulation Language
Update, Insert, Delete Commands
• DQL - Data Query Language
Select
• DCL - Data Control Language
Grant, Revoke
• TCL - Transaction Control Language
Commit, Rollback, Savepoint
8. Amity School of Engineering & Technology
Oracle 7/8
Database
Oracle Complete Solution
Applications
HR
Financials
Manufacturing
…...
Oracle Developer
Oracle Designer
Oracle Discoverer
SQL SQL* PLUS
PL/SQL
Data
Dictionary
Data
Tables
9. Amity School of Engineering & Technology
9
SQL (pronounced "ess-que-el") stands for Structured Query
Language. SQL is used to communicate with a database.
According to ANSI (American National Standards Institute),
it is the standard language for relational database management
systems. SQL statements are used to perform tasks such as
update data on a database, or retrieve data from a database.
Some common relational database management systems that use
SQL are: Oracle, Sybase, Microsoft SQL Server, Access, Ingres,
etc.
Although most database systems use SQL, most of them also
have their own additional proprietary extensions that are usually
only used on their system. However, the standard SQL commands
such as "Select", "Insert", "Update", "Delete", "Create", and
"Drop" can be used to accomplish almost everything that one
needs to do with a database. This tutorial will provide you with
the instruction on the basics of each of these commands as well
as allow you to put them to practice using the SQL Interpreter.
10. Amity School of Engineering & Technology
Drawback of :File Handling :
Data redundancy Data in consistency File format Oracle is platform independent:
Example :DBMSDbase FoxPro
RDBMS
Example :SQL Server Oracle (11.5)Ingress DB2 - IBM Co.Sybase
Maximum 11.5 rules FoxPro
.5 view updation don’t follow1970 - RDBMS - 12 Rules on paper
IBM Corp - Concept of SQLSQL - Recognized standard set
SQL should be the common language for all RDBMS.
History of Oracle :
In 1978 Mr. Edvin founded the Oracle company and its first release was oracle
1.0 which was disaster after it the Oracle corporation has launched Oracle 2.0
in which the database of Oracle was maintained in assembly language.
After it the next measure release was Oracle 3.0 in which the Oracle database
shifted to C-language.
After if the measure release was Oracle 6.0 in which the Oracle kernel was
introduced and the introduction PL/SQL.
10
11. Amity School of Engineering & Technology
After the measure release was Oracle 7, 7.1, 7.2, 7.3.
In Oracle 7.3 :
The oracle has introduction the networking components and
oracle is dived into two parts
Oracle Server release & Oracle client After it the Oracle has
introduced Oracle 8.0 since Oracle 8.0. It has been converted to
OORDBMS.
After it the Sun Micro System and Oracle Corporation tide up
and release a product Oracle 8i (i-internet). (i - Inbuilt Java
support).After it the Oracle 9i has been introduced in which it
has supported WML (Wireless Markup Language or Mobile
Program).Default Java is Given Oracle 9i -
• ORACLE 10g -the meaning of "g" in oracle 10g is a "Grid
computing".
• ORACLE 11g-Oracle Database 11g Release 2 provides the
foundation for IT to successfully deliver more information with
higher quality of service, reduce the risk of change within IT, and
make more efficient use of IT budgets. 11
12. Amity School of Engineering & Technology
SQL : connect system (10 g) other scott /tiger
Command base language
DDL - Data Defination Language
DML - Data Manupliation Language
DCL - Data Control Language
DRL - Data Reterial Language
TCL - Transaction Control Language
DDL :
Create
Alter
Drop
DML :
Insertion
Select
Update
Delete
DRL :
Select
DCL :
Grant
Revoke
TCL :
Commit
12
13. Amity School of Engineering & Technology
• DBMS(data base management systems) and
RDBMS( relational database management system)
the main difference in dbms data is stored in the form
of rows and columns and in the case of rdbms data
stored in the form of tables and data stored in dbms
is temporarly where as in rdbms is permanently eg:
dbms-->sysbase foxpro (some 5-6 rules follow)eg:
rdms-->oracle,sql server
13
14. Amity School of Engineering & Technology
14
> was developed by IBM Corporation, Inc
> set of commands to access data within the
Oracle database.
> Application programs and Oracle tools often
allow users to access the database without
directly using SQL
> but these applications in turn must use SQL
when executing the user's request.
Structured Query Language (SQL)
15. Amity School of Engineering & Technology
15
>> It processes sets of data as groups
rather than as individual units.
>> It provides automatic navigation to the
data.
>> Common Language for All Relational
Databases
Features of SQL
16. Amity School of Engineering & Technology
16
SQL provides commands for a
variety of tasks :
1. Querying data
2. Inserting, updating, and deleting rows
in a table
3. Creating, replacing, altering, and
dropping objects
4. Controlling access to the database and
its objects
5. Guaranteeing database consistency and
integrity
17. Amity School of Engineering & Technology
17
Datatypes in ORACLE 8
1. CHAR
2. VARCHAR/VARCHAR2
3. NUMBER 4. FLOAT
5. DATE 6. CLOB
7. LONG 8. BLOB
9. RAW 10. BFILE
11. LONG RAW 12. MLSLABLE
13. ROWID
20. Amity School of Engineering & Technology
20
VARCHAR/VARCHAR2
• Stores variable-length character
strings
• Allowed length is between 1 and 4000
bytes.
• Usage : varchar2(n)
21. Amity School of Engineering & Technology
21
NUMBER(P, S)
• Stores fixed and floating point numbers
• Allowed precision is up to 38 digits
& Scale ranges from -84 to 127.
• Allowed range of values is
(+/-) 1 x 10^-130 to
(+/-) 9.99..99 x 10^125.
• Usage : number(p,s), number, number(p)
22. Amity School of Engineering & Technology
22
FLOAT
• specifies a floating point number with
decimal precision 38, or binary precision
126
• Can have a decimal point anywhere from the
first to the last digit or can omit the decimal
point altogether.
• A scale value is not applicable
• There is no restriction on the number of
digits that can appear after the decimal
point.
23. Amity School of Engineering & Technology
23
DATE
• For each DATE value the following information is
stored:
century year
month day
hour minute
second
• Stores point-in-time values in a table
• Allowed range of values is between
Jan 1, 4712 B.C. TO Dec 31, 4712 A.D.
• Usage : date.
25. Amity School of Engineering & Technology
25
RAW
• Used for data that is not to be interpreted
(not converted when moving between
different systems) by Oracle. It is used
for storing raw binary data or byte
strings.
• Allowed length is between 1 and 2000
bytes.
• Usage : raw(n)
27. Amity School of Engineering & Technology
27
Restrictions on LONG and
LONG RAW columns
• Only one LONG column per table.
• They cannot be indexed. (Raw can be)
• They cannot have integrity constraints.
• They cannot be used in the WHERE,
GROUP BY, ORDER BY clauses or
DISTINCT operator in SELECT
statements.
28. Amity School of Engineering & Technology
28
• They cannot be referenced by SQL functions.
• They cannot be used in the SELECT list of a
subquery or queries combined by set
operators (UNION, INTERSECT, MINUS).
• They cannot be used in expressions.
• They cannot be referenced when creating
tables with a query (CREATE TABLE...AS
SELECT..) or when inserting into a table with
a query (INSERT INTO..SELECT..).
29. Amity School of Engineering & Technology
29
LOB (Large Objects)
• Internal LOB datatypes, BLOB,
CLOB, NCLOB, and external datatype
BFILE, can store large and
unstructured data such as text,
image, video, and spatial data, up to
four gigabytes in size.
30. Amity School of Engineering & Technology
30
LOB (Large Objects)
• LOBs are similar to LONG and LONG RAW types,
but differ in the following ways:
· Multiple LOBs are allowed in a single row.
· The LOB locator is stored in the table column, either with or
without the actual LOB value; BLOB, NCLOB, and CLOB values
can be stored in separate tablespaces and BFILE data is stored
in an external file on the server.
· When you access a LOB column, it is the locator which is
returned.
· A LOB can be up to four gigabytes in size. BFILE maximum size
is operating system dependent, but cannot exceed four
gigabytes.
· You can select LOB columns and LOB attributes.
31. Amity School of Engineering & Technology
31
BLOB(Binary Large Object)
32. Amity School of Engineering & Technology
32
CLOB(Character Large
Object)
33. Amity School of Engineering & Technology
33
BFILE(Binary File)
• The BFILE datatype enables access
to binary file LOBs that are stored in
filesystems outside the Oracle
database.
• A BFILE column or attribute stores a
BFILE locator, which serves as a
pointer to a binary file on the server's
filesystem.
• The locator maintains the directory
alias and the filename.
35. Amity School of Engineering & Technology
35
SQL Statements
SELECT Data Retrieval Language (DRL)
INSERT
UPDATE Data Manipulation Language (DML)
DELETE
CREATE
ALTER
DROP Data Definition Language (DDL)
RENAME
TRUNCATE
COMMIT
ROLLBACK Transaction Control Language (TCL)
SAVEPOINT
GRANT Data Control Language (DCL)
REVOKE
36. Amity School of Engineering & Technology
36
Database Objects