Sei sulla pagina 1di 21

RDBMSPatel

Mehul (BCA-201) Class: SYBCA Unit/21


-I

Faculty Name : Mehul Patel


Class : SYBCA
Subject : RDBMS (BCA-201)
Topics : Unit I

> WHAT IS DATABASE


A database can be defined as a collection of coherent, meaningful data. The phrase
collection of coherent data needs to have a point of reference to be understood. A
simple point of reference would be the example of a postal address, this would
generally contain:
o A building name,
o A flat number in the building
o A road name
o An area name
o A state name
o A pincode
o A country name (This is optional, but necessary if the letter is destined to a
foreign country)

To project on this further, multiple addresses kept together in one place, such as an
address book, could be termed as a coherent collection of data. Thus the address book
is a database and the postal addresses in the book, is the data that fills the database .

> WHAT IS DATABASE MANAGEMENT SYSTEMS (DBMS)


To be able to successfully design and maintain databases we have to do the following:
1.Identify which part of the world' s data is of interest to us
2.Identify what specific objects in that part of the world's data are of interest
0.Identify a relationship between the objects

Hence, the objects, there attributes and the relationship between them (that are of
interest to us) are stored in the database that is designed, built and populated with
data for a specific purpose.

Software houses took up the cha1lenge of designing a system that would help in
managing data in such a database. These systems were called Database Management
Systems (DBMS). DBMS is a system that allows inserting, updating, deleting and
processing of data. Some of the DBMS developed by software houses were Oracle,
Ingress, Sybase, Dbase 3+, Fox base, FoxPro, MS Access, Database, Data flex,
Advanced Revelation, and so on.

> ADVANTAGES OF DBMS:-

EMP_NO
NAME
SKILL
POSITION_NO
123456
321
Mehul
RDBMS WAITER
Patel
(BCA-201) Class: SYBCA Unit/21
-I
WAITER
123457
323
JON
BUSBOY
BUSBOY
324
123458
BELLBOY
DON
The amount of data redundancy in stored data can325
1. BELLBOY be reduced.
HOSTESS
2.123459
No more data inconsistencies.
PAM
3. Stored data can be shared by a single or multiple users .
4.HOSTESS
Standards can be set and followed .
5. Data integrity can be maintained. Data integrity refers to the problem of
ensuring that database contains only accurate data.
6. Security of data can be simply implemented.
7. Data independence can be achieved, i.e. data and programs that manipulate the
data are two different entities.

۞ DISADVANTAGE OF DBMS:-

1.Cost of Hardware / Software and Migration.


2.Problems associated with centralization.
3. Complexity of Backup and Recovery.

۞ Relational Data Model

The relational data model has emerged from the research, development, test and
trial stages as a commercial product. Software systems using this approach are
available for all size of computer system. This model has the advantage of being
simple in principle; users can express their queries in a powerful query language.

In this model, the relation is the only construct required to represent the
association among the attributes of an entity as well as the relationship among
different entities. One of the main reason for introducing this model was to increase
the productivity of the application programmer by eliminating the need to change
application programs when a change is made to the database. Users need not know
the exact physical structure to use the database and are protected from any
changes made to these structures. They are however, still required to know the
data has been partitioned into the various relations.

EMPLOYEE POSITION

The relation is the only data structure used in the relational data model to represent
both entities and the relationship between them. A relation may be visualized as a
named table. Above figure shows two relations employee and position using tabular
structure. Each column of the table corresponds to an attribute of the relation and
is named.
RDBMSPatel
Mehul (BCA-201) Class: SYBCA Unit/21
-I

> WHAT IS A RELATIONAL DATABASE MANAGEMENT SYSTEM


(RDBMS)

A Relational Database Management System (RDBMS) is a database management


system (DBMS) that is based on the relational model as introduced by Dr. Edgar F.
Codd. Strictly speaking it should also satisfy Codd's 12 rules, but in practice there is no
DBMS that satisfies all these rules. In fact, most successful DBMS that are considered
to be relational violate the relational model in several important ways, including the
Structured Query Language (SQL). However, most database practitioners and
researchers use the term in a loose way such that most databases that support SQL
are included.

