SlideShare a Scribd company logo
Swapnali Pawar
Swapnali Pawar
View
• Views are known as logical tables.They represent the data of
one of more tables.A view derives its data from the tables on
which it is based.
• These tables are called base tables.Views can be based on
actual tables or another view also.
• Whatever DML operations you performed on a view they
actually affect the base table of the view.You can treat views
same as any other table.You can Query, Insert, Update and
delete from views, just as any other table.
• Views are very powerful and handy since they can be
treated just like any other table but do not occupy the space
of a table.
Swapnali Pawar
View Example
Swapnali Pawar
View
1.A view is a virtual table based on result set of an
SQL statement
2.A view contains rows & cols just like table.The fields
in a view are fields from one or more real tables in
database
3.You can add SQL functions with where & join
statements to a view & present the data as if data
coming from single table
Swapnali Pawar
Swapnali Pawar
Advantages of View
1.To Restrict Data Access
2.To make Complex Query Easy
3.To Provide Data Independence
4.To present different views of same
data
Swapnali Pawar
Types of View
1.Simple View-Creating view from single table
2.ComplexView-Creating Complex view with
more than one table in order to make query easier
Swapnali Pawar
2.ComplexView-
Swapnali Pawar
Features SimpleView ComplexView
No. Of Tables 1 1 or More
Contain Function No Yes
Contain Groups of
Data
No Yes
DML Operations
through a view
Yes NotAlways
Swapnali Pawar
CreatingViews
Syntax
CREATE VIEW view_name
AS SELECT columns
FROM tables [WHERE conditions];
Example-
CREATEVIEW [Brazil Customers] AS
SELECT CustomerName, ContactName
FROM Customers
WHERE Country = 'Brazil';
Swapnali Pawar
SQL Updating a View
A view can be updated with the CREATE OR
REPLACE VIEW statement.
SQL CREATE OR REPLACE VIEW
Syntax-
CREATE OR REPLACE VIEW view_name AS
SELECT column1, column2, ...
FROM table_name
WHERE condition;
Swapnali Pawar
Example
CREATE OR REPLACE VIEW StudView AS
SELECT Name, City, Marks
FROM Students
WHERE City =‘Karad'
Swapnali Pawar
SQL DROPVIEW Syntax
DROP VIEW view_name;
The following SQL drops the “StudentView" view
Example-
DROP VIEW StudentView;
Swapnali Pawar
1.Create table-
create table student(id int,name varchar(20),marks
float);
2.Describe table-
describe student;
3.InsertValues inTable-
insert into student values(1,'Swapnali',75);
insert into student values(2,'Sanchita',95);
insert into student values(3,'Paras',99);
4.DisplayValues-
select*from student;
SimpleView Query Execution
Swapnali Pawar
5. CreateView on StudentTable-
create view StudView as
select name,marks from student
where marks>20
6. DescribeView-
desc studview;
7. Display contents of view-
select*from Studview;
NAME MARKS
Sanchita 95
Swapnali 75
Paras 99
Swapnali Pawar
8.ModifyView
create or replace view StudView as
select id,marks,name from student where
marks>25;
9.Display ModifiedView
select*from StudView;
ID MARKS NAME
2 95 Sanchita
1 75 Swapnali
3 99 Paras
Swapnali Pawar
10.Complex view- create 1 more table
create table department(id int,dname
varchar(30));
11.DesscribeTable-
desc department;
12.Insert Some Records-
insert into department values(3,'MS');
13.DisplayTable-select*from department;
ID DNAME
1 CSE
2 MCA
3 MS
ComplexView Query Execution
Swapnali Pawar
14.Complex view creation
Create view StuDeptView as
Select s.id,s.name,s.marks,d.dname from student
s,Department d
where s.id=d.id;
15.DescribeView-
Desc StuDeptView ;
Column Null? Type
ID - NUMBER
NAME - VARCHAR2(20)
MARKS - FLOAT(126)
DNAME-VARCHAR2(30)
16.DisplayView-
Select * from StuDeptView ;
ID NAME MARKS DNAME
1 Swapnali 75 CSE
2 Sanchita 95 MCA
3 Paras 99 MS
Swapnali Pawar
17.DropView-
Drop view StudView;
Drop view StuDeptView;
Swapnali Pawar
Index in SQL
Swapnali Pawar
• Indexes are special lookup tables that the database search engine can use
to speed up data retrieval. Simply put, an index is a pointer to data in a
table.An index in a database is very similar to an index in the back of a
book.
• For example, if you want to reference all pages in a book that discusses a
certain topic, you first refer to the index, which lists all the topics
alphabetically and are then referred to one or more specific page
numbers.
• An index helps to speed up SELECT queries andWHERE clauses, but it
slows down data input, with the UPDATE and the INSERT statements.
Indexes can be created or dropped with no effect on the data.
• Creating an index involves the CREATE INDEX statement, which allows
you to name the index, to specify the table and which column or columns
to index, and to indicate whether the index is in an ascending or
descending order.
• Indexes can also be unique, like the UNIQUE constraint, in that the index
prevents duplicate entries in the column or combination of columns on
which there is an index
CREATE INDEX
Swapnali Pawar
•Index is a database object that makes data retrieval faster
•Eg-Textbook Index
•Index is created on column & that column is called index
key
•Types of Index are-
Swapnali Pawar
1.Unique Index-
When primary key or unique key is defined
for a database table a unique index is created
automatically by oracle Server.eg-Btree
2.Non-Unique Index-
Users can define non-unique index on
table to speedup the access
Eg- Bitmap index
Types of Index are-
Swapnali Pawar
1.BTREE Index-BalancedTree Index
Tree structure
If you want to execute search on marks then you can create Index on Marks so that
faster search results will be displayed
BTREE index id default Index
Index Nodes-Nodes with left & right pointers called Index nodes
Data Nodes-Leaf nodes called data nodes which actually contains data & rowid that
is physical address of data
Swapnali Pawar
Btree Indexing
Swapnali Pawar
BTree Index Query Execution
• Create index Idx1 on Employee(name);
• Set auto trace on; //To check Execution Plan
• Select*from Employee where name=“”Swapnali;
• Create unique Index idxName on
Student(roll_no);
• If Index is not present then oracle uses full table scan.
• Linear search is used on table if Index is not created.
• If Index is present then oracle uses Index Scan.
Swapnali Pawar
Btree Index Creation
1.CreateTable-
create table Swapnali_Mart(pid int,pname varchar(20),pcategory
varchar(20),pCost float);
TABLE SWAPNALI_MARTResult Set 1
Column Null? Type
PID - NUMBER
PNAME - VARCHAR2(20)
PCATEGORY - VARCHAR2(20)
PCOST - FLOAT(126)
2.InsertValues-
insert into Swapnali_Mart values(1,'Pen','Stationary',10);
insert into Swapnali_Mart values(2,'TV','Electronics',50000);
insert into Swapnali_Mart values(3,'Mobile','Electronics',15000);
insert into Swapnali_Mart values(3,'Laptop','Electronics',75000);
PID PNAME PCATEGORY PCOST
3 Laptop Electronics 75000
2 TV Electronics 50000
3 Mobile Electronics 15000
1 Pen Stationary 10
Swapnali Pawar
3.Index Creation-
create index I1 on Swapnali_Mart(pid);
4.Check Excecution Path-
set autotrace on;
5.Display Query based on Index-
select pid,pname,pcategory from Swapnali_Mart where pid>0;
PID PNAME PCATEGORY
1 Pen Stationary
2 TV Electronics
3 Laptop Electronics
3 Mobile Electronics
Btree Index Creation
Swapnali Pawar
Bitmap index
• Bitmaps also called as bit arrays. It is a data structure which uses sequence
of bits to store information.
• Bitmap Usually consumes lot less memory.CPU cost is very low in bitmap
index
• To index columns with low cardinality bitmap index is used.
• Cardinality means uniqueness. Cardinality told how unique data is.
• When cardinality is high it is not advised to use Bitmap Indexing.
• When cardinality is low means data is repeated Bitmap Indexing can be
used.
F-Female Cardinality is 2
M-Male
Syntax
Create Bitmap Index GenderIdx on
Employee(gender);
Swapnali Pawar
Bitmap index
Swapnali Pawar
Roll_No Name Gender
101 Swapnali F
102 Sanchita F
103 Paras M
104 Pankaj M
105 Rupali F
106 Apurva F
107 Vishal M
108 Shivani F
•Female = 11001101
•Male = 00110010
Cardinality=2
Swapnali Pawar
Bitmap Index Creation
create bitmap index bitSwapMartIndex
on
Swapnali_Mart(pcategory);
SQL> set autotrace on;
SQL> set timing on;
To Check Execution Plan
use this commands before
searching query on index
Swapnali Pawar
DROP INDEX Statement
The DROP INDEX statement is used to delete an
index in a table.
DROP INDEX index_name;
Swapnali Pawar
Student Activity
1.Create Studname_product view from BigMart
table
2.Update view set price of Pen==10 where
brand=Lexi
3.Create new view with your name & Drop that
view
4.Create Index on StudentTable
5.Create bitmap Index on EmployeeTable
Swapnali Pawar
Swapnali Pawar
Ad

