Thursday, 8 October 2015



Triggers


A trigger is special type of stored procedure and is procedure and is defined on table or views. Triggers are automatically executed automatically fire when an update, insert, or delete command executed in table. Triggers are a powerful tool that is used to enforce the database rules automatically while you modify the data. The advantage of Triggers To generate the resulting data automatically Avoiding invalid transaction in database. Provide transparent event logging and advanced auditing data modifications. Maintain synchronous table replicates and check the status of the access.


Part of Triggers

A database Trigger has five part.

1: Trigger timing
2: Trigger command
3: Trigger level
4: Trigger restriction
5: Trigger body




Procedures


In a database management system (DBMS), a procedure is a set of structured Query Language (SQL) statements with an assigned name that's stored in the database executed form so that it can be shared by a number of programs.

It is like as Function the main difference between a procedure and function is the, a Function must always return a value, but a Procedure does not return a value.

The procedures can be helpful in controlling access to data (end-users may enter or change data but do not write procedures), preserving data integrity (information is entered in a consistent manner) and improving productivity (statements in a stored procedure only need to be written one time.

Stored procedures provide a powerful way to code application logic that can be stored on the server.

A stored procedure or in simple a proc is a named PL/SQL block which performs one or more specific task. Oracle also uses an additional type of subprogram called a function.


A Procedure has two parts:

1: Header 2: Body

The header contains of the name of the procedure and the parameters or variables passed to the procedure. The body contains declaration section, execution section and exception section it is similar to a normal PL/SQL block.




Packages


A package is an oracle object, which holds other objects within it. Objects commonly held within a package are Procedures, variables, constants, cursors and exceptions. It is method of creating generic, encapsulation re-useable code. A package once written and debugged is compiled and stored in Oracle's system tables held in an Oracle Database.


Advantages of PL/SQL Packages

Packages have many advantages like modularity, easier application design, added functionality and increase performance.




Function


A function is a named PL/SQL Block like as the procedure, and a Function must always return a value. Using CREATE FUNCTION statement to create a standalone stored function or a call specification. A stored function (also called a user function or user defined function) is a set of PL/SQL statements you can call by name. stored functions are very similar to procedures, except that a function returns a value to the environment in which it is called. User functions can be used as part of a SQL expression.


Syntax of create function

Create (or replace) Function function_name[parameters]
    Return return_datatype;
Is
    Declaration_part
Begin
    Execution_part
    Return return_variable;
Exeception
    Exeception_part
    Return return_variable;
End;

Return Type: The header section defines the return type of the fuction. The return data type can be any of the data type like varchar, number etc.




Cursors


Cursors are the most common and important terms in terms of database terminology. It is a core database programing concepts, which forms a basic unit of execution of SQL statement. A cursor is created temporary work area in the system memory when a SQL statement is executed. A cursor holds information on a select statement and the row of data accessed by it. There are two types of Cursors in PL/SQL. Implicit Cursors: These are created by default when DML statement like, Insert, Update, and Delete command executed. Explicit Cursors: this is created when Select command executed and that return more than one row.

Cursor Execution Cycle:

1: Open Stage
2: Fetch Stage
3: Close Stage

 




Exception Handling


PL/SQL has a feature to handle the Exceptions which are occurs in a PL/SQL Block and this feature called exception Handling. Using this Exception Handling you can test the code and avoid it from exiting shortly. When an exception occur messages which explains its cause is received. Exception message in PL/SQL blocks consists of three parts.

1: Type of Exception
2: An Error Code
3: A message




Attribute Data types


Attribute Data type is column data type. Attribute Data types is to inherit the specification of database to program variable of PL/SQL. Attribute Data type is built on pointer concepts to receive the specification of database columns into PL/SQL for the variables. Attribute Data type is work on dynamic memory allocation, which improve the purpose of program with in usage of memory.


%type attribute: %type attribute provides the data type of a variables or database column. Attribute Data type isused to declare the scalar PL/SQL variables. Its syntax is Tablename.columnname%type;

Example:

Declare
    A table1.emp_no%type;
    B table1.emp_name%type;
    C table1.emp_sal%type;
    D table1.Dept_no%type;
Begin
Select emp_name, emp_sal, dept_no, into B, C, D from table1 where emp_no=&A;
    Dbms_output.put_line(B);
    Dbms_output.put_line(C);
    Dbms_output.put_line(D);
End;


% rowtype attribute:

Its syntax is Variablename Tablename %rowtype;

Example:

Declare
    A table1%rowtype;
Begin
Select *into A from Table1 where empno=&empno;
    Dbms_output.put_line(A.emp_name);
    Dbms_output.put_line(A.emp_sal);
    Dbms_output.put_line(A.dept_no);
End;




Embedded SQL


Embedded SQL is a technique of joining the computing power of a programming language and the database management capabilities of SQL. Embedded SQL statements are SQL statements are written inline with the program source code of the host language. Embedded SQL provides environments to develop application programs. The main idea behind embedded SQL is to allow statement in a program written in high level programing language like C, C++.


Example of Embedded SQL

Declare
   A number;
   B number;
   C number;
   D varchar2(10);
Begin
Select emp_name, dept_name, emp_sal into B, C, D from table_emp where emp_no=&A;
   Dbms_output.put_line(B);
   Dbms_output.put_line(C);
   Dbms_output.put_line(D);
End;




Control Statements


If we need to check Some relation or condition between two or more than two variable or expressions than we use conditional statements. Every Programing languages supports this conditional statements, these are.

Simple if

If-then-else

Nested if

Switch case


1: Simple if

Syntax:

If (Condition) then
Statement1;
Statement2; End if;

In PL/SQL every if condition should end with END IF Statement.


2: If-then-else

Syntax:

If (Condition) then
Statement1;
Else
Statement2;
End if;


3: Nested if

Syntax:

If (Condition) then
If (Condition) then
If (Condition) then
Statement1;
Else
Statement2;
End if;
Else Statement3; End if; Else Statement4; End if;

 


4: Switch case

 




Blocks


A PL/SQL compilation and run time system is an engine that compiles and executes PL/SQL blocks and programs. That engine installed in an Oracle server or in application development tool. The Pl/SQL engine accepts as input any valid blocks or program. The PL/SQL engine processing an anonymous block, and PL/SQL engine executes procedural but sends SQL statements to the SQL engine in the Oracle Database.

Block: Block is grouped code or set of statement, the blocks are two types.

1: Anonymous block or Un Named PL/SQL Blocks

2: Stored sub program or Named PL/SQL Blocks


Monday, 28 September 2015



Architecture


Architecture of PL/SQL

A PL/SQL compilation and run time system is an engine that compiles and executes PL/SQL blocks and programs. That engine installed in an Oracle server or in application development tool. The Pl/SQL engine accepts as input any valid blocks or program. The PL/SQL engine processing an anonymous block, and PL/SQL engine executes procedural but sends SQL statements to the SQL engine in the Oracle Database.

Architecture of PL/SQL




What is PL/SQL


PL/SQL stands for procedural Language extension of SQL. PL/SQL is the combination of the SQL along with the some procedural features of programing language. The PL/SQL is the developed by the ORACLE Corporation for improving the ability of the SQL.

Main Features of the PL/SQL

1: It Combine the Data manipulating power of SQL with the power of procedural Language.
2: We can define, variable, Procedures, and functions in Pl/SQL.
3: We can break complex problems into easily understandable procedural code.
4: Code can be reused for multiple applications.

There are many advantage of the PL/SQL

Block Structures
Procedural Language Capability
Better Performance
Error handling
Portable and Transaction Processing Language




Subquery


A Subquery is a query inside a query. In Oracle, you can make sub queries inside your main statements. The Outside query is called as main query and inner query is called as subquery.

These subqueries can exist in the WHERE clause, the From Clause and the SELECT clause, A subquery is basically a select statement which is used instead of another statement.

1: WHERE clause: Most frequently subquery will be start with the WHERE clause. These subqueries are also called Nested subqueries. There are 255 sub-queries in oracle.

2: FORM clause: Subqueries are also found in the FORM clause. These are called inline views.

3: SELECT clause:




Index


An index is a performance-tuning method of allowing faster retrieval of records. Indexes are optional structures associated with tables and clusters that allow SQL statements to execute more quickly against a table.
An index creates an entry for each value that appears in the indexed columns. By default, by default, Oracle creates B-tree indexes.

There are many types of indexes in Oracle all designed for different circumstances:




Sequence


A Sequence is a database object that generates unique numbers; mostly Sequence is used for the primary key values. A Sequence is an object in oracle database that used to generates the number Sequence and this number Sequence useful when you need to create a unique number which act as primary key.

The Sequence of number can be generates in either ascending or descending order.


Syntax:

Create sequence<sequence_name> increment by <integer> start with<integer>maxvalue <integer> minvalue<integer>cache<integer>;

CACHE: Cache the specified number of sequence values into buffer in the SGA. This speed access, but it lost when database shutdown. The default values is 20 and we give maximum value=maxvalue - minvalue.


Example:

Create sequence seq_1 minvalue1 maxvalue 99 start with 1 increment by 1 cache 20;

OR

Create sequence seq_2 increment by 1 start with 1 maxvalue 1000 minvalue 1 cache 20;

 




Synonyms


A Synonym is a substitute name for an object in database. A Synonym is an alias name for object such as table.

Friday, 25 September 2015



View


A View is object consisting of stored query, it doesn’t contain data. Views are logical tables of data extracted from existing tables. A view can be thought of as a stored query or virtual table; we can views in most places where a table can be used.

A View is a method of organizing table data a specified need and View are baesd on SELECT statements, which derive their data real tables.

Use of View in oracle

1: It is used for hiding sensitive columns.

2: It is used for hiding complex queries which is involving multiple tables.

3: Views can be created with check option and prevents the updating of other rows and columns.

4: Views can be offer an extra level of table security by limiting to a predetermined set of rows and/or columns of a table.

5: Views isolate applications from changes in definitions of base tables.

6: View provides data in a different side than of a base table by renaming columns without affecting the base table.


Syntax:

Create or replace view view_name as sql_query;


Example

Create or replace view view_1 as select e_name, e_dept from table_1;


Type of Views

1: Simple Views

2: Complex Views

3: Read-only Views

4: Inline Views

5: Force Views


What is a Materialized View?

It is a database object that stores the results of a query, and it can be stored in the same database as its base table or different database. Materialized views stored in the same database as their base tables can improve query performance through query rewrites. Query rewrites are particularly useful in a data warehouse environment.

Materialized view give the indirect access to table data by storing the results of a query in a distinct schema object. Not like as ordinary view, which is does not take up any storage space or contain any data.

The existence of a materialized view is transparent to SQL, but when used for query rewrites will improve the performance of SQL execution. In updatable materialized view you can insert, update, and delete the data.


Features of Materialized View

1: In can be partitioned and indexed

2: Can be queried directly

3: Can have DML applied against it

4: Several refresh options are available

5: Best in read-intensive environments




Table Partitioning


Dividing the large table into different smaller part is known as the table partitioning and partitioned table can stored in the different table.

There are many advantages of Table Partitioning.

Increases the performance of servers and we can retrieve data from existing table easily.
Backup/Recovery operation is easy for DBA.

Note: We can divide the table into different part only with the during the creation of the table. Once table can create it is not possible to dividing the table in to different part. It means that unpartition the table cannot be partition.

There are various type of partitions technique supported by oracle.

1: Range Partition

2: Hash Partition

3: List Partition

4: Composite Partition


1: Range Partition: In this type of partition we can divide the table based on some range, generaly we can divide into numeric part.

Syntax

Create table table_name(colum1 datatype(size), colum2 datatype(size), -------- column datatype(size) ) partition by range(column_name) (partition partition_name values less than (value) ----- partition partition_name values less than (value));

Example:

Create table table1(emp_id number(5), emp_name varchar2(20), emp_sal number(6)) partition by range (sal)(partition p1 values less than (5000), partition p2 values less than (10000));

Syntax to retrieve the data from specific partition

Select * from table_name partition (partition_name);
Select * from table1 partition (p1);
Select * from table1 partition (p2);


2: Hash Partition:Hash partitioning is a partitioning method where a hash key is used to distribute rows consistently across the different partitions of table. This is usually used where ranges aren't appropriate.
The hash Partitioning is a best choice than range partition when.
You do not know beforehand how much data will map into a given range.
Sizes of range partition would differ quite substantially.

Example:

create table table1 ( emp_id number(4), emp_name varchar2(30),emp_sal number(6)) partition by hash(emp_id) ( partition p1 tablespace emp1, partition p2 tablespace emp2, partition p3 tablespace emp3);


3: List Partition: List partitioning is a partitioning method where we specify a list of separate values for the partitioning key in the description for each partition.

Example:

create table table1(emp_id number(3), emp_name varchar2(15), join_month varchar2(10)) partition by list(join_month) (partition p1 values(‘jan’,’fab’,’march’,’apr’), partition p1 values(‘may’,’jun’,’jul’,’aug’), partition p1 values(‘sep’,’oct’,’nov’,’dec’);




Cross join


A cross join is a Cartesian product in database.

Syntax and Example of Cross Join

We have Two given table name table1 and table2 and how the cross join.

Table1

Table2

Cross Join of These tables

select * from table1,table2; (non ansi type)
select * from table1 cross join table2; (ANSI type)

Output of non ansi type Cross Join


Output of ansi type Cross Join





Self Join


If any table join to itself then it is called self join.



Outer Join



There are three type of outer join i.e. Left, right and full outer join. These are given with example.

We have Two given table name table1 and table2, and use it for examples

Table1

Table2


Left outer join

You can use to join two tables, in tis join you will get matching values from given two tables and also you can get un-matched value s from left side table.

Example:

select * from table1 left outer join table2 on table1.dept_name=table2.dept_name;
or
select * from table1,table2 where table1.dept_name=table2.dept_name(+);

Output of left outer join 1st second method


Output of left outer join 2nd second method


 

Right outer join

in tis join you will get matching values from given two tables and also you can get un-matched value s from right side table.

Example:

select * from table1 right outer join table2 on table1.dept_name=table2.dept_name;
or
select * from table1,table2 where table1.dept_name(+) =table2.dept_name;

Output of right outer join 1st second method


Output of right outer join 2nd second method


Full outer join

In this join you will get matching values from given two tables and also you can join two datasets from left-to-right and right-to-left.

Example:

select * from table1,table2 where table1.dept_name=table2.dept_name;
or
select * from table1,table2 where table1.dept_name =table2.dept_name(+) union select * from table1,table2 where table1.dept_name(+) =table2.dept_name;

Output of Full outer join 1st second method


Output of Full outer join 2nd second method





Natural Join


A natural join will join two datasets on all matching column names, regardless of whether the columns are actually related in anything other than name.


Example: Table1 and table2 share common column name and natural join between two tables

Table1

Table2

select * from table1 natural join table2;


Output of natural join





non-equi join


In this join we can use any relational operator except to equal to operator in the where clause in the substring.

The main advantage of non-equi join is, even though there is no common columns between the tables we can perform join operation.



Equi Join (Inner Join)


In this join where the rows and column are matching or values are matching only those will be display as output. In this join we need to equal to operator in the where clause of select string.

Suppose we have two tables table1 and table2 in our database the we apply Equi join or Inner join in both table

These are two tables

Table1

Table2

These are two methods to join these two table

Syntax:

   select * from table1 table2 where table1.dept_name=table2.dept_name;

select table1.emp_id,table1.emp_name,table1.salary,table2.adress from table1 inner join table2 using(dept_name);

select * from table1 inner join table2 using(dept_name);




JOIN


Joins are a mechanism which is used to combine or merge one or more than one table at a time.

Some time your information may not complete in a single table then at this particular situation we need to combine the table with one another. Join are mainly divided into following type.

1: Equi/Inner/Simple Join

2: Non-Equi join

3: Natural Join

4: Outer Join

Left Outer Join

Right Outer Join

Full Outer Join

5: Self Join

6: Cross Join/Cross Product/ Cartesian Product

Tuesday, 22 September 2015



Check Constraints


A Check Constraints allows an entered value to be checked against a set of defined conditions.

You can check student average marks between 0 and 60, and employee present in a year in days between 0 and 250. You can check your answer is either yes or no.


Example of Check Constraints


create table student(s_id number(10), s_name varchar2(15), status number(3) constraint st check(status=’pt’or status=’ft’));




FOREIGN KEY Constraints




create table student(Roll_no number(10) primary key, Student_name varchar2(20), Dept_name varchar2(5));

insert into student(Roll_no, Student_name, Dept_name) values (1001,'jhon','cse');
insert into student(Roll_no, Student_name, Dept_name) values (1002,'smith','it');
insert into student(Roll_no, Student_name, Dept_name) values (1003,'willy','me');
 

create table player(Roll_no number(10)references student(roll_no),Student_name varchar2(20), collage_name varchar2(20), game_name varchar2(5));



PRIMARY KEY Constraints


Example:

create table student(Roll_no number(10) primary key, Student_name varchar(20), Dept_name varchar(5));




UNIQUE KEY Constraints


 

create table student(Roll_no number(10) Unique, Student_name varchar(20), Dept_name varchar(5));

insert into student(Roll_no, Student_name, Dept_name) values(10001,'jhon','cse')
insert into student(Roll_no, Student_name, Dept_name) values(10002,'hari','it')
insert into student(Roll_no, Student_name, Dept_name) values(10001,'raju','ME')
insert into student(Roll_no, Student_name, Dept_name) values(null,'raju','ME')




NOT NULL Constraints.


Example:

create table student(Roll_no number(10) Not Null, Student_name varchar(20))

insert into student values(Student_name) values( 'student2')

 




Constraint


In the Oracle implements the concepts of Constraint

What is Constraint?

A Constraint is a statement that describes some features of our data which is store in the Database.

When a Constraint is validate and enabled then database does not allow entering the data which is making statement to be false.
All the Constraint is stored in the data dictionary.

The Constraint also prevents the deletion of a table if there are any dependencies from the other table. Constraints enforce rules on the data whenever a row is inserted, updated, or deleted from a table. There are various type of Constraints.

1: NOT NULL Constraints

2: UNIQUE KEY Constraints

3: PRIMARY KEY Constraints

4: FOREIGN KEY Constraints

5: CHECK Constraints




Functions


Functions is sub program which is used to perform some operations

Functions are classified into two type:

1: System Defined Functions 2: User Defined Functions

System Defined Functions A Functions defined by the system is called system Defined Functions.

User Defined Functions A Functions defined by the user is called User Defined Functions.

In Oracle there are three types of Functions.

1: Single Row Functions: Single Row Functions return a value for every row that is processed in a query.

2: Group Functions: The Group functions are the group of rows of data based on the values returned by the query.

The Group Functions are used to calculate aggregate values like total or average, which return just one total or one average values after processing a group of rows.

Group Functions or Multiple Row Functions These are classified into following type

1. SUM()

2. AVG()

3. MIN()

4. MAX()

5. COUNT()

3: Null Functions: These functions are used on NULL values.

1: Single Row Functions

2: Numeric Functions

3: Character Function

4: Date Functions

5: Conversion Functions

Null Functions: These functions are used on NULL values (NVL)

NVL Function ( NVL() ) This Function is used in cases where we want to consider Null values as Zero.

Example:

NVL(expression1, expression2)

If expression1 is null NVL will return expression2. If expression2 is null NVL will return expression1.

If expression1 and 2 to the data type of expression1 and then compares it.

Select empno, nvl(deptno, 0)from emp;
Select empno, nvl(comm, 0)from emp;

Null values and zeros are not equivalent.


Monday, 21 September 2015



Data Control Languages


Data Control Languages are used to organize the database objects.

Data Control Languages is used to control the kind of a data access to the database. Data Control Languages has two commands.

Grant: This command gives right and privileges on database objects or schema.

Revoke: This commands remove the restrict user right or privileges on database objects.




Transaction Control Language


Statement used to manage the changes by DML statements and it allows statements to be grouped together into transactions. In Transaction Control Language contains two commands.

1: Commit: it make durable changes done in the data.

2: Rollback: It restores data to its state prior to user changes.

 

COMMIT Command: it makes changes permanently.

Example:

 

create table student(Roll_no number(10) , Student_name varchar2(20), Dept_name varchar2(5));
Commit;

ROLLBACK Commands: undo any changes made since transaction began.

Example:

 

create table student(Roll_no number(10) , Student_name varchar2(20), Dept_name varchar2(5));
Rollback;

 




Data Manipulating Language (DML)


This sub language is used to manipulating within the table like storing, updating, deleting and modifying. This Command contains the Four commands.

1: INSERT
2: SELECT
3: UPDATE
4: DELETE

1: SELECT:

This Command is used to retrieve the record from existing table.

* using this command we can retrieve all the record and also retrieve the specific record (using where clause).

Syntax:

Select * from table_name;

2: INSERT:

This command is used to insert record into the existing table: Using this command we can insert the record into the table by two methods.

1: Explicit Type.

2: Implicit Type.

1: Explicit Type: In this method, if user need to insert all the values in all the column, user cannot left any column.

Syntax:

insert into table_name values (val1, val2,val3…….valn);

Example:

create table student(Roll_no number(10) , Student_name varchar2(20), Dept_name varchar2(5));

Example:

insert into student values(1100,’Jhon’,’cse’);

Last values in table Student inserted;

2:Implicit Type: In this method we can enter the values at the required column.

Syntax:

Insert into table_name (col1,col2…coln) values (val1,val2….valn);

Syntax:

Insert into student(roll_no,dept_name)values(1200,’ME’);

.

Last values in table Student inserted;

Note: If we do not enter any column in the table then column automatically take NULL. NULL means no values and it is not equal to ZERO or SPACE.

3: UPDATE:

This Command is used to modify the data in the table. By using this command we can modify all the record in the table and also some specific record in the table(by using where clause).

Syntax:

update table_name set column name=value;

Example:

update student set student_name='raju';

Update command using where clause; by using where clause we can update any specific data.

.
Syntax:

update table_name set column_name=value where column_name=value;

Example:

update student set student_name=’jhon’ where roll_no=1003;

If we want to mare column update at a time.

.
Syntax:

update table_name set col1=value,col2=value------coln=value;

Example:

Update student set roll_no=1111,Student_name=’jhon’;

4: DELETE:

This command is used to delete the record in existing table. By using this command we can delete all the record and any specific record from the table (by using the where clause).

Syntax:

Delete from table name;

Example:

Delete form table1




Data Definition Language (DDL)


This is first Sub Language of SQL which is used to defining the Database object like Table. View, Procedure, Function, and Trigger etc. in this sub language has predefine syntax for describing the data.

Data Definition Language (DDL) is used for create, altering, renaming and deleting the schema object from. This Sub Language Contains 5 Commands. Those are

1: CREATE

2: ALTER

3: RENAME

4: TRUNCATE

5: DROP

CREATE:

This Command is used to create Database object such as table, view, synonyms etc.

Syntax:

create table table_name (column_1 datatype(size), column_2 datatype(size), column_3 datatype(size)…… column_n datatype(size));

The Example of CREATE Commands

create table student(Roll_no number(10) , Student_name varchar2(20), Dept_name varchar2(5));

Rules for creating table:

Table must start with an alphabet and it contains minimum one and maximum 30 character, it does not allows space or any other special character such as _,#,$,0-9 numbers.
Oracle does not allow the reserve or data type in table names or columns name.

A Table has minimum 1 and maximum 1000 columns (from the oracle 9i onwards) A table can store minimum 0 record and maximum n numbers of records (capacity of HDD).

ALTER:

This Command is used to modify the structure of the table.
Using this command we can perform 4 different operations on the table.

ALTER-MODIFY

This Command is used to increase or decrease the size of the column or we can change the data type of column.

Syntax:

Alter table table_name modify column name datatype(size);

Exmple:

Alter table student modify(student_name char(20));

ALTER-ADD

This Command is used to Add one or more than one column in table.

ALTER-RENAME

This Command is used to change the column name and also table name.

ALTER-DROP

This Command is used to remove the column from the exiting table.

RENAME:

This command is used to change the table name.
Syntax:

Rename old_table_name to new_table_name;

Example:

Rename student to scholar;

TRUNCATE:

This command is used to delete te record from the existing table permanently.

DROP:

This command is used to remove the table form the database.

Syntax:

Drop table table_name;

Example:

Drop table student;

NOTE:
Other DDL commands FLASHBACK Command PURGE Command



The structured Query Language is divided in to Four sub Language these are:

1: Data Definition Language.

2: Data Manipulating Language.

3: Transaction Control language.

4: Data Control Language.

Each sub Language has our own commands and each Sub language is responsible for our own work.

For Example Data Definition Language is responsible for the define the Database Object such as create table and number of column and number of rows in a table and wich data type in which row. And the Data Manipulating Language give option to inserting deleting the values in table.




Operators in SQL


Operators in SQL Operator are the some special symbols which perform some operations on operands. There are various type of Operators

1: Arithmetic Operators: The Arithmetic Operators manipulate the numeric operands.

2: Character Operators

3: Logical Operators

4: Comparison Operators

5: Set Operators




Data types in Oracle Data Base


A Data Type represents the which type of Data stores in memory.

1: Numeric Data types:This Data type is allows to enter numeric values such as integer or decimal value.
This Data type is further divided into type

1: Number (size):This data type allows us to enter integer values i.e. +ve or –ve. Suppose if we need to enter the Employee id or student serial no the then we use this type of data type.

2: Number (p,s): This Data type allows us to enter decimal values like average marks, Employee Salary then we use this datatype. Here P represents the precession and S represents scale.

2: Alphabets: This Data type allows us to enter character values, such as Employee name, Student name etc.
1: Char(size)
2: varchar(size)
3: Varchar2(size)

1: Char(size) This Data type is allows us to enter character values such as Student name, employee name etc. the maximum size of this data type is 1 to 2000 character and it always allocate the memory in static fashion.

Student_name char(20);

2/3: varchar(size) /Varchar2(size): These two data type also allows us to enter character values and the maximumsize of the these data type is 1 to 4000 character and it always allocated the memory in dynamic fashion.

Note: The difference between the varchar and Varchar2 data type is varchar data type is developed by along with SQL whereas varchar2 data type is developed by Oracle Corporation.

Date: This data type is allowes us to enter date values in database such as employee joining date. And the default formate of date in SQL is DD-MM-YY The range of date formate in oracle data base is 1- JAN-4712BC to 31-DEC-9999 AD

Timestamp: This data type allowes us to enter both date and time the default formate of timestamp is DD-MM-YY HH:MM:SS



Introduction of the SQL (Structured Query Language)


The Language Structured English Query Language (SEQUAL), and later SEQUEL becomes SQL.

The SQL is common language interface because SQL is only language to communicate with all type of databases such as DB2, Teradata, Oracle, etc


SQL (Structured Query Language) is used for communicating the database. It is a non-procedural language. According to ANSI (American National Standard Institute) it is the regular language for relational Database Management System. SQL is used to perform many tasks such as data retrieve, update, insert etc. in database.

Language Structured English Query Language (SEQUAL), SEQUEL later becomes SQL.

There is many features of SQL

1: It is a Non-Procedural Language.

2: It is not case sensitive language means that we can write the sql command either capital or small latter and mixed also.

3: Every commands in SQL ends with ;.

4: It is also called Natural language Interface (NLI) because every commands in SQL in similar to English language.

5: SQL is common language interface because SQL is only language to communicate with all type of databases such as DB2, Teradata, Oracle, etc.


Friday, 18 September 2015



Third Noramal Form


Unnormalized Table

In this Unnormalized Table EMP_ID is primary key, inthis table ZIP code related with CITY and STREET so in Table2 has EMP_ZIP is the primary key

Table1

Table2




Second Noramal Form


Unnormalized Table

After converting into 2nd normal Form we have two table these are given below.

Table 1

Table 2




First Normal form


A table is called First Normal form when each cell of the table contains precisely one value if we want to converting table into First Normal form there are some properties.

There is no any repeating group in the table.

Must have a unique primary key

Example

In this Unnormalized Table EMP_ID is the primery key

Unnormalized Table

Table in First Normal form




NORMALIZATION


Breaking a complex table structures into simple table structures by using some specific rules is called normalization.

Why we need the normalization?

1:It reduces the redundancy in a table.
2: Reduce the complex user view to a set of small and stable sub groups by this method we can design a logical data model this is also called conceptual data model.
3: During the modification no need of reorganization of data.

The most important and widely used normalization forms are.

1:First Normal form

2: Second Normal form

3: Third Normal form

4: BCNF (Boyce - Codd Normal form)

Different Levels of normalization

Different Levels of Normalization




Entity-Relationship Diagram

An entity is an object or thought about which you want to store information in database.

Entity-Relational Model considers the real world consisting of a set of basic objects and that objects is called entity. And this shows the logical structure of database.

Entity-Relationship Diagram is a graphical structure of a database. Showing this graphical structure we use some special symbol that’s given.

Symbol Name
Symbol
Description
Rectangle   

Represents entity sets

Eclipses   
Represents attributes
Diamonds    
Represents relationship sets
Lines      Links attributes to entity sets and entity sets to relationship
Double rectangle    
Represents weak entity sets
Double eclipses   
Represents Multivalued attributes
Dashed eclipses    
Represents derived attributes
Double lines       Represents total participation of an entity in a relationship set



RDBMS (Relational DataBase Management System)


The Relational Model is introduced by a German Scientist Dr. E.F. Codd in 1970 on Mathematical concept known as relational Algebra.

Dr. E.F. Codd provides some Laws for Fully Functional Relational Database Management System these are given.

1: Relational Database Management A Relational database management system uses only its relational experiences to manage the data in his database.

2: Information Representation

3: Logical Accessibility.

4: Insert, update and delete

5: Representation of Null values

6: Catalog facilities

7: Data Language

8: View updatability

9: Physical data independence

10: Logical data independence

11: Database Distribution

12: Non Subversion

13: Integrity Constraints




Object Oriented Model


The Object Oriented Model is based on collection of objects. An object contains values stored in instance variable within the object.
An object also contains bodies of code that operate on the object. These bodies of code are called methods objects that contain the same type of values and the same methods are grouped together into classes.

Advantages of Object Oriented Model

1:Applications require less code.

2: Application use more natural data model.

3: It provides higher performance management of objects and complex interrelationship between objects.

4: Object Oriented features improve productivity.

5: Data access is easy.




Object Relational Model


The Combination of objects infrastructure and set of relational is called as Object Relational Model.

Object Relational System combines the advantages of OOPs concepts and Relational Database features such as multiple view of data and high-level, non-procedural query language.

There are many Object Relational system available in market are DB2, oracle 9 and later, SQL server 7 etc.




Relational File Model


The Relational Model is introduced by a German Scientist Dr. E.F. Codd in 1970 on Mathematical concept known as relational Algebra. In relational model represents data in the form of two dimension table. Each table represents the real world object or thing. The management of data into relational model is known as the logical view of the database.

The examples of relational model databases are Oracle, Microsoft SQL Server, MySQL, Sybase etc.

There are some features of relational model.

1: The relational model removed all parent child relationships and instead characterizes all data in the database as simple row/column tables of a data values.

2: A relation is similar to a table row /columns of data values.

3: Each table is an independent entity and there is no physical relationship between tables.

4: relational model is bsed on set theory.

5: Most data management system based on the relational model take support of query languages. These query language are in simple English language.




Network Model


This Network Model support only the one-to-one and one-to-many type only.

These are advantges of the Network Model.

1: The basic object in this model are data items, data Aggregates, records, and Sets.

2: This Network Model is improvement on the previous model (Hierarchical Model).

3: In Network Model maintain multiple parent child relationship.




Hierarchical Model


The hierarchical Model is introduced in the Information Management System(IMS) Devloped by IBM in 1968.

This hierarchical Model is like as a tree structure, used to construct a hierarchical record in the form of set of nodes and edges. The Relationship beetwen among data have parent-child.

This hierarchical model database is widely used in the first main frame database management system.

There are many advantages and disadvantages of hierarchical model database.

Advantages

1: Ease to maintain and updates.

2: High speed of access to large database

3: Simplicity

4: Data Security

Disadvantages

1: Implementation Complexity: A hierarchical model database is simple but complex to implement.

2: Database management problems

3: Lack of structural independence


Thursday, 17 September 2015



Flat file Model


A Flat file is a Plain Text or mixed text and binary file which usually contains one record per line the single field can be separated by commas or other delimiters.




The Database Model


The Database Model is known as the relational structure of Database method of storing, managing and manipulating the data that mode is said to database model.

These are some common Database base models are given.

1:Flat file Model

2:hierarchical Model

3:Network Model

4:Relational Model

5:Object Relational Model

6:Object Oriented Model

Nowadays the relational model is the very famous.




Need of Database


These are some basic need of database

1: The main goal of DBMS is to provide an effective environment to use in retrieving and storing database information.

2: Database systems are designed to manage large bodies of information.

3: The database system provides the safety of the information stored, despite system crashes or attempts at unauthorized access and if data is shared among several user the n system must maintain consistency.




Concept of Database


What is Database ?

Database is a group of data. It holds information about one particular enterprise. A database management system contains of a collection of interrelated data and set of programs to access that data.

Or

 

Database is a Collection of information that is given by any enterprise. that can be process those through one or more application program by multiple user.

This enterprise may be individual or a complete corporation.




About the oracle Database


An Oracle database is a group of data which is treated as a single component. The main purpose of database is to storing and retrieving the.

The Oracle Database stores data logically in the form of table and in the form of data files ("datafiles"). Tables can contain numerous types of memory sections, such as Data sections, Index sections, etc. This Memory section in the one or more levels. Extents comprise groups of contiguous data blocks. Data blocks from the basic units of data storage.




ORACLE DATABASE


About the oracle

Oracle Database is most famous Database Management System. It is a most famous RDBMS (Relational Database Management System) from the Oracle Corporation. The oracle database originally developed by Larry Ellison and his two friends and former co-workers, Bob Miner and Ed Oates in the year 1977. Oracle DB is one of the most reliable and widely-used relational database engines.

The Oracle Database stores data logically in the form of table and in the form of data files ("datafiles"). Tables can contain numerous types of memory sections, such as Data sections, Index sections, etc. This Memory section in the one or more levels. Extents comprise groups of contiguous data blocks. Data blocks form the basic units of data storage.