Relational Database Management Systems (RDBMS) stores data in the form of related
tables. RDBMS are powerful because they require few assumptions about how data is
related or how it will be extracted from the database. As a result, the same database
can be viewed in many different ways.

An important feature of relational systems is that a single database can be spread


across several tables. This differs from flat-file databases, in which each database is
self-contained in a single table.

Today, popular commercial RDBMS for large databases include Oracle, Microsoft SQL
Server, Sybase SQL Server, and IBM's DB2. The most commonly used free RDBMS are
MySQL, PostgreSQL.

> Dr. E. F. Codd's Rules for RDBMS


Dr. E. F. Codd is an IBM researcher who first developed the relational data model in
1970. In 1985, Dr. Codd published a list of 12 rules that define an ideal relational
database and has provided a guideline for the design of all relational database
systems.

Today, the rules are not talked about as much but remain a goal for relational
database design .

Rule 1: The Information Rule


All data should be presented in table form
Rule 2: Guaranteed Access Rule
All data should be accessible without ambiguity. This can be accomplished
through a combination of the table name, primary key, and column name
Rule 3: Systematic Treatment of Null Values
A field should be allowed to remain empty. This involves the support of a null
value, which is distinct from an empty string or a number with a value of zero.
Of course, this can't apply to primary keys. In addition, most database
implementations support the concept of a not-null field constraint that prevents
null values in a specific table column
RDBMS
Mehul Patel
(BCA-201) Class: SYBCA Unit/21
-I

Rule 4: Dynamic On-Line Catalog based on the Relational Model


A relational database must provide access to its structure through the same
tools that are used to access the data. This is usually accomplished by storing
the structure definition within special system tables
Rule 5: Comprehensive Data Sublanguage Rule
The database must support at least one clearly defined language that includes
functionality for data definition, data manipulation, data integrity, and database
transaction control. All commercial relational databases use forms of standard
SQL (i.e. Structured Query Language) as their supported comprehensive
language
Rule 6: View Updating Rule
Data can be presented in different logical combinations called views. Each view
should support the same full range of data manipulation that has direct access
to a table available. In practice, providing update and delete access to logical
views is difficult and is not fully supported by any current database
Rule 7: High-Level Insert, Update, and Delete
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.
Rule 8: Physical Data Independence
The user is isolated from the physical method of storing and retrieving
information from the database. Changes can be made to the underlying
architecture (hardware, disk storage methods) without affecting how the user
accesses it.
Rule 9: Logical Data Independence
How data is viewed should not be changed when the logical structure (table's
structure) of the database changes. This rule is particularly difficult to satisfy.
Most databases rely on strong ties between the data viewed and the actual
structure of the underlying tables.

Rule 10: Integrity Independence


The database language (like SQL) should support constraints on user input that
maintain database integrity. This rule is not fully implemented by most major
vendors. At a minimum, all databases do preserve two constraints through SQL.
No component of a primary key can have a null value. If a foreign key is defined
in one table, any value in it must exist as a primary key in another table .
Rule 11: Distribution Independence
A user should be totally unaware of whether or not the database is distributed
(whether parts of the database exist in multiple locations). A variety reasons
make this rule difficult to implement .
Rule 12: Non subversion Rule
There should be no way to modify the database structure other than through the
multiple row database language (like SQL). Most databases today support
administrative tools that allow some direct manipulation of the data structure .
RDBMS
Mehul Patel
(BCA-201) Class: SYBCA Unit/21
-I

> DBMS V/S RDBMS


DBMS RDBMS
In DBMS relationship between two tables In RDBMS relationship between two tables
or files are maintained programmatically or files can
be specified at the time of table creation
DBMS does not support Client/Server Most of the RDBMS supports Client/Server
Architecture Architecture
DBMS does not supports Distributed Most of the RDBMS supports Distributed
databases databases
In DBMS there is no security of data In RDBMS there are multiple levels of
security
1.Logging in at O/S level
2. Command level
(i.e. at RDBMS level)
3. Object Level
Each table is given an extension in DBMS Many tables are grouped in one database
in RDBMS
DBMS may satisfy less than 7 to 8 rules of RDBMS usually satisfy more than 7 to 8
Dr. E F Codd rules of Dr. E F Codd

> Naming Conventions