More Related Content

What's hot (20)

SQL - DML and DDL Commands
SQL - DML and DDL CommandsSQL - DML and DDL Commands
SQL - DML and DDL Commands
Shrija Madhu
 
Sql Constraints
Sql ConstraintsSql Constraints
Sql Constraints
I L0V3 CODING DR
 
SQL Joins.pptx
SQL Joins.pptxSQL Joins.pptx
SQL Joins.pptx
Ankit Rai
 
Joins And Its Types
Joins And Its TypesJoins And Its Types
Joins And Its Types
Wings Interactive
 
introdution to SQL and SQL functions
introdution to SQL and SQL functionsintrodution to SQL and SQL functions
introdution to SQL and SQL functions
farwa waqar
 
SQL Constraints
SQL ConstraintsSQL Constraints
SQL Constraints
Randy Riness @ South Puget Sound Community College
 
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with ExamplesDML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
LGS, GBHS&IC, University Of South-Asia, TARA-Technologies
 
Sql joins
Sql joinsSql joins
Sql joins
Gaurav Dhanwant
 
Sql – Structured Query Language
Sql – Structured Query LanguageSql – Structured Query Language
Sql – Structured Query Language
pandey3045_bit
 
PL/SQL Introduction and Concepts
PL/SQL Introduction and Concepts PL/SQL Introduction and Concepts
PL/SQL Introduction and Concepts
Bharat Kalia
 
