pgdba database class intro
Post on 23-Jan-2016
226 Views
Preview:
DESCRIPTION
TRANSCRIPT
ORACLE 11G Database
Objectives
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
Objects and Attributes
Characteristics of Person
Name
Date of birth
Gender
Objects of interest is Entity
Attributes
UniversityBusiness Example of Data
Data
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.
InsertUpdateDelete
DBMS
A Database
1970 E F Codd (1923-2003) invented the Relational DBMS
Oracle is RDBMS
Centralized Repository of Data
A Database
RDBMS
ENDUSER
Relational Database Management System
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.
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
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.
Table – Important ConceptsForeign Key - Creates relationship
JOBS
EMPLOYEES
Foreign Key within Table
Primary Key Foreign Key
SERVER
orcl
Client
Username: Password:
Port 1521
ORACLE DATABASE SERVER
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.
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.
Database
Schemas
Objects
consists of
own
Logical Objects
TablesIndexesSequencesViewsProceduresTriggersEtc
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
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
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.
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
BASIC TABLE CREATION
CREATE TABLE table-name
( column-name datatype (size),
column-name datatype (size),
…
);
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>’;
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’;
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
Datatype
VARCHAR2(w) CHAR(w) NUMBER NUMBER(w) NUMBER(w,s) DATE LONG
Example
CREATE TABLE EMP( EMP_NO NUMBER(4),
EMP_NAME VARCHAR2(25),MANAGER NUMBER(4),SALARY NUMBER(8,2));
InsertINSERT INTO table-name [(column-name,
column-name, …)]VALUES (value, value, …);
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);
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.
top related