DBMS RDBMS
Field Column, Attributes
Record Row, Tuple, Entity
File Table, Relation, Entity Class

Many of the databases will be small, with one or two tables. But as the databases
become braver, tackling, bigger projects, it will be noticed that the design of the tables
is proving problematic. The SQL written starts to become unmanageable and data
anomalies start to creep in. This means it is time to learn about database
normalization, or the optimization of tables.
RDBMS
Mehul Patel
(BCA-201) Class: SYBCA Unit/21
-I

> NORMALIZATION

Normalization is a process that helps analysts or database designers to design table


structures for an application. The focus of normalization is to attempt to reduce
redundant table data to the very minimum.
Through the normalization process, the collection of data in a single table is replaced,
by the same data being distributed over multiple tables with a specific relationship
being setup between the tables. By this process RDBMS schema designers try their
best to reduce table data to the very minimum.

Normalization is carried out for the following reasons:


1.To structure the data between tables so that data maintenance is simplified
2.To allow data retrieval at optimal speed
3.To simplify data maintenance through updates, inserts and deletes
4.To reduce the need to restructure tables as new application requirements arise
5.To improve the quality of design for an application by rationalization of table data

Normalization is a technique that:


1. Decomposes data into two-dimensional tables
2. Eliminates any relationships in which table data does fully depend upon the primary
key of a record
3. Eliminates any relationship that contains transitive dependencies

A description of the three forms of Normalization is as mentioned below.

> First Normal Form


When a table is decomposed into two-dimensional tables with all repeating groups of
data eliminated, the table data is said to be in its first normal form.
The repetitive portion of data belonging to the record is termed as repeating groups.
To understand the application of normalization to table data the following table
structure will be taken as an example :

Table: EmpPro
Field Key Type
Project Number --
Project Name --
Employee Number -- 1-n
Employee Name -- 1-n
Rate Category -- 1-n
Hurly Rate -- 1-n

1-n indicates that there are many occurrences of this field - it is a repeating group.

Data held in the above table structure


RDBMS
Mehul Patel
(BCA-201) Class: SYBCA Unit/21
-I

Project Project Employee Employee Rate Hourly


Number Name Number Name Category Rate
P001 My SQL & Linux E001 Sharanam A 7000
P001 My SL & Linux E002 Vaishali B 6500
P001 My SQL & Linux E006 Hansel C 4500
P002 Office & Linux E001 Sharanam A 7000
P002 Office & Linux E007 Chhaya B 4000

In the above data there are a few problems:


The Project Name in the second record is misspelled. This can be solved, by
removing duplicates. Do this using normalization
Data is repeated and thus occupies more space

A table is in 1st normal form if:


There are no repeating groups
All the key attributes are defined
All attributes are dependent on a primary key

So far there are no keys, and there are repeating groups. So remove the repeating
groups, and define the primary key.

To convert a table to its First Normal Form:


1. The un-normalized data in the first table is the entire table
2. A key that will uniquely identify each record should be assigned to the table. This
key has to be unique because it should be capable of identifying any specific row
from the table for extracting information for use. This key is called the table's
primary key.

This table is now in 1st normal form.

Table: EmpProj
Field Key
Project Number Primary Key
Project Name --
Employee Number Primary Key
Employee Name --
Rate Category --
Hurly Rate --
RDBMS
Mehul Patel
(BCA-201) Class: SYBCA Unit/21
-I

Field
Key
Project Number
Primary Key
Employee Number
>Second Normal Form Primary Key
A table is said to be in its second normal form when each record in the table is in the
first normal form and each column in the record is fully dependent on its primary key.

A table is in 2nd normal form if:


It's in 1st normal form
It includes no partial dependencies (where an attribute is dependent on
only a part of a primary key)

The steps to convert a table to its Second Normal Form:


1.Find and remove fields that are related to the only part of the key
2.Group the removed items in another table
3.Assign the new table with the key i.e. part of a whole composite key

Going through all the fields reveals the following:


Project name is only dependent on Project number
Employee name, Rate category and Hourly rate are dependent only on Employee
number

To convert the table into the second normal form remove and place these fields in a
separate table, with the key being that part of the original key they are dependent on.

This leads to the following 3 tables:

Table: EmpProj