Trigger
TriggerTrigger
Trigger
VForce Infotech
 
Sql operators & functions 3
Sql operators & functions 3Sql operators & functions 3
Sql operators & functions 3
Dr. C.V. Suresh Babu
 
SQL
SQLSQL
SQL
Shunya Ram
 
SQL Commands
SQL Commands SQL Commands
SQL Commands
Sachidananda M H
 
Sql views
Sql viewsSql views
Sql views
arshid045
 
Mysql
MysqlMysql
Mysql
TSUBHASHRI
 
PostgreSQL Database Slides
PostgreSQL Database SlidesPostgreSQL Database Slides
PostgreSQL Database Slides
metsarin
 
Chapter 4 Structured Query Language
Chapter 4 Structured Query LanguageChapter 4 Structured Query Language
Chapter 4 Structured Query Language
Eddyzulham Mahluzydde
 
joins in database
 joins in database joins in database
joins in database
Sultan Arshad
 
SQL Queries
SQL QueriesSQL Queries
SQL Queries
Nilt1234
 

Similar to View & index in SQL (20)

SQL WORKSHOP::Lecture 13
SQL WORKSHOP::Lecture 13SQL WORKSHOP::Lecture 13
SQL WORKSHOP::Lecture 13
Umair Amjad
 
[Www.pkbulk.blogspot.com]dbms10
[Www.pkbulk.blogspot.com]dbms10[Www.pkbulk.blogspot.com]dbms10
[Www.pkbulk.blogspot.com]dbms10
AnusAhmad
 
1_SQL_11_13_Notes_on_how_to_gain_knowledge.ppt
1_SQL_11_13_Notes_on_how_to_gain_knowledge.ppt1_SQL_11_13_Notes_on_how_to_gain_knowledge.ppt
1_SQL_11_13_Notes_on_how_to_gain_knowledge.ppt
consravs
 
INTRODUCTION TO SQL QUERIES REALTED BRIEF
INTRODUCTION TO SQL QUERIES REALTED BRIEFINTRODUCTION TO SQL QUERIES REALTED BRIEF
INTRODUCTION TO SQL QUERIES REALTED BRIEF
VADAPALLYPRAVEENKUMA1
 
Les13
Les13Les13
Les13
arnold 7490
 
Les12
Les12Les12
Les12
Vijay Kumar
 
Vertica-Database
Vertica-DatabaseVertica-Database
Vertica-Database
Chakraborty Navin
 
Data Definition Language Commands in DBMS
Data Definition Language Commands in DBMSData Definition Language Commands in DBMS
Data Definition Language Commands in DBMS
agrawalmonikacomp
 
Physical Design and Development
Physical Design and DevelopmentPhysical Design and Development
Physical Design and Development
Er. Nawaraj Bhandari
 
Sql server T-sql basics ppt-3
Sql server T-sql basics  ppt-3Sql server T-sql basics  ppt-3
Sql server T-sql basics ppt-3
Vibrant Technologies & Computers
 
SQL
SQLSQL
SQL
Surendra Shukla
 
Sql wksht-2
Sql wksht-2Sql wksht-2
Sql wksht-2
Mukesh Tekwani
 
