SlideShare une entreprise Scribd logo
1  sur  5
Télécharger pour lire hors ligne
Mrs. Sunita M Dol
Page 1
Views
We define a view in SQL by using the create view command. To define a view, we must
give the view a name and must state the query that computes the view. The form of the
create view command is
create view v as <query expression>
where <query expression> is any legal query expression. The view name is represented by v.
Create the view faculty which consist of an instructor’s ID, name and department name
select * from instructor;
ID name dept_namesalary
10101SrinivasanComp. Sci. 65000
12121Wu Finance 90000
15151Mozart Music 40000
22222Einstein Physics 95000
32343El Said History 60000
33456Gold Physics 87000
45565Katz Comp. Sci. 75000
58583Califieri History 62000
76543Singh Finance 80000
76766Crick Biology 72000
83821Brandt Comp. Sci. 92000
98345Kim Elec. Eng. 80000
create view faculty as select ID, name, dept_name from instructor;
ID name dept_name
10101SrinivasanComp. Sci.
12121Wu Finance
15151Mozart Music
Mrs. Sunita M Dol
Page 2
ID name dept_name
22222Einstein Physics
32343El Said History
33456Gold Physics
45565Katz Comp. Sci.
58583Califieri History
76543Singh Finance
76766Crick Biology
83821Brandt Comp. Sci.
98345Kim Elec. Eng.
Create a view that lists all course sections offered by the Biology department in the
summer 2017 semester with the building and room number of each section
select * from course;
course_id title dept_name credits
BIO-101 Intro. to Biology Biology 4
BIO-301 Genetics Biology 4
BIO-399 Computational Biology Biology 3
CS-101 Intro. to Computer Science Comp. Sci. 4
CS-190 Game Design Comp. Sci. 4
CS-315 Robotics Comp. Sci. 3
CS-319 Image Processing Comp. Sci. 3
CS-347 Database System Concepts Comp. Sci. 3
EE-181 Intro. to Digital Systems Elec. Eng. 3
FIN-201 Investment Banking Finance 3
HIS-351 World History History 3
MU-199 Music Video Production Music 3
PHY-101 Physical Principles Physics 4
select * from section;
Mrs. Sunita M Dol
Page 3
course_id sec_id semester year building room_number time_slot_id
BIO-101 1 Summer 2017 Painter 514 B
BIO-301 1 Summer 2018 Painter 514 A
CS-101 1 Fall 2017 Packard 101 H
CS-101 1 Spring 2018 Packard 101 F
CS-190 1 Spring 2017 Taylor 3128 E
CS-190 2 Spring 2017 Taylor 3128 A
CS-315 1 Spring 2018 Watson 120 D
CS-319 1 Spring 2018 Watson 100 B
CS-319 2 Spring 2018 Taylor 3128 C
CS-347 1 Fall 2017 Taylor 3128 A
EE-181 1 Spring 2017 Taylor 3128 C
FIN-201 1 Spring 2018 Packard 101 B
HIS-351 1 Spring 2018 Painter 514 C
MU-199 1 Spring 2018 Packard 101 D
PHY-101 1 Fall 2017 Watson 100 A
create view Biology_Summer_2017 as
select course.course_id, sec_id, building, room_number
from course, section
where course.course_id = section.course_id
and course.dept_name = 'Biology'
and section.semester = 'Summer'
and section.year = 2017;
select * from Biology_Summer_2017;
course_idsec_idbuildingroom_number
BIO-101 1 Painter 514
select course_id
from Biology_Summer_2017
Mrs. Sunita M Dol
Page 4
where building= 'Painter';
course_id
BIO-101
Create a view that finds the department-wise total salary
select * from instructor;
ID name dept_namesalary
10101SrinivasanComp. Sci. 65000
12121Wu Finance 90000
15151Mozart Music 40000
22222Einstein Physics 95000
32343El Said History 60000
33456Gold Physics 87000
45565Katz Comp. Sci. 75000
58583Califieri History 62000
76543Singh Finance 80000
76766Crick Biology 72000
83821Brandt Comp. Sci. 92000
98345Kim Elec. Eng. 80000
create view departments_total_salary (dept_name, total_salary) as
select dept_name, sum (salary)
from instructor
group by dept_name;
select * from departments_total_salary
dept_name total_salary
Biology 72000
Mrs. Sunita M Dol
Page 5
Comp. Sci. 232000
Elec. Eng. 80000
Finance 170000
History 122000
Music 40000
Physics 182000
Practice Problem Statements
1. Consider the clerk who needs to access all data in the instructor relation, except
salary. The clerk should not be authorized to access the instructor relation. Create
view relation faculty that can be made available to the clerk,
2. Create a view that lists all course sections offered by the Physics department in the
Fall 2009 semester with the building and room number of each section.
3. Define a view physics_fall_2009_watson that lists the course ID and room number of
all Physics courses offered in the Fall 2009 semester in the Watson building
References:
 Database system concepts by Abraham Silberschatz, Henry F. Korth, S. Sudarshan