Table: Proj
Field Key
Project Number Primary Key
Project Name --
Table: Emp
Field Key
Employee Number Primary Key
Employee Name --
Rate Category --
Hurly Rate --

The table is now in 2nd normal form, but not yet in its 3rd normal form
RDBMS
Mehul Patel
(BCA-201) Class: SYBCA Unit/21
-I
Field Key
Table: Emp Employee Number Primary Key
Table: Rate Employee Name
Rate Category
>Third Normal Field Form
Table data is said to be inKey
third normal format when all transitive dependencies are
removed from this data".

The table is in 3rd normal form if:


It's in 2nd normal form
It contains no transitive dependencies (where a non-key attribute is
dependent on another non-key attribute)

A general case of transitive dependencies is as follows:


A, B, C are three columns in table.
If C is related to B If B is
related to A Then C is indirectly
related to A
This is when transitive dependency exists.

To convert such data to its third normal form remove this transitive dependency by
splitting each relation in two separate relations. This means that data in columns A, B,
C must be placed in three separate tables, which are linked using a foreign key

Going through all the fields reveals the following:


Employee table is the only one with more than one non-key attribute
Employee name is not dependent on either Rate category or Hourly rate
Hourly rate is dependent on Rate category

To convert the table into the third normal form remove and place these fields in a
separate table, with the attribute it was dependent on as key, as follows:

This leads to the following 4 tables:

Field
Table: EmpProj Key
Project Number Primary Key
Employee Number Primary Key
Table: Proj
Field Key
Project Number Primary Key
Project Name --

Rate Category --
Hurly Rate --
RDBMS
Mehul Patel
(BCA-201) Class: SYBCA Unit
10/21
-I

These tables are all now in their 3rd normal form, and ready to be implemented. There
are other normal forms such as Boyce-Codd normal form (BCNF), 4th and 5th normal
form, but these are very rarely used for business applications. In most cases, tables
that are in there 3rd normal form are already conforming to these types of table
formats anyway.

> Circumstances under which Normalization can be avoided


There are situations when normalization can be avoided. This can be seen in the
following table structure:

Table: Customer
Field Key
Customer Number Primary Key
Customer Name --
Address --
Pincode --
City --

Going through all the fields reveals the following:


No repeating groups exists
A primary key is defined

This proves that it is at least in 1st normal form


There is only one key so partial dependencies do not exists

This proves that it is at least in 2nd normal form


There are transitive dependencies
It seems that like City might be determined by Pincode, which' is usually the case in
most parts of the world, but there is no need to remove City, and place it in a separate
table, with Pincode as the key.

Although this table is not technically in its 3rd normal format, removing this
information is not worth it. Creating more tables increases the load slightly, slowing
processing down. This is often counteracted by the reduction in table sizes, and
redundant data. But in this case, where the City would almost always be referenced as
part of the address, it isn't worth it. Normalization is just a helpful process that usually
results in the most efficient table structure, and not a rule for database design.
RDBMS
Mehul Patel
(BCA-201) Class: SYBCA Unit
11/21
-I

> INTRODUCTION TO ORACLE

Way back in June 1970, Dr E. F. Codd published a paper entitled A Relational Model of
Data for Large Shared Data Banks. This relational model, sponsored by IBM, then
came to be accepted as the definitive model for RDBMS. The language developed by
IBM to manipulate the data stored within Codd's model was originally called Structured
English Query Language (SEQUEL) with the word English later being dropped in favor
Structured Query Language (SQL).

In 1979 a company called, Relational Software, Inc. released the first commercially
available implementation of SQL. Relational Software later came to be known as Oracle
Corporation. Oracle Corporation is a company that produces the most widely used,
Server based, Multi-user RDBMS named Oracle.

INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL)


Structured Query Language (SQL) is a language that provides an interface to relational
database systems. SQL was developed by IBM in the 1970s for use in System R, and is
a de facto standard, as well as an ISO and ANSI standard. SQL is often pronounced
SEQUEL.

In common usage SQL also encompasses DML (Data Manipulation Language), for
Inserts, Updates, Deletes and DDL (Data Definition Language), used for creating and
111odifying tables and other database structures.

> What is SQL?