PL/SQL New and Advanced Features for Extreme Performance
PL/SQL New and Advanced Features for Extreme PerformancePL/SQL New and Advanced Features for Extreme Performance
PL/SQL New and Advanced Features for Extreme Performance
Zohar Elkayam
 
Oracle vs. SQL Server- War of the Indices
Oracle vs. SQL Server- War of the IndicesOracle vs. SQL Server- War of the Indices
Oracle vs. SQL Server- War of the Indices
Kellyn Pot'Vin-Gorman
 
Introduction to Oracle Database.pptx
Introduction to Oracle Database.pptxIntroduction to Oracle Database.pptx
Introduction to Oracle Database.pptx
SiddhantBhardwaj26
 
Database development coding standards
Database development coding standardsDatabase development coding standards
Database development coding standards
Alessandro Baratella
 
Module08
Module08Module08
Module08
guest5c8fba1
 
Module08
Module08Module08
Module08
Sridhar P
 
DDL(Data defination Language ) Using Oracle
DDL(Data defination Language ) Using OracleDDL(Data defination Language ) Using Oracle
DDL(Data defination Language ) Using Oracle
Farhan Aslam
 
Microsoft SQL Server Filtered Indexes & Sparse Columns Feb 2011
Microsoft SQL Server Filtered Indexes & Sparse Columns Feb 2011Microsoft SQL Server Filtered Indexes & Sparse Columns Feb 2011
Microsoft SQL Server Filtered Indexes & Sparse Columns Feb 2011
Mark Ginnebaugh
 
SQL WORKSHOP::Lecture 13
SQL WORKSHOP::Lecture 13SQL WORKSHOP::Lecture 13
SQL WORKSHOP::Lecture 13
Umair Amjad
 
[Www.pkbulk.blogspot.com]dbms10
[Www.pkbulk.blogspot.com]dbms10[Www.pkbulk.blogspot.com]dbms10
[Www.pkbulk.blogspot.com]dbms10
AnusAhmad
 
1_SQL_11_13_Notes_on_how_to_gain_knowledge.ppt
1_SQL_11_13_Notes_on_how_to_gain_knowledge.ppt1_SQL_11_13_Notes_on_how_to_gain_knowledge.ppt
1_SQL_11_13_Notes_on_how_to_gain_knowledge.ppt
consravs
 
INTRODUCTION TO SQL QUERIES REALTED BRIEF
INTRODUCTION TO SQL QUERIES REALTED BRIEFINTRODUCTION TO SQL QUERIES REALTED BRIEF
INTRODUCTION TO SQL QUERIES REALTED BRIEF
VADAPALLYPRAVEENKUMA1
 
Data Definition Language Commands in DBMS
Data Definition Language Commands in DBMSData Definition Language Commands in DBMS
Data Definition Language Commands in DBMS
agrawalmonikacomp
 
PL/SQL New and Advanced Features for Extreme Performance
PL/SQL New and Advanced Features for Extreme PerformancePL/SQL New and Advanced Features for Extreme Performance
PL/SQL New and Advanced Features for Extreme Performance
Zohar Elkayam
 
Oracle vs. SQL Server- War of the Indices
Oracle vs. SQL Server- War of the IndicesOracle vs. SQL Server- War of the Indices
Oracle vs. SQL Server- War of the Indices
Kellyn Pot'Vin-Gorman
 
Introduction to Oracle Database.pptx
Introduction to Oracle Database.pptxIntroduction to Oracle Database.pptx
Introduction to Oracle Database.pptx
SiddhantBhardwaj26
 
Database development coding standards
Database development coding standardsDatabase development coding standards
Database development coding standards
Alessandro Baratella
 
DDL(Data defination Language ) Using Oracle
DDL(Data defination Language ) Using OracleDDL(Data defination Language ) Using Oracle
DDL(Data defination Language ) Using Oracle
Farhan Aslam
 
Microsoft SQL Server Filtered Indexes & Sparse Columns Feb 2011
Microsoft SQL Server Filtered Indexes & Sparse Columns Feb 2011Microsoft SQL Server Filtered Indexes & Sparse Columns Feb 2011
Microsoft SQL Server Filtered Indexes & Sparse Columns Feb 2011
Mark Ginnebaugh
 
Ad

More from Swapnali Pawar (20)

Unit 3 introduction to android
Unit 3 introduction to android Unit 3 introduction to android
Unit 3 introduction to android
Swapnali Pawar
 
Unit 1-Introduction to Mobile Computing
Unit 1-Introduction to Mobile ComputingUnit 1-Introduction to Mobile Computing
Unit 1-Introduction to Mobile Computing
Swapnali Pawar
 
