15
Introduction To Oracle Database IT-3441 Lecture # 3 Jahanzaib Ali Khan

Introduction to oracle database (basic concepts)

Embed Size (px)

Citation preview

Page 1: Introduction to oracle database (basic concepts)

Introduction To Oracle DatabaseIT-3441

Lecture # 3Jahanzaib Ali Khan

Page 2: Introduction to oracle database (basic concepts)

Oracle is an Relational Database• Database in which all data is stored in Relations (Tables) with rows

and columns. Each table is composed of records (called Tuples) and each record is identified by a field (attribute) containing a unique value. Every table shares at least one field with another table in 'one to one,' 'one to many,' or 'many to many' relationships. These relationships allow the database user to access the data in almost an unlimited number of ways, and to combine the tables as building blocks to create complex and very large databases.

• The oracle database houses everything There is 1 database which has multiple tablespaces, schemas,Datafiles and segments.

Page 3: Introduction to oracle database (basic concepts)

Database Management System• A database management system (DBMS) is software that controls the

storage, organization, and retrieval of data. Typically, a DBMS has the following elements:

• A database application is a software program that interacts with a database to access and manipulate data.

• The first generation of database management systems included the following types:

• A hierarchical database organizes data in a tree structure. Each parent record has one or more child records, similar to the structure of a file system.

• A network database is similar to a hierarchical database, except records have a many-to-many rather than a one-to-many relationship.

• Current Model is Relational Database Model , Described Earlier.

Page 4: Introduction to oracle database (basic concepts)

What is Oracle Schema ??• In simple terms a schema in an Oracle database is another

name for a user. So a schema and a user are the same thing.

• SCHEMA = USER• The purpose of a schema in Oracle is to house database

objects. The objects could be like tables and indexes, or object definitions like views, packages, triggers, etc. Hopefully image will help you to understand the relationship between a database, a schema, the segments in a schema and the tablespace in which the segments reside.

Page 5: Introduction to oracle database (basic concepts)

Schema !!

Page 6: Introduction to oracle database (basic concepts)

More about Schema !!!

• A schema is owned by a database user and has the same name as that user. Each user owns a single schema. Schema objects can be created and manipulated with SQL and include the following types of objects:Clusters

• Database links• Database triggers• Dimensions• External procedure libraries• Indexes and index types• Java classes, Java resources, and Java sources• Materialized views and materialized view logs• Object tables, object types, and object views• Operators• Sequences• Stored functions, procedures, and packages• Synonyms• Tables and index-organized tables• Views

Page 7: Introduction to oracle database (basic concepts)

Table• A table describes an entity such as employees. You define a table

with a table name, such as employees, and set of columns. In general, you give each column a name, a data type, and a width when you create the table.

• A table is a set of rows. A column identifies an attribute of the entity described by the table, whereas a rowidentifies an instance of the entity. For example, attributes of the employees entity correspond to columns for employee ID and last name. A row identifies a specific employee.

• You can optionally specify rules for each column of a table. These rules are called integrity constraints. One example is a NOT NULL integrity constraint. This constraint forces the column to contain a value in every row.

Page 8: Introduction to oracle database (basic concepts)

Indexes• An index is an optional data structure that you can create

on one or more columns of a table. Indexes can increase the performance of data retrieval. When processing a request, the database can use available indexes to locate the requested rows efficiently. Indexes are useful when applications often query a specific row or range of rows.

• Indexes are logically and physically independent of the data. Thus, you can drop and create indexes with no effect on the tables or other indexes. All applications continue to function after you drop an index.

Page 9: Introduction to oracle database (basic concepts)

Oracle Table Spaces• This is a logical structure, meaning that a tablespace is not a physical

object• A tablespace is made of 1 or more physical structures called datafiles• Each tablespace can have different characteristics, such as size and how

the size are managed• They are used to group segments (tables, indexes, etc) into logical

groups. For example, you may have accounting data in one tablespace and reporting data in another. This does not have to be the case, though, you are free to put whatever you like in the tablespacesyou create

• The SYSTEM and SYSAUX tablespaces are mandatory as of 10g, and it is recommended to not put your own user created segments in either of these tablespaces

Page 10: Introduction to oracle database (basic concepts)

Datafiles

• A datafile is a physical file on disk, just like any other file which sits on a hard disk but in an Oracle format

• The datafile is created as part of a tablespace, and only one tablespace

• You can set datafiles to autoextend which means they they become full they will automatically extend preventing users from running out of space

• For performance reasons, I would recommend having fewer, larger datafiles rather than lots of small ones

Page 11: Introduction to oracle database (basic concepts)

The Oracle Schema or User• Oracle Schema and user are synonymous and the terms

are usually used interchangeably• There can be thousands of users within one database• The schema owns segments (tables, indexes, etc) and

objects (views, constraints, etc) and each segment/object can belong to only one schema

• Users can see segments and objects in other schemas if they have been given the appropriate permissions

• If you have many schemas it is a good idea to use Oracle roles to manage what privileges they have

Page 12: Introduction to oracle database (basic concepts)

Summing Up Things • In Oracle Database, a database schema is a collection of logical data

structures, or schema objects [i.e. related tables]. A database schema is owned by a database user and has the same name as the user name.

• You can create multiple Oracle databases. Or you can create a single database with multiple schemas. Or you can create a single database with a single schema an put everything there if all your object names are unique.

• A database consists of one or many tablespaces. A database has one-to-many relationship with tablespaces. That is, one database can have many tablespaces, but a given tablespace can belong to only one database.

• Similary, a tablespace has one-to-many relationship with datafiles. That is, a tablespace can have one or many datafiles but a given datafile can belong to only one tablespace.

• Database>>Schema>>TableSpace>>Datafiles

Page 13: Introduction to oracle database (basic concepts)

Data Access• Structured Query Language:• SQL is a non-procedural query language used to operate

with oracle Database.• All operations on the data in an Oracle database are

performed using SQL statements. For example, you use SQL to create tables and query and modify data in tables. A SQL statement can be thought of as a very simple, but powerful, computer program or instruction. A SQL statement is a string of SQL text such as the following:

• SELECT first_name, last_name FROM employees;

Page 14: Introduction to oracle database (basic concepts)

PL/SQL and Java• PL/SQL is a procedural extension to Oracle SQL. PL/SQL is integrated with

Oracle Database, enabling you to use all of the Oracle Database SQL statements, functions, and data types. You can use PL/SQL to control the flow of a SQL program, use variables, and write error-handling procedures.

• A primary benefit of PL/SQL is the ability to store application logic in the database itself. A PL/SQL procedureor function is a schema object that consists of a set of SQL statements and other PL/SQL constructs, grouped together, stored in the database, and run as a unit to solve a specific problem or to perform a set of related tasks. The principal benefit of server-side programming is that built-in functionality can be deployed anywhere.

• Oracle Database can also store program units written in Java. A Java stored procedure is a Java method published to SQL and stored in the database for general use. You can call existing PL/SQL programs from Java and Java programs from PL/SQL.

Page 15: Introduction to oracle database (basic concepts)

Practical Task !!!

• Open then login into Oracle 11g Express by typing your username and password

• Create New Workspace• Goto Application Express• Create a sample project