(McGraw Hill International Edition) sixth edition.
 Database system concepts by Abraham Silberschatz, Henry F. Korth, S. Sudarshan
(McGraw Hill International Edition) fifth edition.
 http://codex.cs.yale.edu/avi/db-book/db4/slide-dir/
 http://codex.cs.yale.edu/avi/db-book/db5/slide-dir/
 http://codex.cs.yale.edu/avi/db-book/db6/slide-dir/

Contenu connexe

Similaire à 8.Views.pdf

Aminullah assagaf mp2 manajemen proyek
Aminullah assagaf mp2 manajemen proyekAminullah assagaf mp2 manajemen proyek
Aminullah assagaf mp2 manajemen proyek
Aminullah Assagaf
 
Aminullah assagaf mp2 manajemen proyek
Aminullah assagaf mp2 manajemen proyekAminullah assagaf mp2 manajemen proyek
Aminullah assagaf mp2 manajemen proyek
Aminullah Assagaf
 
Scheduling by Primavera - Training
Scheduling by Primavera - TrainingScheduling by Primavera - Training
Scheduling by Primavera - Training
Mohammed Feroze
 
BMIS 325CMS Project Phase II InstructionsIn this phase, you w.docx
BMIS 325CMS Project Phase II InstructionsIn this phase, you w.docxBMIS 325CMS Project Phase II InstructionsIn this phase, you w.docx
BMIS 325CMS Project Phase II InstructionsIn this phase, you w.docx
hartrobert670
 
Appendix  A  Future value in.docx
Appendix  A  Future value in.docxAppendix  A  Future value in.docx
Appendix  A  Future value in.docx
rossskuddershamus
 
Balloon Project Summary
Balloon Project SummaryBalloon Project Summary
Balloon Project Summary
rhlee46
 
Inventor Drawing Assignment
Inventor Drawing AssignmentInventor Drawing Assignment
Inventor Drawing Assignment
P1666
 
Multiviews
MultiviewsMultiviews
Multiviews
P1666
 
Multiviews
MultiviewsMultiviews
Multiviews
P1666
 

Similaire à 8.Views.pdf (20)

43.3 d cob2016
43.3 d cob201643.3 d cob2016
43.3 d cob2016
 
Human Performance AI Enhanced
Human Performance AI EnhancedHuman Performance AI Enhanced
Human Performance AI Enhanced
 
Aminullah assagaf mp2 manajemen proyek
Aminullah assagaf mp2 manajemen proyekAminullah assagaf mp2 manajemen proyek
Aminullah assagaf mp2 manajemen proyek
 
Aminullah assagaf mp2 manajemen proyek
Aminullah assagaf mp2 manajemen proyekAminullah assagaf mp2 manajemen proyek
Aminullah assagaf mp2 manajemen proyek
 
Boeing Undergraduate Case Competition 2016
Boeing Undergraduate Case Competition 2016 Boeing Undergraduate Case Competition 2016
Boeing Undergraduate Case Competition 2016
 
Sales forecasting using sas
Sales forecasting using sasSales forecasting using sas
Sales forecasting using sas
 
Q3 2014 industrial market report
Q3 2014 industrial market reportQ3 2014 industrial market report
Q3 2014 industrial market report
 
Aminullah assagaf mp2 manajemen proyek
Aminullah assagaf mp2 manajemen proyekAminullah assagaf mp2 manajemen proyek
Aminullah assagaf mp2 manajemen proyek
 
Kema switch certified
Kema switch certifiedKema switch certified
Kema switch certified
 