Unit 2.design mobile computing architecture
Unit 2.design mobile computing architectureUnit 2.design mobile computing architecture
Unit 2.design mobile computing architecture
Swapnali Pawar
 
Introduction to ios
Introduction to iosIntroduction to ios
Introduction to ios
Swapnali Pawar
 
Fresher interview tips demo
Fresher interview tips demoFresher interview tips demo
Fresher interview tips demo
Swapnali Pawar
 
Introduction to android
Introduction to androidIntroduction to android
Introduction to android
Swapnali Pawar
 
Android Introduction
Android IntroductionAndroid Introduction
Android Introduction
Swapnali Pawar
 
SQL JOINS
SQL JOINSSQL JOINS
SQL JOINS
Swapnali Pawar
 
Unit 2.design computing architecture 2.1
Unit 2.design computing architecture 2.1Unit 2.design computing architecture 2.1
Unit 2.design computing architecture 2.1
Swapnali Pawar
 
Unit 2 Design mobile computing architecture MC1514
Unit 2 Design mobile computing architecture MC1514Unit 2 Design mobile computing architecture MC1514
Unit 2 Design mobile computing architecture MC1514
Swapnali Pawar
 
Design computing architecture ~ Mobile Technologies
Design computing architecture ~ Mobile TechnologiesDesign computing architecture ~ Mobile Technologies
Design computing architecture ~ Mobile Technologies
Swapnali Pawar
 
Exception Handling
Exception Handling Exception Handling
Exception Handling
Swapnali Pawar
 
Mobile technology-Unit 1
Mobile technology-Unit 1Mobile technology-Unit 1
Mobile technology-Unit 1
Swapnali Pawar
 
Mobile Technology 3
Mobile Technology 3Mobile Technology 3
Mobile Technology 3
Swapnali Pawar
 
Web Programming& Scripting Lab
Web Programming& Scripting LabWeb Programming& Scripting Lab
Web Programming& Scripting Lab
Swapnali Pawar
 
Mobile Technology
Mobile TechnologyMobile Technology
Mobile Technology
Swapnali Pawar
 
Mobile Technology
Mobile TechnologyMobile Technology
Mobile Technology
Swapnali Pawar
 
Database Management System 1
Database Management System 1Database Management System 1
Database Management System 1
Swapnali Pawar
 
web programming & scripting 2
web programming & scripting 2web programming & scripting 2
web programming & scripting 2
Swapnali Pawar
 
web programming & scripting
web programming & scriptingweb programming & scripting
web programming & scripting
Swapnali Pawar
 
Unit 3 introduction to android
Unit 3 introduction to android Unit 3 introduction to android
Unit 3 introduction to android
Swapnali Pawar
 
Unit 1-Introduction to Mobile Computing
Unit 1-Introduction to Mobile ComputingUnit 1-Introduction to Mobile Computing
Unit 1-Introduction to Mobile Computing
Swapnali Pawar
 
Unit 2.design mobile computing architecture
Unit 2.design mobile computing architectureUnit 2.design mobile computing architecture
Unit 2.design mobile computing architecture
Swapnali Pawar
 
Fresher interview tips demo
Fresher interview tips demoFresher interview tips demo
Fresher interview tips demo
Swapnali Pawar
 
Introduction to android
Introduction to androidIntroduction to android
Introduction to android
Swapnali Pawar
 
Unit 2.design computing architecture 2.1
Unit 2.design computing architecture 2.1Unit 2.design computing architecture 2.1
Unit 2.design computing architecture 2.1
Swapnali Pawar
 
Unit 2 Design mobile computing architecture MC1514
Unit 2 Design mobile computing architecture MC1514Unit 2 Design mobile computing architecture MC1514
Unit 2 Design mobile computing architecture MC1514
Swapnali Pawar
 
Design computing architecture ~ Mobile Technologies
Design computing architecture ~ Mobile TechnologiesDesign computing architecture ~ Mobile Technologies
Design computing architecture ~ Mobile Technologies
Swapnali Pawar
 
Mobile technology-Unit 1
Mobile technology-Unit 1Mobile technology-Unit 1
Mobile technology-Unit 1
Swapnali Pawar
 
Web Programming& Scripting Lab
Web Programming& Scripting LabWeb Programming& Scripting Lab
Web Programming& Scripting Lab
Swapnali Pawar
 
Database Management System 1
Database Management System 1Database Management System 1
Database Management System 1
Swapnali Pawar
 
web programming & scripting 2
web programming & scripting 2web programming & scripting 2
web programming & scripting 2
Swapnali Pawar
 
