Sandeep RDBMS Notes
Sandeep RDBMS Notes
Sandeep RDBMS Notes
2014
Table Of Contents
Database Concept
Overview of DBMS
Database Architecture
Database Model
Codd's rule
RDBMS Concept
Database key
Normalization
E-R Diagrams
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
2014
SQL Concept
SQL Introduction
DDL Command
Create query
Alter query
WHERE clause
SELECT query
LIKE clause
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
ORDER BY clause
Group BY clause
Having clause
DISTINCT keyword
2014
Advance SQL
SQL Constraints
SQL function
SQL Join
SQL Alias
SQL Sequences
SQL Views
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
2014
Overview of Database
A Database is a collection of related data organised in a way that data can be easily accessed, managed and
updated. Any piece of information can be a data, for example name of your school. Database is actualy a place
where related piece of information is stored and various operations can be performed on it.
DBMS
A DBMS is a software that allows creation, definition and manipulation of database. Dbms is actualy a tool used
to perform any kind of operation on data in database. Dbms also provides protection and security to database. It
maintains data consistency in case of multiple users. Here are some examples of popular dbms, MySql, Oracle,
Sybase, Microsoft Access and IBM DB2 etc.
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
2014
Users : Users may be of various type such as DB administrator, System developer and End users.
Database application : Database application may be Personal, Departmental, Enterprise and Internal
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
2014
DBMS : Software that allow users to define, create and manages database access, Ex: MySql, Oracle etc.
Functions of DBMS
Concurrency Control
Provides a clear and logical view of the process that manipulates data.
Advantages of DBMS
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
2014
Disadvantages of DBMS
Complexity
Costly
Large in size
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
2014
Database Architecture
Database architecture is logically divided into two types.
1. Logical two-tier Client / Server architecture
2. Logical three-tier Client / Server architecture
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
2014
Two-tier Client / Server architecture is used for User Interface program and Application Programs that runs on
client side. An interface called ODBC(Open Database Connectivity) provides an API that allow client side
program to call the dbms. Most DBMS vendors provide ODBC drivers. A client program may connect to several
DBMS's. In this architecture some variation of client is also possible for example in some DBMS's more
functionality is transferred to the client including data dictionary, optimization etc. Such clients are called Data
server.
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
2014
Three-tier Client / Server database architecture is commonly used architecture for web applications.
Intermediate layer called Application server or Web Server stores the web connectivty software and the
business logic(constraints) part of application used to access the right amount of data from the database server.
This layer acts like medium for sending partially processed data between the database server and the client.
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
10
2014
Database Model
A Database model defines the logical design of data. The model describes the relationships between different
parts of the data. In history of database design, three models have been in use.
Hierarchical Model
Network Model
Relational Model
Hierarchical Model
In this model each entity has only one parent but can have several children . At the top of hierarchy there is only
one entity which is called Root.
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
11
2014
Network Model
In the network model, entities are organised in a graph,in which some entities can be accessed through sveral
path
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
12
2014
Relational Model
In this model, data is organised in two-dimesional tables called relations. The tables or relation are related to
each other.
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
13
2014
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
14
2014
Codd's Rule
E.F Codd was a Computer Scientist who invented Relational model for Database management. Based on
relational model, Relation database was created. Codd proposed 13 rules popularly known as Codd's 12
rulesto test DBMS's concept against his relational model. Codd's rule actualy define what quality a DBMS
requires in order to become a Relational Database Management System(RDBMS). Till now, there is hardly any
commercial product that follows all the 13 Codd's rules. Even Oracle follows only eight and half out(8.5) of 13.
The Codd's 12 rules are as follows.
Rule zero
This rule states that for a system to qualify as an RDBMS, it must be able to manage database entirely through
the relational capabilities.
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
15
2014
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
16
2014
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
17
2014
18
2014
RDBMS Concepts
A Relational Database management System(RDBMS) is a database management system based on relational
model introduced by E.F Codd. In relational model, data is represented in terms of tuples(rows).
RDBMS is used to manage Relational database. Relational database is a collection of organized set of tables
from which data can be accessed easily. Relational Database is most commonly used database. It consists of
number of tables and each table has its own primary key.
What is Table ?
In Relational database, a table is a collection of data elements organised in terms of rows and columns. A table
is also considered as convenient representation of relations. But a table can have duplicate tuples while a
truerelation cannot have duplicate tuples. Table is the most simplest form of data storage.
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
19
2014
Name
Age
Salary
Adam
34
13000
Alex
28
15000
Stuart
20
18000
Ross
42
19020
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
20
2014
What is a Record ?
A single entry in a table is called a Record or Row. A Record in a table represents set of related data. For
example, the above Employee table has 4 records. Following is an example of single record.
1
Adam
34
13000
What is Field ?
A table consists of several records(row), each record can be broken into several smaller entities known
asFields. The above Employee table consist of four fields, ID, Name, Age and Salary.
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
21
2014
What is a Column ?
In Relational table, a column is a set of value of a particular type. The term Attribute is also used to represent a
column. For example, in Employee table, Name is a column that represent names of employee.
Name
Adam
Alex
Stuart
Ross
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
22
2014
Database Keys
Keys are very important part of Relational database. They are used to establish and identify relation between
tables. They also ensure that each record within a table can be uniquely identified by combination of one or
more fields within a table.
Super Key
Super Key is defined as a set of attributes within a table that uniquely identifies each record within a table.
Super Key is a superset of Candidate key.
Candidate Key
Candidate keys are defined as the set of fields from which primary key can be selected. It is an attribute or set of
attribute that can act as a primary key for a table to uniquely identify each record in that table.
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
23
2014
Primary Key
Primary key is a candidate key that is most appropriate to become main key of the table. It is a key that uniquely
identify each record in a table.
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
24
2014
Composite Key
Key that consist of two or more attributes that uniquely identify an entity occurance is called Composite key. But
any attribute that makes up the Composite key is not a simple key in its own.
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
25
2014
Non-key Attribute
Non-key attributes are attributes other than candidate key attributes in a table.
Non-prime Attribute
Non-prime Attributes are attributes other than Primary attribute.
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
26
2014
Normalization of Database
Database Normalisation is a technique of organizing the data in the database. Normalization is a systematic
approach of decomposing tables to eliminate data redundancy and undesirable characteristics like Insertion,
Update and Deletion Anamolies. It is a multi-step process that puts data into tabular form by removing duplicated
data from the relation tables.
Normalization is used for mainly two purpose,
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
27
2014
S_Name
S_Address
Subject_opted
401
Adam
Noida
Bio
402
Alex
Panipat
Maths
403
Stuart
Jammu
Maths
404
Adam
Noida
Physics
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
28
2014
Updation Anamoly : To update address of a student who occurs twice or more than twice in a table, we will
have to update S_Address column in all the rows, else data will become inconsistent.
Insertion Anamoly : Suppose for a new admission, we have a Student id(S_id), name and address of a
student but if student has not opted for any subjects yet then we have to insert NULL there, leading to
Insertion Anamoly.
Deletion Anamoly : If (S_id) 401 has only one subject and temporarily he drops it, when we delete that row,
entire student record will be deleted along with it.
Normalization Rule
Normalization rule are divided into following normal form.
1. First Normal Form
2. Second Normal Form
3. Third Normal Form
4. BCNF
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
29
2014
Age
Subject
Adam
15
Biology, Maths
Alex
14
Maths
Stuart
17
Maths
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
30
2014
In First Normal Form, any row must not have a column in which more than one value is saved, like separated
with commas. Rather than that, we must separate such data into multiple rows.
Student Table following 1NF will be :
Student
Age
Subject
Adam
15
Biology
Adam
15
Maths
Alex
14
Maths
Stuart
17
Maths
Using the First Normal Form, data redundancy increases, as there will be many columns with same data in
multiple rows but each row as a whole will be unique.
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
31
2014
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
32
2014
Age
Adam
15
Alex
14
Stuart
17
In Student Table the candidate key will be Student column, because all other column i.e Age is dependent on it.
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
33
2014
Subject
Adam
Biology
Adam
Maths
Alex
Maths
Stuart
Maths
In Subject Table the candidate key will be {Student, Subject} column. Now, both the above tables qualifies for
Second Normal Form and will never suffer from Update Anomalies. Although there are a few complex cases in
which table in Second Normal Form suffers Update Anomalies, and to handle those scenarios Third Normal
Form is there.
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
34
2014
Student_name
DOB
Street
city
State
Zip
In this table Student_id is Primary key, but street, city and state depends upon Zip. The dependency between zip
and other fields is called transitive dependency. Hence to apply 3NF, we need to move the street, city and
state to new table, with Zip as primary key.
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
35
2014
Student_name
DOB
Zip
Address Table :
Zip
Street
city
state
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
36
2014
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
37
2014
E-R Diagram
ER-Diagram is a visual representation of data that describes how data is related to each other.
38
2014
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
39
2014
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
40
2014
1) Entity
An Entity can be any object, place, person or class. In E-R Diagram, an entity is represented using rectangles.
Consider an example of an Organisation. Employee, Manager, Department, Product and many more can be
taken as entities from an Organisation.
Weak Entity
Weak entity is an entity that depends on another entity. Weak entity doen't have key attribute of their own.
Double rectangle represents weak entity.
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
41
2014
2) Attribute
An Attribute describes a property or characterstic of an entity. For example, Name, Age, Address etc can be
attributes of a Student. An attribute is represented using eclipse.
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
42
2014
Key Attribute
Key attribute represents the main characterstic of an Entity. It is used to represent Primary key. Ellipse with
underlying lines represent Key Attribute.
Composite Attribute
An attribute can also have their own attributes. These attributes are known as Composite attribute.
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
43
2014
3) Relationship
A Relationship describes relations between entities. Relationship is represented using diamonds.
Binary Relationship
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
44
Recursive Relationship
Ternary Relationship
2014
Binary Relationship
Binary Relationship means relation between two Entities. This is further divided into three types.
1. One to One : This type of relationship is rarely seen in real world.
The above example describes that one student can enroll only for one course and a course will also have
only one Student. This is not what you will usually see in relationship.
2. One to Many : It reflects business rule that one entity is associated with many number of same entity. For
example, Student enrolls for only one Course but a Course can have many Students.
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
45
2014
The arrows in the diagram describes that one student can enroll for only one course.
3. Many to Many :
The above diagram represents that many students can enroll for more than one courses.
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
46
2014
Recursive Relationship
When an Entity is related with itself it is known as Recursive Relationship.
Ternary Relationship
Relationship of degree three is called Ternary relationship.
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
47
2014
Generalization
Generalization is a bottom-up approach in which two lower level entities combine to form a higher level entity.
In generalization, the higher level entity can also combine with other lower level entity to make further higher
level entity.
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
48
2014
Specialization
Specialization is opposite to Generalization. It is a top-down approach in which one higher level entity can be
broken down into two lower level entity. In specialization, some higher level entities may not have lower-level
entity sets at all.
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
49
2014
Aggregration
Aggregration is a process when relation between two entity is treated as a single entity. Here the relation
between Center and Course, is acting as an Entity in relation with Visitor.
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
50
2014
Introduction to SQL
Structure Query Language(SQL) is a programming language used for storing and managing data in RDBMS.
SQL was the first commercial language introduced for E.F Codd's Relational model. Today almost all
RDBMS(MySql, Oracle, Infomix, Sybase, MS Access) uses SQL as the standard database language. SQL is
used to perform all type of data operations in RDBMS.
SQL Command
SQL defines following data languages to manipulate data of RDBMS.
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
51
2014
Description
create
alter
for alteration
truncate
drop
to drop a table
rename
to rename a table
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
52
2014
Description
insert
update
delete
to delete a row
merge
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
53
2014
Description
commit
to permanently save
rollback
to undo change
savepoint
to save temporarily
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
54
2014
Description
grant
revoke
Description
select
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
55
2014
create command
create is a DDL command used to create a table or a database.
Creating a Database
To create a database in RDBMS, create command is uses. Following is the Syntax,
create database database-name;
Creating a Table
create command is also used to create a table. We can specify names and datatypes of various columns
along.Following is the Syntax,
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
56
2014
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
57
2014
alter command
alter command is used for alteration of table structures. There are various uses of alter command, such as,
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
58
2014
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
59
2014
To Rename a column
Using alter command you can rename an existing column. Following is the Syntax,
alter table table-name rename old-column-name to column-name;
Here is an Example for this,
alter table Student rename address to Location;
The above command will rename address column to Location.
To Drop a Column
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
60
2014
alter command is also used to drop columns also. Following is the Syntax,
alter table table-name drop(column-name);
Here is an Example for this,
alter table Student drop(address);
The above command will drop address column from the Student table
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
61
2014
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
62
2014
drop command
drop query completely removes a table from database. This command will also destroy the table structure.
Following is its Syntax,
drop table table-name
Here is an Example explaining it.
drop table Student;
The above query will delete the Student table completely. It can also be used on Databases. For Example, to
drop a database,
drop database Test;
The above query will drop a database named Test from the system.
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
63
2014
rename query
rename command is used to rename a table. Following is its Syntax,
rename table old-table-name to new-table-name
Here is an Example explaining it.
rename table Student to Student-record;
The above query will rename Student table to Student-record.
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
64
2014
DML command
Data Manipulation Language (DML) statements are used for managing data in database. DML commands are
not auto-committed. It means changes made by DML command are not permanent to database, it can be rolled
back.
1) INSERT command
Insert command is used to insert data into a table. Following is its general syntax,
INSERT into table-name values(data1,data2,..)
Lets see an example,
Consider a table Student with following fields.
S_id
S_Name
age
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
65
S_Name
age
101
Adam
15
2014
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
66
2014
The above command will insert only two column value other column is set to null.
S_id
S_Name
age
101
Adam
15
102
Alex
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
67
2014
S_Name
age
101
Adam
15
102
Alex
103
chris
14
Suppose the age column of student table has default value of 14.
Also, if you run the below query, it will insert default value into the age column, whatever the default value may
be.
INSERT into Student values(103,'Chris')
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
68
2014
2) UPDATE command
Update command is used to update a row of a table. Following is its general syntax,
UPDATE table-name set column-name = value where condition;
Lets see an example,
update Student set age=18 where s_id=102;
S_id
S_Name
age
101
Adam
15
102
Alex
18
103
chris
14
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
69
2014
S_Name
age
101
Adam
15
102
Alex
18
103
Abhi
17
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
70
2014
3) Delete command
Delete command is used to delete data from a table. Delete command can also be used with condition to delete
a particular row. Following is its general syntax,
DELETE from table-name;
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
71
2014
S_Name
age
101
Adam
15
102
Alex
18
103
Abhi
17
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
72
2014
The above command will delete the record where s_id is 103 from Student table.
S_id
S_Name
age
101
Adam
15
102
Alex
18
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
73
2014
TCL command
Transaction Control Language(TCL) commands are used to manage transactions in database.These are used to
manage the changes made by DML statements. It also allows statements to be grouped together into logical
transactions.
Commit command
Commit command is used to permanently save any transaaction into database.
Following is Commit command's syntax,
commit;
Rollback command
This command restores the database to last commited state. It is also use with savepoint command to jump to a
savepoint in a transaction.
Following is Rollback command's syntax,
rollback to savepoint-name;
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
74
2014
Savepoint command
savepoint command is used to temporarily save a transaction so that you can rollback to that point whenever
necessary.
Following is savepoint command's syntax,
savepoint savepoint-name;
NAME
abhi
adam
alex
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
75
2014
Lets use some SQL queries on the above table and see the results.
INSERT into class values(5,'Rahul');
commit;
UPDATE class set name='abhijit' where id='5';
savepoint A;
INSERT into class values(6,'Chris');
savepoint B;
INSERT into class values(7,'Bravo');
savepoint C;
SELECT * from class;
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
76
2014
NAME
abhi
adam
alex
abhijit
chris
bravo
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
77
2014
NAME
abhi
adam
alex
abhijit
chris
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
78
2014
NAME
abhi
adam
alex
abhijit
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
79
2014
DCL command
Data Control Language(DCL) is used to control privilege in Database. To perform any operation in the
database, such as for creating tables, sequences or views we need privileges. Privileges are of two
types,
System : creating session, table etc are all types of system privilege.
Object : any command or query to work on tables comes under object privilege.
DCL defines two commands,
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
80
2014
81
2014
column-nameN
from table-name WHERE [condition];
s_Name
age
address
101
Adam
15
Noida
102
Alex
18
Delhi
103
Abhi
17
Rohtak
104
Ankit
22
Panipat
Now we will use a SELECT statement to display data of the table, based on a condition, which we will
add to the SELECT query using WHERE clause.
SELECT s_id,
s_name, age,
address
s_Name
Age
Address
101
Adam
15
Noida
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
82
2014
SELECT Query
Select query is used to retrieve data from a tables. It is the most used SQL query. We can retrieve complete
tables, or partial by mentioning conditions using WHERE clause.
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
83
2014
S_Name
age
address
101
Adam
15
Noida
102
Alex
18
Delhi
103
Abhi
17
Rohtak
104
Ankit
22
Panipat
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
84
2014
The above query will fetch information of s_id, s_name and age column from Student table
S_id
S_Name
age
101
Adam
15
102
Alex
18
103
Abhi
17
104
Ankit
22
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
85
2014
S_Name
age
address
101
Adam
15
Noida
102
Alex
18
Delhi
103
Abhi
17
Rohtak
104
Ankit
22
Panipat
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
86
2014
Abhi
17
Rohtak
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
87
2014
Name
age
salary
101
Adam
26
5000
102
Ricky
42
8000
103
Abhi
22
10000
104
Rohan
35
5000
from Employee;
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
88
2014
The above command will display a new column in the result, showing 3000 added into existing salaries of the
employees.
eid
Name
salary+3000
101
Adam
8000
102
Ricky
11000
103
Abhi
13000
104
Rohan
8000
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
89
2014
Like clause
Like clause is used as condition in SQL query. Like clause compares data with an expression using wildcard
operators. It is used to find similar data from the table.
Wildcard operators
There are two wildcard operators that are used in like clause.
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
90
2014
s_Name
age
101
Adam
15
102
Alex
18
103
Abhi
17
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
91
2014
The above query will return all records where s_name starts with character 'A'.
s_id
s_Name
age
101
Adam
15
102
Alex
18
103
Abhi
17
Example
SELECT * from Student where s_name like = '_d%';
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
92
2014
The above query will return all records from Student table where s_name contain 'd' as second character.
s_id
s_Name
age
101
Adam
15
Example
SELECT * from Student where s_name like = '%x';
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
93
2014
The above query will return all records from Student table where s_name contain 'x' as last character.
s_id
s_Name
age
102
Alex
18
Order By Clause
Order by clause is used with Select statement for arranging retrieved data in sorted order. The Order
by clause by default sort data in ascending order. To sort data in descending order DESC keyword is
used with Order byclause.
Syntax of Order By
SELECT column-list|* from table-name order by asc|desc;
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
94
2014
name
age
salary
401
Anu
22
9000
402
Shane
29
8000
403
Rohan
34
6000
404
Scott
44
10000
405
Tiger
35
8000
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
95
2014
The above query will return result in ascending order of the salary.
eid
name
age
salary
403
Rohan
34
6000
402
Shane
29
8000
405
Tiger
35
8000
401
Anu
22
9000
404
Scott
44
10000
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
96
2014
name
age
salary
404
Scott
44
10000
401
Anu
22
9000
405
Tiger
35
8000
402
Shane
29
8000
403
Rohan
34
6000
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
97
2014
Group By Clause
Group by clause is used to group the results of a SELECT query based on one or more columns. It is also used
with SQL functions to group the result from one or more tables.
Syntax for using Group by in a statement.
SELECT column_name, function(column_name)
FROM table_name
WHERE condition
GROUP BY column_name
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
98
2014
name
age
salary
401
Anu
22
9000
402
Shane
29
8000
403
Rohan
34
6000
404
Scott
44
9000
405
Tiger
35
8000
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
99
2014
Here we want to find name and age of employees grouped by their salaries
SQL query for the above requirement will be,
SELECT name, age
from Emp group by salary
Result will be,
name
age
Rohan
34
shane
29
anu
22
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
100
2014
name
age
salary
401
Anu
22
9000
402
Shane
29
8000
403
Rohan
34
6000
404
Scott
44
9000
405
Tiger
35
8000
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
101
2014
salary
Rohan
6000
Shane
8000
Scott
9000
You must remember that Group By clause will always come at the end, just like the Order by clause.
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
102
2014
HAVING Clause
having clause is used with SQL Queries to give more precise condition for a statement. It is used to mention
condition in Group based SQL functions, just like WHERE clause.
Syntax for having will be,
select column_name, function(column_name)
FROM table_name
WHERE column_name condition
GROUP BY column_name
HAVING function(column_name) condition
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
103
2014
order_name
previous_balance
customer
11
ord1
2000
Alex
12
ord2
1000
Adam
13
ord3
2000
Abhi
14
ord4
1000
Adam
15
ord5
2000
Alex
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
104
2014
Suppose we want to find the customer whose previous_balance sum is more than 3000.
We will use the below SQL query,
SELECT *
from sale group customer
having sum(previous_balance) > 3000
Result will be,
oid
order_name
previous_balance
customer
11
ord1
2000
Alex
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
105
2014
Distinct keyword
The distinct keyword is used with Select statement to retrieve unique values from the table. Distinct removes
all the duplicate records while retrieving from database.
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
106
2014
Example
Consider the following Emp table.
eid
name
age
salary
401
Anu
22
5000
402
Shane
29
8000
403
Rohan
34
10000
404
Scott
44
10000
405
Tiger
35
8000
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
107
2014
The above query will return only the unique salary from Emp table
salary
5000
8000
10000
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
108
2014
AND operator
AND operator is used to set multiple conditions with Where clause.
Example of AND
Consider the following Emp table
eid
name
age
salary
401
Anu
22
5000
402
Shane
29
8000
403
Rohan
34
12000
404
Scott
44
10000
405
Tiger
35
9000
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
109
2014
SELECT * from Emp WHERE salary < 10000 AND age > 25
The above query will return records where salary is less than 10000 and age greater than 25.
eid
name
age
salary
402
Shane
29
8000
405
Tiger
35
9000
OR operator
OR operator is also used to combine multiple conditions with Where clause. The only difference between AND
and OR is their behaviour. When we use AND to combine two or more than two conditions, records satisfying all
the condition will be in the result. But in case of OR, atleast one condition from the conditions specified must be
satisfied by any record to be in the result.
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
110
2014
Example of OR
Consider the following Emp table
eid
name
age
salary
401
Anu
22
5000
402
Shane
29
8000
403
Rohan
34
12000
404
Scott
44
10000
405
Tiger
35
9000
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
111
2014
Shane
29
8000
403
Rohan
34
12000
404
Scott
44
10000
405
Tiger
35
9000
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
112
2014
SQL Constraints
SQl Constraints are rules used to limit the type of data that can go into a table, to maintain the accuracy and
integrity of the data inside table.
Constraints can be divided into following two types,
Constraints are used to make sure that the integrity of data is maintained in the database. Following are the
most used constraints that can be applied to a table.
NOT NULL
UNIQUE
PRIMARY KEY
FOREIGN KEY
CHECK
DEFAULT
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
113
2014
UNIQUE Constraint
UNIQUE constraint ensures that a field or column will only have unique values. A UNIQUE constraint field will
not have duplicate data. UNIQUE constraint can be applied at column level or table level.
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
114
2014
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
115
2014
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
116
2014
Customer_Detail Table :
c_id
Customer_Name
address
101
Adam
Noida
102
Alex
Delhi
103
Stuart
Rohtak
Order_Detail Table :
Order_id
Order_Name
c_id
10
Order1
101
11
Order2
103
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
117
Order3
2014
102
In Customer_Detail table, c_id is the primary key which is set as foreign key in Order_Detail table. The value
that is entered in c_id which is set as foreign key in Order_Detail table must be present
in Customer_Detailtable where it is set as primary key. This prevents invalid data to be inserted into c_id
column of Order_Detailtable.
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
118
2014
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
119
2014
On Delete Cascade : This will remove the record from child table, if that value of foriegn key is deleted from
the main table.
On Delete Null : This will set all the values in that record of child table as NULL, for which the value of
foriegn key is eleted from the main table.
If we don't use any of the above, then we cannot delete data from the main table for which data in child table
exists. We will get an error if we try to do so.
ERROR : Record in child table exist
CHECK Constraint
CHECK constraint is used to restrict the value of a column between a range. It performs check on the values,
before storing them into the database. Its like condition checking before saving data into a column.
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
120
2014
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
121
2014
SQL Functions
SQL provides many built-in functions to perform operations on data. These functions are useful while
performing mathematical calculations, string concatenations, sub-strings etc. SQL functions are divided
into two catagories,
Aggregrate Functions
Scalar Functions
Aggregrate Functions
These functions return a single value after calculating from a group of values.Following are some
frequently used Aggregrate functions.
1) AVG()
Average returns average value after calculating from values in a numeric column.
Its general Syntax is,
SELECT AVG(column_name) from table_name
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
122
2014
name
age
salary
401
Anu
22
9000
402
Shane
29
8000
403
Rohan
34
6000
404
Scott
44
10000
405
Tiger
35
8000
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
123
2014
2) COUNT()
Count returns the number of rows present in the table either based on some condition or without
condition.
Its general Syntax is,
SELECT COUNT(column_name) from table-name
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
124
2014
name
age
salary
401
Anu
22
9000
402
Shane
29
8000
403
Rohan
34
6000
404
Scott
44
10000
405
Tiger
35
8000
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
125
2014
Example of COUNT(distinct)
Consider following Emp table
eid
name
age
salary
401
Anu
22
9000
402
Shane
29
8000
403
Rohan
34
6000
404
Scott
44
10000
405
Tiger
35
8000
126
2014
3) FIRST()
First function returns first value of a selected column
Syntax for FIRST function is,
SELECT FIRST(column_name) from table-name
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
127
2014
Example of FIRST()
Consider following Emp table
eid
name
age
salary
401
Anu
22
9000
402
Shane
29
8000
403
Rohan
34
6000
404
Scott
44
10000
405
Tiger
35
8000
SQL query
SELECT FIRST(salary) from Emp;
Result will be,
first(salary)
9000
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
128
2014
4) LAST()
LAST return the return last value from selected column
Syntax of LAST function is,
SELECT LAST(column_name) from table-name
Example of LAST()
Consider following Emp table
eid
name
age
salary
401
Anu
22
9000
402
Shane
29
8000
403
Rohan
34
6000
404
Scott
44
10000
405
Tiger
35
8000
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
129
2014
5) MAX()
MAX function returns maximum value from selected column of the table.
Syntax of MAX function is,
SELECT MAX(column_name) from table-name
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
130
2014
Example of MAX()
Consider following Emp table
eid
name
age
salary
401
Anu
22
9000
402
Shane
29
8000
403
Rohan
34
6000
404
Scott
44
10000
405
Tiger
35
8000
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
131
2014
6) MIN()
MIN function returns minimum value from a selected column of the table.
Syntax for MIN function is,
SELECT MIN(column_name) from table-name
Example of MIN()
Consider following Emp table,
eid
name
age
salary
401
Anu
22
9000
402
Shane
29
8000
403
Rohan
34
6000
404
Scott
44
10000
405
Tiger
35
8000
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
132
2014
7) SUM()
SUM function returns total sum of a selected columns numeric values.
Syntax for SUM is,
SELECT SUM(column_name) from table-name
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
133
2014
Example of SUM()
Consider following Emp table
eid
name
age
salary
401
Anu
22
9000
402
Shane
29
8000
403
Rohan
34
6000
404
Scott
44
10000
405
Tiger
35
8000
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
134
2014
Scalar Functions
Scalar functions return a single value from an input value. Following are soe frequently used Scalar
Functions.
1) UCASE()
UCASE function is used to convert value of string column to Uppercase character.
Syntax of UCASE,
SELECT UCASE(column_name) from table-name
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
135
2014
Example of UCASE()
Consider following Emp table
eid
name
age
salary
401
anu
22
9000
402
shane
29
8000
403
rohan
34
6000
404
scott
44
10000
405
Tiger
35
8000
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
136
2014
Result is,
UCASE(name)
ANU
SHANE
ROHAN
SCOTT
TIGER
2) LCASE()
LCASE function is used to convert value of string column to Lowecase character.
Syntax for LCASE is,
SELECT LCASE(column_name) from table-name
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
137
2014
Example of LCASE()
Consider following Emp table
eid
name
age
salary
401
anu
22
9000
402
shane
29
8000
403
rohan
34
6000
404
scott
44
10000
405
Tiger
35
8000
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
138
2014
3) MID()
MID function is used to extract substrings from column values of string type in a table.
Syntax for MID function is,
SELECT MID(column_name, start, length) from table-name
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
139
2014
Example of MID()
Consider following Emp table
eid
name
age
salary
401
anu
22
9000
402
shane
29
8000
403
rohan
34
6000
404
scott
44
10000
405
Tiger
35
8000
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
140
2014
4) ROUND()
ROUND function is used to round a numeric field to number of nearest integer. It is used on Decimal
point values. Syntax of Round function is,
SELECT ROUND(column_name, decimals) from table-name
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
141
2014
Example of ROUND()
Consider following Emp table
eid
name
age
salary
401
anu
22
9000.67
402
shane
29
8000.98
403
rohan
34
6000.45
404
scott
44
10000
405
Tiger
35
8000.01
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
142
2014
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
143
2014
Join in SQL
SQL Join is used to fetch data from two or more tables, which is joined to appear as single set of data. SQL Join
is used for combining column from two or more tables by using values common to both tables. Join Keyword is
used in SQL queries for joining two or more tables. Minimum required condition for joining table, is (n-1) wheren,
is number of tables. A table can also join to itself known as, Self Join.
Types of Join
The following are the types of JOIN that we can use in SQL.
Inner
Outer
Left
Right
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
144
2014
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
145
2014
NAME
abhi
adam
alex
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
146
2014
Address
DELHI
MUMBAI
CHENNAI
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
147
2014
NAME
ID
Address
abhi
DELHI
adam
DELHI
alex
DELHI
abhi
MUMBAI
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
148
adam
MUMBAI
alex
MUMBAI
abhi
CHENNAI
adam
CHENNAI
alex
CHENNAI
2014
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
149
2014
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
150
2014
NAME
abhi
adam
alex
anu
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
151
2014
Address
DELHI
MUMBAI
CHENNAI
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
152
2014
NAME
ID
Address
abhi
DELHI
adam
MUMBAI
alex
CHENNAI
Natural JOIN
Natural Join is a type of Inner join which is based on column having same name and same datatype present in
both the tables to be joined.
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
153
2014
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
154
2014
NAME
abhi
adam
alex
anu
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
155
2014
Address
DELHI
MUMBAI
CHENNAI
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
156
2014
NAME
Address
abhi
DELHI
adam
MUMBAI
alex
CHENNAI
In the above example, both the tables being joined have ID column(same name and same datatype), hence the
records for which value of ID matches in both the tables will be the result of Natural Join of these two tables.
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
157
2014
Outer JOIN
Outer Join is based on both matched and unmatched data. Outer Joins subdivide further into,
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
158
2014
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
159
2014
NAME
abhi
adam
alex
anu
ashish
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
160
2014
Address
DELHI
MUMBAI
CHENNAI
NOIDA
PANIPAT
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
161
2014
NAME
ID
Address
abhi
DELHI
adam
MUMBAI
alex
CHENNAI
anu
null
null
ashish
null
null
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
162
2014
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
163
2014
NAME
abhi
adam
alex
anu
ashish
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
164
2014
Address
DELHI
MUMBAI
CHENNAI
NOIDA
PANIPAT
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
165
2014
NAME
ID
Address
abhi
DELHI
adam
MUMBAI
alex
CHENNAI
null
null
NOIDA
null
null
PANIPAT
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
166
2014
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
167
2014
NAME
abhi
adam
alex
anu
ashish
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
168
2014
Address
DELHI
MUMBAI
CHENNAI
NOIDA
PANIPAT
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
169
2014
NAME
ID
Address
abhi
DELHI
adam
MUMBAI
alex
CHENNAI
anu
null
null
ashish
null
null
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
170
null
NOIDA
null
null
PANIPAT
2014
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
171
2014
SQL Alias
Alias is used to give an alias name to a table or a column. This is quite useful in case of large or complex
queries. Alias is mainly used for giving a short alias name for a column or a table with complex names.
Syntax of Alias for table names,
SELECT column-name
from table-name
as alias-name
Following is an Example using Alias,
SELECT * from Employee_detail as ed;
Alias syntax for columns will be like,
SELECT
column-name as alias-name
from
table-name
Example using alias for columns,
SELECT customer_id as cid from Emp;
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
172
2014
Name
abhi
adam
alex
anu
ashish
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
173
2014
Address
DELHI
MUMBAI
CHENNAI
NOIDA
PANIPAT
Below is the Query to fetch data from both the tables using SQL Alias,
SELECT C.id, C.Name, Ci.Address from Class as C, Class_info as Ci where C.id=Ci.id;
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
174
2014
Name
Address
abhi
DELHI
adam
MUMBAI
alex
CHENNAI
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
175
2014
Union
UNION is used to combine the results of two or more Select statements. However it will eliminate duplicate rows
from its result set. In case of union, number of columns and datatype must be same in both the tables.
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
176
2014
Example of UNION
The First table,
ID
Name
abhi
adam
Name
adam
Chester
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
177
2014
NAME
abhi
adam
Chester
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
178
2014
Union All
This operation is similar to Union. But it also shows the duplicate rows.
NAME
abhi
adam
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
179
2014
NAME
adam
Chester
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
180
2014
NAME
abhi
adam
adam
Chester
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
181
2014
Intersect
Intersect operation is used to combine two SELECT statements, but it only retuns the records which are
common from both SELECT statements. In case of Intersect the number of columns and datatype must be
same. MySQL does not support INTERSECT operator.
Example of Intersect
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
182
2014
NAME
abhi
adam
NAME
adam
Chester
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
183
2014
NAME
adam
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
184
2014
Minus
Minus operation combines result of two Select statements and return only those result which belongs to first set
of result. MySQL does not support INTERSECT operator.
Example of Minus
The First table,
ID
NAME
abhi
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
185
2014
adam
NAME
adam
Chester
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
186
2014
NAME
abhi
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
187
2014
SQL Sequence
Sequence is a feature supported by some database systems to produce unique values on demand. Some
DBMS like MySQL supports AUTO_INCREMENT in place of Sequence. AUTO_INCREMENT is applied on
columns, it automatically increments the column value by 1 each time a new record is entered into the table.
Sequence is also some what similar to AUTO_INCREMENT but its has some extra features.
Creating Sequence
Syntax to create sequences is,
CREATE Sequence sequence-name
start with initial-value
increment by increment-value
maxvalue maximum-value
cycle|nocycle
initial-value specifies the starting value of the Sequence, increment-value is the value by which sequence will
be incremented and maxvalue specifies the maximum value until which sequence will increment
itself. cyclespecifies that if the maximum value exceeds the set limit, sequence will restart its cycle from the
begining. No cycle specifies that if sequence exceeds maxvalue an error will be thrown.
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
188
2014
NAME
abhi
adam
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
189
2014
alex
NAME
abhi
adam
alex
anu
Once you use nextval the sequence will increment even if you don't Insert any record into the table.
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
190
2014
SQL View
A view in SQL is a logical subset of data from one or more tables. View is used to restrict data access.
Syntax for creating a View,
CREATE or REPLACE view view_name AS
SELECT column_name(s)
FROM table_name
WHERE condition
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
191
2014
order_name
previous_balance
customer
11
ord1
2000
Alex
12
ord2
1000
Adam
13
ord3
2000
Abhi
14
ord4
1000
Adam
15
ord5
2000
Alex
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
192
2014
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
193
2014
Update a View
Update command for view is same as for tables.
Syntax to Update a View is,
UPDATE view-name
set value
WHERE condition;
If we update a view it also updates base table data automatically.
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
194
2014
Read-Only View
We can create a view with read-only option to restrict access to the view.
Syntax to create a view with Read-Only Access
CREATE or REPLACE force view view_name AS
SELECT column_name(s)
FROM table_name
WHERE condition with read-only
The above syntax will create view for read-only purpose, we cannot Update or Insert data into read-only view. It
will throw an error.
Types of View
There are two types of view,
Simple View
Complex View
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
195
Complex View
Contain functions
2014
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
196
2014
Web : www.issac.meximas.com
Like Us : facebook.com/issac.meximas
197