PGDBA database Class Intro

33
ORACLE 11G Database

description

Class 1 of data base structure.

Transcript of PGDBA database Class Intro

Page 1: PGDBA database Class Intro

ORACLE 11G Database

Page 2: PGDBA database Class Intro

Objectives

Page 3: PGDBA database Class Intro

What is Data?

Data is any fact that needs to be stored.

Employees name, departments name, telephone numbers address in address books are data.

Data often pertains to or describes some object of interest

Page 4: PGDBA database Class Intro

Objects and Attributes

Characteristics of Person

Name

Date of birth

Gender

Objects of interest is Entity

Attributes

Page 5: PGDBA database Class Intro

UniversityBusiness Example of Data

Page 6: PGDBA database Class Intro

Data

Page 7: PGDBA database Class Intro

What is a Database? When related data is stored in a centralized manner

– DATABASE. Database consists of data pertaining to one or more

object of interest. These objects may be related to each other Student(an object) enrolls for a course (another

object) Relational can be maintained and managed within

database.

Page 8: PGDBA database Class Intro

InsertUpdateDelete

DBMS

A Database

1970 E F Codd (1923-2003) invented the Relational DBMS

Oracle is RDBMS

Page 9: PGDBA database Class Intro

Centralized Repository of Data

A Database

RDBMS

ENDUSER

Relational Database Management System

Page 10: PGDBA database Class Intro

DataBase Management SystemDatabase Management System that

represent the database as TablesTables are basic structure – made up two

dimensional tables.Rows and ColumnsIn addition to tables a number of different

object can be maintained in the database.

Page 11: PGDBA database Class Intro

DataBase Management System DataBase Management Systems(DBMS) is a software

package that allows data to be effectively stored, retrieved and manipulated.

The data stored in a DBMS package can be accessed by multiple users and by multiple application programs.

You can find database management systems many places in your everyday life.

Examples of Database management system--- The ATM that you get cash.--- The Online flight reservation--- The Online banking

Page 12: PGDBA database Class Intro

Table – Important ConceptsPrimary Key – Uniquely defines a row of TableNull – Unknown or unavailable value

Primary Key Null

Attributes

Rows/Tuple

EMPLOYEE

AttributesEntity

No of columns associated in table or relation is called degree. In above table degree is 6.No of rows in the table is called cardinally.

Page 13: PGDBA database Class Intro

Table – Important ConceptsForeign Key - Creates relationship

JOBS

EMPLOYEES

Page 14: PGDBA database Class Intro

Foreign Key within Table

Primary Key Foreign Key

Page 15: PGDBA database Class Intro

SERVER

orcl

Client

Username: Password:

Port 1521

ORACLE DATABASE SERVER

Page 16: PGDBA database Class Intro

Types of Data2343 -Positive Integer243.44 -Real numberABCbxyDks -Character StirngSkb343CS -Alphanumeric StringSkb343CS&5## -Alphanumeric & Character Stirng01-Jul-2009 -Date

Each column in table Oracle database can hold only one type of data. User should mention the type of data to be entered (known as Datatype) along with columns when a table is created in the database.

Page 17: PGDBA database Class Intro
Page 18: PGDBA database Class Intro

Users of the database A data base may be accessed by many different users. A user would be an individual, operator, administrator or

application that has access to the database Every user is associated with a username and password. Depending the job function of user, they need appropriate

access to the database.

Page 19: PGDBA database Class Intro

Database

Schemas

Objects

consists of

own

Logical Objects

TablesIndexesSequencesViewsProceduresTriggersEtc

Page 20: PGDBA database Class Intro

Username : HRPassword:

Username: SYSTEMPassword :

Username : SCOTTPassword : TIGER

Username :SYSPassword :

SYS and SYSTEM user is created at the time of installation of database

Users of the Database

Page 21: PGDBA database Class Intro

Tables Synonyms

Views Indexes

Constraints Procedures

Packages FunctionsTriggers

SchemaA Schema is a logical collection of the objects that belong to a userUsername : HRSchema Name : HR

Page 22: PGDBA database Class Intro

Structured Query Language(SQL) Structured Query Language(SQL) Structured Query Language(SQL) is a high-

level language used to interact with an Oracle database

Users write SQL statements, which is accepted by the RDBMS, which in turn either responds with an output or performs an action within the database.

Page 23: PGDBA database Class Intro
Page 24: PGDBA database Class Intro

SQLData Definition Language(DDL)

- CREATE- ALTER- DROP

Data Manipulation Language(DML) - INSERT- UPDATE- DELETE

Data Control Language(DCL) - GRANT- REVOKE

Data Control Language(TCL)- COMMIT- ROLLBACK

Data Query Language- SELECT

Page 25: PGDBA database Class Intro

BASIC TABLE CREATION

CREATE TABLE table-name

( column-name datatype (size),

column-name datatype (size),

);

Page 26: PGDBA database Class Intro

Adding comments to definitions

For application that include numerous tables, it is useful to add comments on table definitions or to add comments on columns.

A comment on a table can be created using the commandcomment on table <table> is ‘<text>’;

A comment on a column can be created using the commandcomment on column <table>.<column> is

‘<text>’;

Page 27: PGDBA database Class Intro

Adding comments to definitions -- Create table

create table t ( col1 number(6) ) ; -- Add comments to the columns comment on column t.col1 is 'this is a comment';comment on table t is ‘this is comment for table t’;

Page 28: PGDBA database Class Intro

Naming Identifier rules

Must begin with a letterCase insensitive It may contain letters, numerals and _30 character in lengthMust not be SQL reserve word or

duplicate name of another object in your account

Page 29: PGDBA database Class Intro

Datatype

VARCHAR2(w) CHAR(w) NUMBER NUMBER(w) NUMBER(w,s) DATE LONG

Page 30: PGDBA database Class Intro

Example

CREATE TABLE EMP( EMP_NO NUMBER(4),

EMP_NAME VARCHAR2(25),MANAGER NUMBER(4),SALARY NUMBER(8,2));

Page 31: PGDBA database Class Intro

InsertINSERT INTO table-name [(column-name,

column-name, …)]VALUES (value, value, …);

Page 32: PGDBA database Class Intro

InsertINSERT INTO table-name

[(column-name, column-name, …)]VALUES (value, value, …);

INSERT INTO EMP (EMP_NO, DEPT_NO, EMP_NAME, ADDRESS, MANAGER, SALARY)

VALUES (1001, 03, ’A. DAS’, ‘203 B.T. ROAD’, 003, 10000);

INSERT INTO EMP (EMP_NO, DEPT_NO, EMP_NAME, ADDRESS, MANAGER, SALARY)

VALUES (&E_NO, &E_DEP, &E_MANE, &E_ADDRESS, &E_MANAGER, &E_SALARY);

Page 33: PGDBA database Class Intro

TCL - Commit and Rollback A sequence of database modification, i.e., a sequence of insert, update, and delete

statements, is called a transaction.

Modifications of tuple are temporarily stored in the database system. They become permanent only after the statement commit; has been issued.

As long as the user has not issued the commit statement, it is possible to undo all modifications since the last commit.

To undo modifications, one has to issue the statement rollback;

It is advisable to complete each modification of the database with a commit (as long as modification has the expected effect).

Note that any data definition command such as create table results in an internal commit.

A commit is also implicitly executed when the user terminates an Oracle sessions.