web programming & scripting
web programming & scriptingweb programming & scripting
web programming & scripting
Swapnali Pawar
 
Ad

Recently uploaded (20)

Vitamins Chapter-7, Biochemistry and clinical pathology, D.Pharm 2nd year
Vitamins Chapter-7, Biochemistry and clinical pathology, D.Pharm 2nd yearVitamins Chapter-7, Biochemistry and clinical pathology, D.Pharm 2nd year
Vitamins Chapter-7, Biochemistry and clinical pathology, D.Pharm 2nd year
ARUN KUMAR
 
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Library Association of Ireland
 
Unit 5: Dividend Decisions and its theories
Unit 5: Dividend Decisions and its theoriesUnit 5: Dividend Decisions and its theories
Unit 5: Dividend Decisions and its theories
bharath321164
 
Open Access: Revamping Library Learning Resources.
Open Access: Revamping Library Learning Resources.Open Access: Revamping Library Learning Resources.
Open Access: Revamping Library Learning Resources.
Rishi Bankim Chandra Evening College, Naihati, North 24 Parganas, West Bengal, India
 
Diabetic neuropathy peripheral autonomic
Diabetic neuropathy peripheral autonomicDiabetic neuropathy peripheral autonomic
Diabetic neuropathy peripheral autonomic
Pankaj Patawari
 
Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025
Mebane Rash
 
One Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learningOne Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learning
momer9505
 
High Performance Liquid Chromatography .pptx
High Performance Liquid Chromatography .pptxHigh Performance Liquid Chromatography .pptx
High Performance Liquid Chromatography .pptx
Ayush Srivastava
 
Studying Drama: Definition, types and elements
Studying Drama: Definition, types and elementsStudying Drama: Definition, types and elements
Studying Drama: Definition, types and elements
AbdelFattahAdel2
 
Timber Pitch Roof Construction Measurement-2024.pptx
Timber Pitch Roof Construction Measurement-2024.pptxTimber Pitch Roof Construction Measurement-2024.pptx
Timber Pitch Roof Construction Measurement-2024.pptx
Tantish QS, UTM
 
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Celine George
 
Introduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe EngineeringIntroduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe Engineering
Damian T. Gordon
 
SPRING FESTIVITIES - UK AND USA -
SPRING FESTIVITIES - UK AND USA            -SPRING FESTIVITIES - UK AND USA            -
SPRING FESTIVITIES - UK AND USA -
Colégio Santa Teresinha
 
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar RabbiPresentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Md Shaifullar Rabbi
 
The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...
Sandeep Swamy
 
GDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptxGDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptx
azeenhodekar
 
Geography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjectsGeography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjects
ProfDrShaikhImran
 
Quality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdfQuality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdf
Dr. Bindiya Chauhan
 
Anti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptxAnti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptx
Mayuri Chavan
 
Handling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptxHandling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptx
AuthorAIDNationalRes
 
Vitamins Chapter-7, Biochemistry and clinical pathology, D.Pharm 2nd year
Vitamins Chapter-7, Biochemistry and clinical pathology, D.Pharm 2nd yearVitamins Chapter-7, Biochemistry and clinical pathology, D.Pharm 2nd year
Vitamins Chapter-7, Biochemistry and clinical pathology, D.Pharm 2nd year
ARUN KUMAR
 
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Library Association of Ireland
 
Unit 5: Dividend Decisions and its theories
Unit 5: Dividend Decisions and its theoriesUnit 5: Dividend Decisions and its theories
Unit 5: Dividend Decisions and its theories
bharath321164
 
Diabetic neuropathy peripheral autonomic
Diabetic neuropathy peripheral autonomicDiabetic neuropathy peripheral autonomic
Diabetic neuropathy peripheral autonomic
Pankaj Patawari
 
Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025
Mebane Rash
 
One Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learningOne Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learning
momer9505
 
High Performance Liquid Chromatography .pptx
High Performance Liquid Chromatography .pptxHigh Performance Liquid Chromatography .pptx
High Performance Liquid Chromatography .pptx
Ayush Srivastava
 
Studying Drama: Definition, types and elements
Studying Drama: Definition, types and elementsStudying Drama: Definition, types and elements
Studying Drama: Definition, types and elements
AbdelFattahAdel2
 
Timber Pitch Roof Construction Measurement-2024.pptx
Timber Pitch Roof Construction Measurement-2024.pptxTimber Pitch Roof Construction Measurement-2024.pptx
Timber Pitch Roof Construction Measurement-2024.pptx
Tantish QS, UTM
 
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Celine George
 
Introduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe EngineeringIntroduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe Engineering
Damian T. Gordon
 
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar RabbiPresentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Md Shaifullar Rabbi
 