SQL (Structural Query Language) is a set of commands that lets you access a
relational database. SQL is a standard interface for many relational databases. It has a
simple command structure for data definition, access, and manipulation. SQL is set-
oriented and non-procedural. When you use SQL you specify what to be done, not how
to do it.

> Features of SQL:


1. SQL can be used by a range of users, including those with little or no programming
experience.
2. It is a non-procedural language.
3. It reduces the amount of time required for creating and maintaining systems.
4. It is an English-like language.
RDBMS
Mehul Patel
(BCA-201) Class: SYBCA Unit
12/21
-I

> Rules for SQL


1. SQL starts with a verb {i.e. a SQL action word).
Example: SELECT statements. This verb may have additional adjectives.
Example: SELECT ... FROM
2. Each verb is followed by number of clauses.
Example: FROM, WHERE, HAVING
3. A space separates clauses. Example: DROP TABLE EMP;
4. A comma (,) separates parameters (without a clause)
5. A ';' is used to end SQL statements
6. Statements may be split across lines but keywords may not
7. Lexical units such as identifiers, operator names, literals are separated by one or
more spaces or other delimiters that will not be confused with the lexical unit
8. Reserved words cannot be used as identifiers unless enclosed with double quotes.
Reserved words are: ALL, DROP, USER, ORDER, DELETE, SELECT, INITIAL,
ROWLABEL, VIEW, EXISTS, UNIUE, INTEGER, AS, ASC, INTO, ALTER, ROWID,
INSERT, VALUES, VARCHAR2 etc...

9. Identifiers can contain up to 30 characters and must start with an alphabetic


character
0. Character and date literals must be enclosed within single quotes
0. Numeric literals can be represented by simple values such as 0.32, -34, 01991,
and so on,
Scientific notation as 2E5 meaning 2x1O to the power of 5 = 200,000.
1. Comments may be enclosed between /* and */ symbols and may be multi line.
Single line comments may be prefixed with a- symbol

> SQL Delimiters


Delimiters are symbols or compound symbols, which have a special meaning within
SQL and PL/SQL statements,

+ Addition “ Quote Identifier


- Subtraction : Host Variable
* Multiplication ** Exponential
/ Division <> != ^= Relational
=>< Relational <= >= Relational
() Expression or list := Assignment
; Terminator => Association
% Attribute indicator || Concatenation
, Item Separator << Label
. Component Selector ?? Label
@ Remote access indicator -- Comment (single line)
‘ Character string delimiter /* */ Comment (multi line)
RDBMS
Mehul Patel
(BCA-201) Class: SYBCA Unit/21
-I

> Components of SQL