Leveraging data science adaptive intelligence and machine learning in oracle ...
Leveraging data science adaptive intelligence and machine learning in oracle ...Leveraging data science adaptive intelligence and machine learning in oracle ...
Leveraging data science adaptive intelligence and machine learning in oracle ...
 
Scheduling by Primavera - Training
Scheduling by Primavera - TrainingScheduling by Primavera - Training
Scheduling by Primavera - Training
 
BMIS 325CMS Project Phase II InstructionsIn this phase, you w.docx
BMIS 325CMS Project Phase II InstructionsIn this phase, you w.docxBMIS 325CMS Project Phase II InstructionsIn this phase, you w.docx
BMIS 325CMS Project Phase II InstructionsIn this phase, you w.docx
 
Time cost-trade-off
Time cost-trade-offTime cost-trade-off
Time cost-trade-off
 
Appendix  A  Future value in.docx
Appendix  A  Future value in.docxAppendix  A  Future value in.docx
Appendix  A  Future value in.docx
 
Oracle trace data collection errors: the story about oceans, islands, and rivers
Oracle trace data collection errors: the story about oceans, islands, and riversOracle trace data collection errors: the story about oceans, islands, and rivers
Oracle trace data collection errors: the story about oceans, islands, and rivers
 
Balloon Project Summary
Balloon Project SummaryBalloon Project Summary
Balloon Project Summary
 
Inventor Drawing Assignment
Inventor Drawing AssignmentInventor Drawing Assignment
Inventor Drawing Assignment
 
Multiviews
MultiviewsMultiviews
Multiviews
 
Multiviews
MultiviewsMultiviews
Multiviews
 
My Sql
My Sql My Sql
My Sql
 

Plus de Sunita Milind Dol

Plus de Sunita Milind Dol (20)

9.Joins.pdf
9.Joins.pdf9.Joins.pdf
9.Joins.pdf
 
4. DML.pdf
4. DML.pdf4. DML.pdf
4. DML.pdf
 
3. DDL.pdf
3. DDL.pdf3. DDL.pdf
3. DDL.pdf
 
2. SQL Introduction.pdf
2. SQL Introduction.pdf2. SQL Introduction.pdf
2. SQL Introduction.pdf
 
1. University Example.pdf
1. University Example.pdf1. University Example.pdf
1. University Example.pdf
 
Assignment12
Assignment12Assignment12
Assignment12
 
Assignment11
Assignment11Assignment11
Assignment11
 
Assignment10
Assignment10Assignment10
Assignment10
 
Assignment9
Assignment9Assignment9
Assignment9
 
Assignment8
Assignment8Assignment8
Assignment8
 
Assignment7
Assignment7Assignment7
Assignment7
 
Assignment6
Assignment6Assignment6
Assignment6
 
Assignment5
Assignment5Assignment5
Assignment5
 
Assignment4
Assignment4Assignment4
Assignment4
 
Assignment3
Assignment3Assignment3
Assignment3
 
Assignment2
Assignment2Assignment2
Assignment2
 
Assignment1
Assignment1Assignment1
Assignment1
 
Handout#12
Handout#12Handout#12
Handout#12
 
Handout#11
Handout#11Handout#11
Handout#11
 
Handout#10
Handout#10Handout#10
Handout#10
 

Dernier

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
QucHHunhnh
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 

Dernier (20)

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
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
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.
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
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
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 