The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...
Sandeep Swamy
 
GDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptxGDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptx
azeenhodekar
 
Geography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjectsGeography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjects
ProfDrShaikhImran
 
Quality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdfQuality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdf
Dr. Bindiya Chauhan
 
Anti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptxAnti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptx
Mayuri Chavan
 
Handling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptxHandling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptx
AuthorAIDNationalRes
 

View & index in SQL

  • 3. View • Views are known as logical tables.They represent the data of one of more tables.A view derives its data from the tables on which it is based. • These tables are called base tables.Views can be based on actual tables or another view also. • Whatever DML operations you performed on a view they actually affect the base table of the view.You can treat views same as any other table.You can Query, Insert, Update and delete from views, just as any other table. • Views are very powerful and handy since they can be treated just like any other table but do not occupy the space of a table. Swapnali Pawar
  • 5. View 1.A view is a virtual table based on result set of an SQL statement 2.A view contains rows & cols just like table.The fields in a view are fields from one or more real tables in database 3.You can add SQL functions with where & join statements to a view & present the data as if data coming from single table Swapnali Pawar
  • 7. Advantages of View 1.To Restrict Data Access 2.To make Complex Query Easy 3.To Provide Data Independence 4.To present different views of same data Swapnali Pawar
  • 8. Types of View 1.Simple View-Creating view from single table 2.ComplexView-Creating Complex view with more than one table in order to make query easier Swapnali Pawar
  • 10. Features SimpleView ComplexView No. Of Tables 1 1 or More Contain Function No Yes Contain Groups of Data No Yes DML Operations through a view Yes NotAlways Swapnali Pawar
  • 11. CreatingViews Syntax CREATE VIEW view_name AS SELECT columns FROM tables [WHERE conditions]; Example- CREATEVIEW [Brazil Customers] AS SELECT CustomerName, ContactName FROM Customers WHERE Country = 'Brazil'; Swapnali Pawar
  • 12. SQL Updating a View A view can be updated with the CREATE OR REPLACE VIEW statement. SQL CREATE OR REPLACE VIEW Syntax- CREATE OR REPLACE VIEW view_name AS SELECT column1, column2, ... FROM table_name WHERE condition; Swapnali Pawar
  • 13. Example CREATE OR REPLACE VIEW StudView AS SELECT Name, City, Marks FROM Students WHERE City =‘Karad' Swapnali Pawar
  • 14. SQL DROPVIEW Syntax DROP VIEW view_name; The following SQL drops the “StudentView" view Example- DROP VIEW StudentView; Swapnali Pawar
  • 15. 1.Create table- create table student(id int,name varchar(20),marks float); 2.Describe table- describe student; 3.InsertValues inTable- insert into student values(1,'Swapnali',75); insert into student values(2,'Sanchita',95); insert into student values(3,'Paras',99); 4.DisplayValues- select*from student; SimpleView Query Execution Swapnali Pawar
  • 16. 5. CreateView on StudentTable- create view StudView as select name,marks from student where marks>20 6. DescribeView- desc studview; 7. Display contents of view- select*from Studview; NAME MARKS Sanchita 95 Swapnali 75 Paras 99 Swapnali Pawar
  • 17. 8.ModifyView create or replace view StudView as select id,marks,name from student where marks>25; 9.Display ModifiedView select*from StudView; ID MARKS NAME 2 95 Sanchita 1 75 Swapnali 3 99 Paras Swapnali Pawar
  • 18. 10.Complex view- create 1 more table create table department(id int,dname varchar(30)); 11.DesscribeTable- desc department; 12.Insert Some Records- insert into department values(3,'MS'); 13.DisplayTable-select*from department; ID DNAME 1 CSE 2 MCA 3 MS ComplexView Query Execution Swapnali Pawar
  • 19. 14.Complex view creation Create view StuDeptView as Select s.id,s.name,s.marks,d.dname from student s,Department d where s.id=d.id; 15.DescribeView- Desc StuDeptView ; Column Null? Type ID - NUMBER NAME - VARCHAR2(20) MARKS - FLOAT(126) DNAME-VARCHAR2(30) 16.DisplayView- Select * from StuDeptView ; ID NAME MARKS DNAME 1 Swapnali 75 CSE 2 Sanchita 95 MCA 3 Paras 99 MS Swapnali Pawar
  • 20. 17.DropView- Drop view StudView; Drop view StuDeptView; Swapnali Pawar
  • 22. • Indexes are special lookup tables that the database search engine can use to speed up data retrieval. Simply put, an index is a pointer to data in a table.An index in a database is very similar to an index in the back of a book. • For example, if you want to reference all pages in a book that discusses a certain topic, you first refer to the index, which lists all the topics alphabetically and are then referred to one or more specific page numbers. • An index helps to speed up SELECT queries andWHERE clauses, but it slows down data input, with the UPDATE and the INSERT statements. Indexes can be created or dropped with no effect on the data. • Creating an index involves the CREATE INDEX statement, which allows you to name the index, to specify the table and which column or columns to index, and to indicate whether the index is in an ascending or descending order. • Indexes can also be unique, like the UNIQUE constraint, in that the index prevents duplicate entries in the column or combination of columns on which there is an index CREATE INDEX Swapnali Pawar
  • 23. •Index is a database object that makes data retrieval faster •Eg-Textbook Index •Index is created on column & that column is called index key •Types of Index are- Swapnali Pawar
  • 24. 1.Unique Index- When primary key or unique key is defined for a database table a unique index is created automatically by oracle Server.eg-Btree 2.Non-Unique Index- Users can define non-unique index on table to speedup the access Eg- Bitmap index Types of Index are- Swapnali Pawar
  • 25. 1.BTREE Index-BalancedTree Index Tree structure If you want to execute search on marks then you can create Index on Marks so that faster search results will be displayed BTREE index id default Index Index Nodes-Nodes with left & right pointers called Index nodes Data Nodes-Leaf nodes called data nodes which actually contains data & rowid that is physical address of data Swapnali Pawar
  • 27. BTree Index Query Execution • Create index Idx1 on Employee(name); • Set auto trace on; //To check Execution Plan • Select*from Employee where name=“”Swapnali; • Create unique Index idxName on Student(roll_no); • If Index is not present then oracle uses full table scan. • Linear search is used on table if Index is not created. • If Index is present then oracle uses Index Scan. Swapnali Pawar
  • 28. Btree Index Creation 1.CreateTable- create table Swapnali_Mart(pid int,pname varchar(20),pcategory varchar(20),pCost float); TABLE SWAPNALI_MARTResult Set 1 Column Null? Type PID - NUMBER PNAME - VARCHAR2(20) PCATEGORY - VARCHAR2(20) PCOST - FLOAT(126) 2.InsertValues- insert into Swapnali_Mart values(1,'Pen','Stationary',10); insert into Swapnali_Mart values(2,'TV','Electronics',50000); insert into Swapnali_Mart values(3,'Mobile','Electronics',15000); insert into Swapnali_Mart values(3,'Laptop','Electronics',75000); PID PNAME PCATEGORY PCOST 3 Laptop Electronics 75000 2 TV Electronics 50000 3 Mobile Electronics 15000 1 Pen Stationary 10 Swapnali Pawar
  • 29. 3.Index Creation- create index I1 on Swapnali_Mart(pid); 4.Check Excecution Path- set autotrace on; 5.Display Query based on Index- select pid,pname,pcategory from Swapnali_Mart where pid>0; PID PNAME PCATEGORY 1 Pen Stationary 2 TV Electronics 3 Laptop Electronics 3 Mobile Electronics Btree Index Creation Swapnali Pawar
  • 30. Bitmap index • Bitmaps also called as bit arrays. It is a data structure which uses sequence of bits to store information. • Bitmap Usually consumes lot less memory.CPU cost is very low in bitmap index • To index columns with low cardinality bitmap index is used. • Cardinality means uniqueness. Cardinality told how unique data is. • When cardinality is high it is not advised to use Bitmap Indexing. • When cardinality is low means data is repeated Bitmap Indexing can be used. F-Female Cardinality is 2 M-Male Syntax Create Bitmap Index GenderIdx on Employee(gender); Swapnali Pawar
  • 32. Roll_No Name Gender 101 Swapnali F 102 Sanchita F 103 Paras M 104 Pankaj M 105 Rupali F 106 Apurva F 107 Vishal M 108 Shivani F •Female = 11001101 •Male = 00110010 Cardinality=2 Swapnali Pawar
  • 33. Bitmap Index Creation create bitmap index bitSwapMartIndex on Swapnali_Mart(pcategory); SQL> set autotrace on; SQL> set timing on; To Check Execution Plan use this commands before searching query on index Swapnali Pawar
  • 34. DROP INDEX Statement The DROP INDEX statement is used to delete an index in a table. DROP INDEX index_name; Swapnali Pawar
  • 35. Student Activity 1.Create Studname_product view from BigMart table 2.Update view set price of Pen==10 where brand=Lexi 3.Create new view with your name & Drop that view 4.Create Index on StudentTable 5.Create bitmap Index on EmployeeTable Swapnali Pawar