SlideShare une entreprise Scribd logo
1  sur  36
Télécharger pour lire hors ligne
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

Contenu connexe

Tendances (20)

Aggregate function
Aggregate functionAggregate function
Aggregate function
 
SQL
SQLSQL
SQL
 
Triggers
TriggersTriggers
Triggers
 
MySql slides (ppt)
MySql slides (ppt)MySql slides (ppt)
MySql slides (ppt)
 
Sql commands
Sql commandsSql commands
Sql commands
 
SQL Overview
SQL OverviewSQL Overview
SQL Overview
 
Sql subquery
Sql  subquerySql  subquery
Sql subquery
 
Introduction to-sql
Introduction to-sqlIntroduction to-sql
Introduction to-sql
 
DATABASE CONSTRAINTS
DATABASE CONSTRAINTSDATABASE CONSTRAINTS
DATABASE CONSTRAINTS
 
SQL JOIN
SQL JOINSQL JOIN
SQL JOIN
 
Sql views
Sql viewsSql views
Sql views
 
5. stored procedure and functions
5. stored procedure and functions5. stored procedure and functions
5. stored procedure and functions
 
Oracle Database View
Oracle Database ViewOracle Database View
Oracle Database View
 
Integrity constraints in dbms
Integrity constraints in dbmsIntegrity constraints in dbms
Integrity constraints in dbms
 
SQL Joins.pptx
SQL Joins.pptxSQL Joins.pptx
SQL Joins.pptx
 
Oracle: Joins
Oracle: JoinsOracle: Joins
Oracle: Joins
 
Stored procedure
Stored procedureStored procedure
Stored procedure
 
SQL Basics
SQL BasicsSQL Basics
SQL Basics
 
Sql and Sql commands
Sql and Sql commandsSql and Sql commands
Sql and Sql commands
 
Database Triggers
Database TriggersDatabase Triggers
Database Triggers
 

Similaire à View & index in SQL

SQL WORKSHOP::Lecture 13
SQL WORKSHOP::Lecture 13SQL WORKSHOP::Lecture 13
SQL WORKSHOP::Lecture 13Umair Amjad
 
[Www.pkbulk.blogspot.com]dbms10
[Www.pkbulk.blogspot.com]dbms10[Www.pkbulk.blogspot.com]dbms10
[Www.pkbulk.blogspot.com]dbms10AnusAhmad
 
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 PerformanceZohar 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 IndicesKellyn Pot'Vin-Gorman
 
Introduction to Oracle Database.pptx
Introduction to Oracle Database.pptxIntroduction to Oracle Database.pptx
Introduction to Oracle Database.pptxSiddhantBhardwaj26
 
Database development coding standards
Database development coding standardsDatabase development coding standards
Database development coding standardsAlessandro Baratella
 
DDL(Data defination Language ) Using Oracle
DDL(Data defination Language ) Using OracleDDL(Data defination Language ) Using Oracle
DDL(Data defination Language ) Using OracleFarhan 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 2011Mark Ginnebaugh
 
Optimizer percona live_ams2015
Optimizer percona live_ams2015Optimizer percona live_ams2015
Optimizer percona live_ams2015Manyi Lu
 
Ground Breakers Romania: Explain the explain_plan
Ground Breakers Romania: Explain the explain_planGround Breakers Romania: Explain the explain_plan
Ground Breakers Romania: Explain the explain_planMaria Colgan
 

Similaire à View & index in SQL (20)

SQL WORKSHOP::Lecture 13
SQL WORKSHOP::Lecture 13SQL WORKSHOP::Lecture 13
SQL WORKSHOP::Lecture 13
 
[Www.pkbulk.blogspot.com]dbms10
[Www.pkbulk.blogspot.com]dbms10[Www.pkbulk.blogspot.com]dbms10
[Www.pkbulk.blogspot.com]dbms10
 
Les13
Les13Les13
Les13
 
Les12
Les12Les12
Les12
 
Vertica-Database
Vertica-DatabaseVertica-Database
Vertica-Database
 
Physical Design and Development
Physical Design and DevelopmentPhysical Design and Development
Physical Design and Development
 
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
 
SQL
SQLSQL
SQL
 
Sql wksht-2
Sql wksht-2Sql wksht-2
Sql wksht-2
 
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
 
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
 
Introduction to Oracle Database.pptx
Introduction to Oracle Database.pptxIntroduction to Oracle Database.pptx
Introduction to Oracle Database.pptx
 
Database development coding standards
Database development coding standardsDatabase development coding standards
Database development coding standards
 
Module08
Module08Module08
Module08
 
Module08
Module08Module08
Module08
 
DDL(Data defination Language ) Using Oracle
DDL(Data defination Language ) Using OracleDDL(Data defination Language ) Using Oracle
DDL(Data defination Language ) Using Oracle
 
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
 
Les10
Les10Les10
Les10
 
Optimizer percona live_ams2015
Optimizer percona live_ams2015Optimizer percona live_ams2015
Optimizer percona live_ams2015
 
Ground Breakers Romania: Explain the explain_plan
Ground Breakers Romania: Explain the explain_planGround Breakers Romania: Explain the explain_plan
Ground Breakers Romania: Explain the explain_plan
 

Plus de 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 ComputingSwapnali Pawar
 
Unit 2.design mobile computing architecture
Unit 2.design mobile computing architectureUnit 2.design mobile computing architecture
Unit 2.design mobile computing architectureSwapnali Pawar
 
Fresher interview tips demo
Fresher interview tips demoFresher interview tips demo
Fresher interview tips demoSwapnali Pawar
 
Introduction to android
Introduction to androidIntroduction to android
Introduction to androidSwapnali 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.1Swapnali 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 MC1514Swapnali Pawar
 
Design computing architecture ~ Mobile Technologies
Design computing architecture ~ Mobile TechnologiesDesign computing architecture ~ Mobile Technologies
Design computing architecture ~ Mobile TechnologiesSwapnali Pawar
 
Mobile technology-Unit 1
Mobile technology-Unit 1Mobile technology-Unit 1
Mobile technology-Unit 1Swapnali Pawar
 
Web Programming& Scripting Lab
Web Programming& Scripting LabWeb Programming& Scripting Lab
Web Programming& Scripting LabSwapnali Pawar
 
Database Management System 1
Database Management System 1Database Management System 1
Database Management System 1Swapnali Pawar
 
web programming & scripting 2
web programming & scripting 2web programming & scripting 2
web programming & scripting 2Swapnali Pawar
 
web programming & scripting
web programming & scriptingweb programming & scripting
web programming & scriptingSwapnali Pawar
 

Plus de Swapnali Pawar (20)

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

Dernier

Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIFood Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIShubhangi Sonawane
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701bronxfugly43
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docxPoojaSen20
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfChris Hunter
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 

Dernier (20)

Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIFood Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 

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