8.Views.pdf

  • 1. Mrs. Sunita M Dol Page 1 Views We define a view in SQL by using the create view command. To define a view, we must give the view a name and must state the query that computes the view. The form of the create view command is create view v as <query expression> where <query expression> is any legal query expression. The view name is represented by v. Create the view faculty which consist of an instructor’s ID, name and department name select * from instructor; ID name dept_namesalary 10101SrinivasanComp. Sci. 65000 12121Wu Finance 90000 15151Mozart Music 40000 22222Einstein Physics 95000 32343El Said History 60000 33456Gold Physics 87000 45565Katz Comp. Sci. 75000 58583Califieri History 62000 76543Singh Finance 80000 76766Crick Biology 72000 83821Brandt Comp. Sci. 92000 98345Kim Elec. Eng. 80000 create view faculty as select ID, name, dept_name from instructor; ID name dept_name 10101SrinivasanComp. Sci. 12121Wu Finance 15151Mozart Music
  • 2. Mrs. Sunita M Dol Page 2 ID name dept_name 22222Einstein Physics 32343El Said History 33456Gold Physics 45565Katz Comp. Sci. 58583Califieri History 76543Singh Finance 76766Crick Biology 83821Brandt Comp. Sci. 98345Kim Elec. Eng. Create a view that lists all course sections offered by the Biology department in the summer 2017 semester with the building and room number of each section select * from course; course_id title dept_name credits BIO-101 Intro. to Biology Biology 4 BIO-301 Genetics Biology 4 BIO-399 Computational Biology Biology 3 CS-101 Intro. to Computer Science Comp. Sci. 4 CS-190 Game Design Comp. Sci. 4 CS-315 Robotics Comp. Sci. 3 CS-319 Image Processing Comp. Sci. 3 CS-347 Database System Concepts Comp. Sci. 3 EE-181 Intro. to Digital Systems Elec. Eng. 3 FIN-201 Investment Banking Finance 3 HIS-351 World History History 3 MU-199 Music Video Production Music 3 PHY-101 Physical Principles Physics 4 select * from section;
  • 3. Mrs. Sunita M Dol Page 3 course_id sec_id semester year building room_number time_slot_id BIO-101 1 Summer 2017 Painter 514 B BIO-301 1 Summer 2018 Painter 514 A CS-101 1 Fall 2017 Packard 101 H CS-101 1 Spring 2018 Packard 101 F CS-190 1 Spring 2017 Taylor 3128 E CS-190 2 Spring 2017 Taylor 3128 A CS-315 1 Spring 2018 Watson 120 D CS-319 1 Spring 2018 Watson 100 B CS-319 2 Spring 2018 Taylor 3128 C CS-347 1 Fall 2017 Taylor 3128 A EE-181 1 Spring 2017 Taylor 3128 C FIN-201 1 Spring 2018 Packard 101 B HIS-351 1 Spring 2018 Painter 514 C MU-199 1 Spring 2018 Packard 101 D PHY-101 1 Fall 2017 Watson 100 A create view Biology_Summer_2017 as select course.course_id, sec_id, building, room_number from course, section where course.course_id = section.course_id and course.dept_name = 'Biology' and section.semester = 'Summer' and section.year = 2017; select * from Biology_Summer_2017; course_idsec_idbuildingroom_number BIO-101 1 Painter 514 select course_id from Biology_Summer_2017
  • 4. Mrs. Sunita M Dol Page 4 where building= 'Painter'; course_id BIO-101 Create a view that finds the department-wise total salary select * from instructor; ID name dept_namesalary 10101SrinivasanComp. Sci. 65000 12121Wu Finance 90000 15151Mozart Music 40000 22222Einstein Physics 95000 32343El Said History 60000 33456Gold Physics 87000 45565Katz Comp. Sci. 75000 58583Califieri History 62000 76543Singh Finance 80000 76766Crick Biology 72000 83821Brandt Comp. Sci. 92000 98345Kim Elec. Eng. 80000 create view departments_total_salary (dept_name, total_salary) as select dept_name, sum (salary) from instructor group by dept_name; select * from departments_total_salary dept_name total_salary Biology 72000
  • 5. Mrs. Sunita M Dol Page 5 Comp. Sci. 232000 Elec. Eng. 80000 Finance 170000 History 122000 Music 40000 Physics 182000 Practice Problem Statements 1. Consider the clerk who needs to access all data in the instructor relation, except salary. The clerk should not be authorized to access the instructor relation. Create view relation faculty that can be made available to the clerk, 2. Create a view that lists all course sections offered by the Physics department in the Fall 2009 semester with the building and room number of each section. 3. Define a view physics_fall_2009_watson that lists the course ID and room number of all Physics courses offered in the Fall 2009 semester in the Watson building References:  Database system concepts by Abraham Silberschatz, Henry F. Korth, S. Sudarshan (McGraw Hill International Edition) sixth edition.  Database system concepts by Abraham Silberschatz, Henry F. Korth, S. Sudarshan (McGraw Hill International Edition) fifth edition.  http://codex.cs.yale.edu/avi/db-book/db4/slide-dir/  http://codex.cs.yale.edu/avi/db-book/db5/slide-dir/  http://codex.cs.yale.edu/avi/db-book/db6/slide-dir/