1.DDL (Data Definition Language) --
It is a set of SQL commands -- used to create, modify and delete database
structure but not data. These commands are normally not used by a general
user, who should be accessing the database via an application. They are
normally used by the DBA to a limited extent, a database designer or application
developer. These statements are immediate i.e. they are not susceptible to
ROLLBACK commands. It should also be noted that if several DML statements
for example update's are executed then issuing any DDL command would
COMMIT all the updates as every DDL c6mmand implicitly issues a COMMIT
command to the database. Anybody using DDL must have the CREA TE object
privilege and a Table space area in which to create objects.
2.DML (Data Manipulation Language
It is the area of SQL that allows changing data within the Database.
3.DCL (Data Control Language)
It is the component of SQL statement that control access to data and to the
database. Occasionally DCL statements are grouped with DML statements.
4.DQL (Data Query Language)
It is the component of SQL statement that allows getting data from the database
and imposing ordering upon it. In includes the SELECT statement. This
command is heart of SQL. It allows getting the data out of the database perform
operations with it. When SELECT is fired against a table or tables the result is
compiled into a further temporary table, which displayed or perhaps received by
the program i.e. a front-end.

> Examples of DDL, DML and DCL commands

DDL: Data Definition Language Statements


Examples:
CREATE - To create objects in the database
ALTER - alters the structure of the database
DROP - Delete objects from the database
TRUNCATE - Remove all records from a table, including all spaces allocated for the
records are removed
COMMENT - Add comments to the data dictionary
GRANT - Gives user's access privileges to database
REVOKE - Withdraw access privileges given with the GRANT command

DML: Data Manipulation Language statements


Examples:
INSERT - Insert data into a table
UPDATE - Updates existing data within a table
DELETE - Deletes all records from a table, the space for the records remain
CALL - Call a PL/SQL or Java subprogram
EXPLAINS PLAN - Explain access path to data
LOCK - TABLE Control concurrency
RDBMS
Mehul Patel
(BCA-201) Class: SYBCA Unit/21
-I

DCL: Data Control Language statements


Examples:
COMMIT - Save work done
SAVEPOINT - Identify a point in a transaction to which you can later roll back
ROLLBACK - Restore database to original since the last COMMIT
SET TRANSACTION - Change transaction options like what rollback segment to use
GRANT / REVOKE - Grant or take back permissions to or from the oracle users

DQL: Data Query Language statement


Examples:
SELECT - Retrieve data from the a database
RDBMS
Mehul Patel
(BCA-201) Class: SYBCA Unit/21
-I

> DATATYPE(S):
1. Character Data types
Character data types are used to manipulate words and free-form text. These
data types are used to store character (alphanumeric) data in the database or national
character set. They are less restrictive than other data types and consequently have
fewer properties.
These data types are used for character data:

CHAR
VARCHAR
VARCHAR2

CHAR Data type


The CHAR data type specifies a fixed length character string. When you create a
table with a CHAR column, you supply the column length in bytes. Oracle subsequently
ensures that all values stored in that column have this length. If you insert a value
that is shorter than the column length, Oracle blank-pads the value to column length.
If you try to insert a value that is too long for the column, Oracle returns an error.
The default length for a CHAR column is 1 character and the maximum allowed is
2000 characters. A zero-length string can be inserted into a CHAR column, but the
column is blank-padded to 1 character when used in comparisons.

VARCHAR2 Datatype
The VARCHAR2 datatype specifies a variable length character string. When you
create a VARCHAR2 column, you can supply the maximum number of bytes of data
that it can hold. Oracle subsequently stores each value in the column exactly as you
specify it, provided it does not exceed the column's maximum length. This maximum
must be at least 1 byte, although the actual length of the string stored is permitted to
be zero. If you try to insert a value that exceeds the specified length, Oracle returns an
error.
You must specify a maximum length for a VARCHAR2 column. The maximum length
of VARCHAR2 data is 4000 bytes .

VARCHAR Datatype
The VARCHAR datatype is currently synonymous with the VARCHAR2 datatype.
It is recommended that you use VARCHAR2 rather than VARCHAR. In a future version
of Oracle, VARCHAR might be a separate datatype used for variable length character
strings compared with different comparison semantics .
RDBMS
Mehul Patel
(BCA-201) Class: SYBCA Unit/21
-I

2. NUMBER Datatype
The NUMBER datatype is used to store zero, positive and negative fixed and
floating point numbers with magnitudes between 1.0 x 10-130
and 9.9...9 x 10 125 (38 9s
followed by 88 0s) with 38 digits of precision. If you specify an arithmetic expression
whose value has a magnitude greater than or equal to 1.0 x 10 126
, Oracle returns an
error.
You can specify a fixed-point number using the following form:
NUMBER (p,s)
Where,
p is the precision , or the total number of digits. Oracle guarantees the portability of
numbers with precision ranging from 1 to 38.
s is the scale, or the number of digits to the right of the decimal point. The scale
can range from -84 to 127.
The following examples show how Oracle stores data using different precisions and
scales.
Actual Data Specified As Stored As
7456123 .89 NUMBER 7456123 .89
7456123 .89 NUMBER(9) 7456124
7456123 .89 NUMBER(9,2) 7456123 .89
7456123 .89 NUMBER(9,1) 7456123 .9
7456123 .8 NUMBER(6) exceeds precision
7456123 .8 NUMBER(15,1) 7456123 .8
7456123 .89 NUMBER(7,-2) 7456100
7456123 .89 NUMBER(-7,2) exceeds precision

You can specify a scale that is greater than precision, although it is uncommon.
In this case, the precision specifies the maximum number of digits to the right of the
decimal point. As with all number datatypes, if the value exceeds the precision, Oracle
returns an error message. If the value exceeds the scale, Oracle rounds the value. For
example, a column defined as NUMBER (4,5) requires a zero for the first digit after the
decimal point and rounds all values past the fifth digit after the decimal point. The
following examples show the effects of a scale greater than precision:

Actual Data Specified As Stored As


.01234 NUMBER (4,5) .01234
.00012 NUMBER (4,5) .00012
.000127 NUMBER (4,5) .00013
.0000012 NUMBER (2,7) .0000012
.00000123 NUMBER (2,7) .0000012
RDBMS
Mehul Patel
(BCA-201) Class: SYBCA Unit/21
-I

3. LONG Datatype
LONG columns store variable length character strings containing up to 2
gigabytes, or 2 31 -1 bytes. LONG columns have many of the characteristics of
VARCHAR2 columns. You can use LONG columns to store long text strings. Oracle uses
LONG columns in the data dictionary to store the text of view definitions. The length of
LONG values may also be limited by the memory available on your computer.
The use of LONG values is subject to some restrictions:

> A table cannot contain more than one LONG column.


> LONG columns cannot appear in integrity constraints (except for NULL and NOT
NULL constraints).
> LONG columns cannot be indexed.
> A stored function cannot return a LONG value.
> Within a single SQL statement, all LONG columns, updated tables, and locked
tables must be located on the same database.

4. DATE Datatype
The DATE datatype is used to store date and time information. Although date
and time information can be represented in both CHAR and NUMBER datatypes, the
DATE datatype has special associated properties.
For each DATE value the following information is stored:

century
year
month
day
hour
minute
second

5. RAW and LONG RAW Datatypes


The RAW and LONG RAW datatypes are used for data that is not to be interpreted
(not converted when moving data between different systems) by Oracle. These data
types are intended for binary data or byte strings. For example, LONG RAW can be
used to store graphics, sound, documents, or arrays of binary data; the interpretation
is dependent on the use.
LONG RAW data cannot be indexed, but RAW data can be indexed.

6. Large Object (LOB) Data types


Internal LOB data types, BLOB, CLOB, NCLOB, and external data type BFILE, can
store large and unstructured data such as text, image, video, and spatial data, up to
four gigabytes in size.
You can define one or more LOB data type columns in a table .
RDBMS
Mehul Patel
(BCA-201) Class: SYBCA Unit/21
-I

7. ROWID
For each row in the database, the ROWID pseudo column returns a row's address.
Usually, a ROWID value uniquely identifies a row in the database. However, rows in
different tables that are stored together in the same cluster can have the same
ROWID.
Values of the ROWID pseudo column have the data type ROWID.

ROWID values have several important uses:


They are the fastest way to access a single row.
They can show you how a table's rows are stored.
They are unique identifiers for rows in a table.

You should not use ROWID as a table's primary key. If you delete and reinsert a
row with the Import and Export utilities, for example, its ROWID may change. If you
delete a row, Oracle may reassign its ROWID to a new row inserted later.
Although you can use the ROWID pseudo column in the SELECT and WHERE clauses
of a query, these pseudo column values are not actually stored in the database. You
cannot insert, update, or delete a value of the ROWID pseudo column.

Example: Select ROWID from EPM;


RDBMS
Mehul Patel
(BCA-201) Class: SYBCA Unit/21
-I

> CREATE TABLE


TYPE: DDL
SYNTAX:
CREATE TABLE tablename
(columnname datatype(size), columnname datatype(size)....);
Whenever user creates table, the table name must be a legal SQL name and it
must not conflict with the name of any of your existing tables.
e.g.
CREATE TABLE stud
(s_no NUMBER(3), s_name VARCHAR2(15), address VARCHAR2(20) );

Creating a table from previously created table.


SYNTAX:
CREATE TABLE tablename1 (columnanme, columnname.....) AS SELECT
columnname,columnname..... FROM tablename2
[WHERE <condition>]
Note: If the tablename2 is having records in it then the target table –
tablename1 is populated with records well.
e.g CREATE TABLE stud1 AS SELECT * FROM STUD;
Create duplicate table with empty:
CREATE TABLE <new tablename> AS SELECT * FROM <old tablename> WHERE
1=2
> DROP TABLE
TYPE: DDL
SYNTAX: DROP TABLE tablename;
Removing the table and all its data and constraints from the database.
Example: DROP TABLE stud;
> INSERTION OF DATA INTO TABLES
TYPE: DML
Purpose: To add rows/records to a table or a view’s base table.
SYNTAX: INSERT INTO <tablename> [columnname, ...... ]
VALUES (<expr1>, . . .);
Bind variables:
1.&variable_ name
It will not preserve value to a variable. Once the value is transferred into a
specific column each time it will ask the user to input users to input value.
INSERT INTO <tablename> [ <columnname>,.....] VALUES (&S_NO,....);
2. &&variable_name
It will preserve value to a variable. It is used for define variable first time.
It will not ask user second time and previous values will automatically been
assigned to the specific field .
INSERT INTO <tablename> [ <columnname>,.....] VALUES
(&&S_NO,&&SNAME,....);
Inserting data into a table from another table:
INSERT INTO tablename SELECT columnname,columnname FROM
tablename [ WHERE <condition> ];
RDBMS
Mehul Patel
(BCA-201) Class: SYBCA Unit/21
-I

> UPDATING A CONTENTS OF A TABLE:

TYPE: DML
SYNTAX:
UPDATE <tablename>
SET columnname = <expr>, columnname =<expr>
[ WHERE <condition> ];
Changing the existing values in a table or in a view’s base table.

> DELETION OPERATIONS:


TYPE: DML
SYNTAX:
DELETE [FROM] <tablename> [WHERE <condition>];
To remove row(s) from table:
DELETE FROM <tablename>;
Will delete all the records from a table name specified
DELETE FROM <tablename> WHERE <condition> Will delete all the
records, which satisfies the condition specified after where.

> TRUNCATE
TYPE: DML
SYNTAX: TRUNCATE TABLE <tablename>;
Will delete all the records from a table and records cannot be ROLLBACK.

> RENAME
TYPE: DDL
SYNTAX: RENAME <oldname> TO <newname>;
User can rename a table.

> SELECT COMMAND:


TYPE: DML
SYNTAX:
SELECT * FROM tab;
Will display the information of all the tables, views in the current database.
SELECT * FROM tablename;
Will display all the records from a table with all the fields.
SELECT columnname, columnname FROM tablename;
Will display all the records with specific fields that user has specified with
SELECT command.
SELECT * FROM <tablename> WHERE <condition>;
Will display all the records with given condition specified after WHERE will
become true.
SELECT DISTINCT columname FROM tablename;
Will eliminate the duplicate records for column specified after DISTINCT
SELECT columnname, columnname FROM <tablename>
ORDER BY columnname , columnname ;
RDBMS
Mehul Patel
(BCA-201) Class: SYBCA Unit/21
-I

Sorting of data in a table.

SELECT columnname, columnname FROM <tablename>


ORDER BY <expN> [ASCE | DESC];
Here <expN> specifies that the field number that means user can specify field
number instead of specifying the columnname.
ASCE means sort the records in an ascending order.
DESC means sort the records in a descending order.
> VIEWING THE TABLE STRUCTURE:
SYNTAX:
DESCRIBE <table name>
OR
DESC <table name>

> MODIFYING THE STRUCTURE OF TABLE:


TYPE: DDL
ADDING NEW COLUMNS:
SYNTAX:
ALTER TABLE <tablename> ADD
(newcolumnname datatype(size), newcolumnname datatype(size));
MODIFYING EXISTING COLUMNS:
ALTER TABLE <tablename> MODIFY
(Columnname newdatatype (size));
DELETING COLUMNS
ALTER TABLE <tablename> DROP COLUMN <columnname>;
Restrictions on the ALTER table:
User cannot change the column name
User cannot decrease the size of column if record(s) there in the table for
that column.
Earlier versions do not support the deletion of column(s ).
> SPOOL
To store the results of a query in a file as well as print and display on the screen
using SPOOL command:
Syntax: SPOOL <file>
After given the spool with file name that tells SQL to store all the
information that is displayed on the screen after SPOOL command has been
entered, into the specified file. The default file extension is .LST unless user
specifies the specific extension.
SQL will continue to spool information to the file until you turn spooling
off.
SPOOL OFF: Will stop spooling data to a file.
-)

SPOOL OUT: This command will stop spooling and will also copy the spool file’s
-)

contents to a default printer .

Potrebbero piacerti anche