SlideShare a Scribd company logo
1
Ch 6: Problems and Exercises 1
CREATE TABLE STUDENT
(StudentID NUMBER NOT NULL ,
StudentName VARCHAR2(25),
CONSTRAINT STUDENT_PK PRIMARY KEY (StudentID));
CREATE TABLE FACULTY
(FacultyID NUMBER NOT NULL,
FacultyName VARCHAR2(25),
CONSTRAINT FACULTY_PK PRIMARY KEY (FacultyID));
CREATE TABLE COURSE
(CourseID CHAR(8) NOT NULL,
CourseName VARCHAR2(15),
CONSTRAINT COURSE_PK PRIMARY KEY (CourseID));
2
Ch 6: Problems and Exercises 1 (cont.)
CREATE TABLE SECTION
(SectionNo NUMBER NOT NULL,
CourseID CHAR(8),
CONSTRAINT SECTION_PK PRIMARY KEY (SectionNo),
CONSTRAINT SECTION_FK FOREIGN KEY (CourseID)
REFERENCES COURSE (CourseID));
CREATE TABLE QUALIFIED
(FacultyID NUMBER NOT NULL ,
CourseID CHAR(8) NOT NULL,
DateQualified DATE,
CONSTRAINT QUALIFIED_PK PRIMARY KEY (FacultyID, CourseID)
CONSTRAINT QUALIFIED_FK1 FOREIGN KEY (FacultyID)
REFERENCES FACULTY (FacultyID)
CONSTRAINT QUALIFIED_FK2 FOREIGN KEY (CourseID)
REFERENCES COURSE (CourseID));
3
Ch 6: Problems and Exercises 1 (cont.)
CREATE TABLE REGISTRATION
(StudentID NUMBER NOT NULL,
SectionNo NUMBER NOT NULL,
Semester CHAR(7),
CONSTRAINT REGISTRATION_PK PRIMARY KEY (StudentID,
SectionNo),
CONSTRAINT REGISTRATION_FK1 FOREIGN KEY (StudentID)
REFERENCES STUDENT (StudentID),
CONSTRAINT REGISTRATION_FK2 FOREIGN KEY (SectionNo)
REFERENCES SECTION (SectionNo));
4
Ch 6: Problems and Exercises 2
CREATE VIEW Student_V AS
SELECT * FROM STUDENT;
5
Ch 6: Problems and Exercises 3
(a) Referential integrity may be enforced when the SECTION table is created:
CREATE TABLE SECTION
(SectionNo NUMBER NOT NULL,
CourseID CHAR(8),
CONSTRAINT SECTION_PK PRIMARY KEY (SectionNo)
CONSTRAINT SECTION_FK FOREIGN KEY (CourseID)
REFERENCES COURSE (CourseID));
(b) Or, referential integrity may be enforced using the ALTER TABLE command:
ALTER TABLE SECTION
ADD CONSTRAINT SECTION_FK FOREIGN KEY (CourseID)
REFERENCES COURSE(CourseID);
6
Ch 6: Problems and Exercises 4
(a) ALTER TABLE STUDENT
ADD (Class VARCHAR2(6));
(b) DROP TABLE REGISTRATION;
(c) ALTER TABLE FACULTY
MODIFY (FacultyName VARCHAR2(40));
7
Ch 6: Problems and Exercises 5
(a) INSERT INTO STUDENT (StudentID, StudentName) VALUES
(65798, ‘Lopez’);
Alternatively:
INSERT INTO STUDENT VALUES (65798, ‘Lopez’);
(b) DELETE FROM STUDENT
WHERE StudentID = 65798;
(c) UPDATE COURSE
SET CourseName=‘Introduction to Relational Databases’
WHERE CourseID=‘ISM 4212’;
8
Ch 6: Problems and Exercises 6
(a) SELECT StudentID, StudentName
FROM STUDENT
WHERE StudentID < 50000;
(b) SELECT FacultyName
FROM FACULTY
WHERE FacultyID = 4756;
(c) SELECT MIN(SectionNo)
FROM REGISTRATION
WHERE Semester= ‘I-2008’;
9
Ch 6: Problems and Exercises 7
(a) SELECT COUNT (*)
FROM REGISTRATION
WHERE SectionID=2714 AND Semester=‘I-2008’;
(b) SELECT FacultyID, CourseID, DateQualified
FROM QUALIFIED
WHERE DateQualified >= ‘01-JAN-1993’;
10
Ch 6: Problems and Exercises 8
(a) SELECT StudentID, COUNT (*)
FROM REGISTRATION
WHERE SectionNo IN (2714, 2715)
GROUP BY StudentID
HAVING COUNT(*) = 2;
(b) SELECT FacultyID, COUNT (*)
FROM QUALIFIED
WHERE CourseID IN (‘ISM 3113’, ‘ISM 3112’)
GROUP BY FacultyID
HAVING COUNT(*) = 1;
Note: COUNT(*)>1 also ok.
11
Ch 6: Problems and Exercises 9
(a) SELECT DISTINCT CourseID
FROM SECTION;
(b) SELECT StudentName
FROM STUDENT
ORDER BY StudentName;
(c) SELECT SectionNo, StudentID
FROM REGISTRATION
ORDER BY SectionNo, StudentID;
(d) SELECT CourseID, CourseName
FROM COURSE
ORDER BY CourseID ;

More Related Content

Viewers also liked

Database fundamentals(database)
Database fundamentals(database)Database fundamentals(database)
Database fundamentals(database)welcometofacebook
 
database design intro(database)
database design intro(database)database design intro(database)
database design intro(database)welcometofacebook
 
Source code for view details(database)
Source code for view details(database)Source code for view details(database)
Source code for view details(database)welcometofacebook
 
Souce code of validation trigger examples(database)
Souce code of validation trigger examples(database)Souce code of validation trigger examples(database)
Souce code of validation trigger examples(database)welcometofacebook
 
Source codes for alerts lovs and reports generation(database)
Source codes for alerts lovs and reports generation(database)Source codes for alerts lovs and reports generation(database)
Source codes for alerts lovs and reports generation(database)welcometofacebook
 
Source code for insert multiple rows(database)
Source code for insert multiple rows(database)Source code for insert multiple rows(database)
Source code for insert multiple rows(database)welcometofacebook
 
cltv calculation-calyx corolla
cltv calculation-calyx corolla cltv calculation-calyx corolla
cltv calculation-calyx corolla welcometofacebook
 
Class+3+ +quantitative+analysis+exercise+answer+key
Class+3+ +quantitative+analysis+exercise+answer+keyClass+3+ +quantitative+analysis+exercise+answer+key
Class+3+ +quantitative+analysis+exercise+answer+keywelcometofacebook
 
Database development progress(database)
Database development progress(database)Database development progress(database)
Database development progress(database)welcometofacebook
 
Subnet questions with ans(networking)
Subnet questions with ans(networking)Subnet questions with ans(networking)
Subnet questions with ans(networking)welcometofacebook
 
EVC exercise-novel motor oil
EVC exercise-novel motor oilEVC exercise-novel motor oil
EVC exercise-novel motor oilwelcometofacebook
 

Viewers also liked (20)

Database fundamentals(database)
Database fundamentals(database)Database fundamentals(database)
Database fundamentals(database)
 
Solution1(database)
Solution1(database)Solution1(database)
Solution1(database)
 
database design intro(database)
database design intro(database)database design intro(database)
database design intro(database)
 
Solution4(database)
Solution4(database)Solution4(database)
Solution4(database)
 
Exercise1(database)
Exercise1(database)Exercise1(database)
Exercise1(database)
 
Exercise5(database)
Exercise5(database)Exercise5(database)
Exercise5(database)
 
Source code for view details(database)
Source code for view details(database)Source code for view details(database)
Source code for view details(database)
 
Souce code of validation trigger examples(database)
Souce code of validation trigger examples(database)Souce code of validation trigger examples(database)
Souce code of validation trigger examples(database)
 
Exercise4(database)
Exercise4(database)Exercise4(database)
Exercise4(database)
 
Source codes for alerts lovs and reports generation(database)
Source codes for alerts lovs and reports generation(database)Source codes for alerts lovs and reports generation(database)
Source codes for alerts lovs and reports generation(database)
 
Source code for insert multiple rows(database)
Source code for insert multiple rows(database)Source code for insert multiple rows(database)
Source code for insert multiple rows(database)
 
Exercise2(database)
Exercise2(database)Exercise2(database)
Exercise2(database)
 
cltv calculation-calyx corolla
cltv calculation-calyx corolla cltv calculation-calyx corolla
cltv calculation-calyx corolla
 
EVC exercise-odi case
EVC exercise-odi caseEVC exercise-odi case
EVC exercise-odi case
 
jones blair calculations
jones blair calculationsjones blair calculations
jones blair calculations
 
Class+3+ +quantitative+analysis+exercise+answer+key
Class+3+ +quantitative+analysis+exercise+answer+keyClass+3+ +quantitative+analysis+exercise+answer+key
Class+3+ +quantitative+analysis+exercise+answer+key
 
Database development progress(database)
Database development progress(database)Database development progress(database)
Database development progress(database)
 
Subnet questions with ans(networking)
Subnet questions with ans(networking)Subnet questions with ans(networking)
Subnet questions with ans(networking)
 
CLTV exercise-Instyle
CLTV exercise-InstyleCLTV exercise-Instyle
CLTV exercise-Instyle
 
EVC exercise-novel motor oil
EVC exercise-novel motor oilEVC exercise-novel motor oil
EVC exercise-novel motor oil
 

Similar to Solution5(database)

Oracle sql developer essentials
Oracle sql developer essentialsOracle sql developer essentials
Oracle sql developer essentials
Alok Vishwakarma
 
Md
MdMd
Database queries
Database queriesDatabase queries
Database queries
laiba29012
 
Charles WilliamsCS362Unit 3 Discussion BoardStructured Query Langu.docx
Charles WilliamsCS362Unit 3 Discussion BoardStructured Query Langu.docxCharles WilliamsCS362Unit 3 Discussion BoardStructured Query Langu.docx
Charles WilliamsCS362Unit 3 Discussion BoardStructured Query Langu.docx
christinemaritza
 

Similar to Solution5(database) (6)

Oracle sql developer essentials
Oracle sql developer essentialsOracle sql developer essentials
Oracle sql developer essentials
 
Md
MdMd
Md
 
Les10
Les10Les10
Les10
 
Tubes Basdat
Tubes BasdatTubes Basdat
Tubes Basdat
 
Database queries
Database queriesDatabase queries
Database queries
 
Charles WilliamsCS362Unit 3 Discussion BoardStructured Query Langu.docx
Charles WilliamsCS362Unit 3 Discussion BoardStructured Query Langu.docxCharles WilliamsCS362Unit 3 Discussion BoardStructured Query Langu.docx
Charles WilliamsCS362Unit 3 Discussion BoardStructured Query Langu.docx
 

More from welcometofacebook

Quantitative exercise-toasty oven
Quantitative exercise-toasty ovenQuantitative exercise-toasty oven
Quantitative exercise-toasty ovenwelcometofacebook
 
competing in a global market(4210)
competing in a global market(4210)competing in a global market(4210)
competing in a global market(4210)welcometofacebook
 
distribution strategies calyx and corolla(4210)
distribution strategies calyx and corolla(4210)distribution strategies calyx and corolla(4210)
distribution strategies calyx and corolla(4210)welcometofacebook
 
distribution strategies(4210)
distribution strategies(4210)distribution strategies(4210)
distribution strategies(4210)welcometofacebook
 
product and brand strategies(4210)
product and brand strategies(4210)product and brand strategies(4210)
product and brand strategies(4210)welcometofacebook
 
overview of marketing strategy(4210)
overview of marketing strategy(4210)overview of marketing strategy(4210)
overview of marketing strategy(4210)welcometofacebook
 
Final exam review answer(networking)
Final exam review answer(networking)Final exam review answer(networking)
Final exam review answer(networking)welcometofacebook
 
Midterm review questions ans(networking)
Midterm review questions ans(networking)Midterm review questions ans(networking)
Midterm review questions ans(networking)welcometofacebook
 
IP adress and routing(networking)
IP adress and routing(networking)IP adress and routing(networking)
IP adress and routing(networking)welcometofacebook
 
Layer 2 switching fundamentals(networking)
Layer 2 switching fundamentals(networking)Layer 2 switching fundamentals(networking)
Layer 2 switching fundamentals(networking)welcometofacebook
 

More from welcometofacebook (20)

Quantitative exercise-toasty oven
Quantitative exercise-toasty ovenQuantitative exercise-toasty oven
Quantitative exercise-toasty oven
 
consumer behavior(4210)
consumer behavior(4210)consumer behavior(4210)
consumer behavior(4210)
 
competing in a global market(4210)
competing in a global market(4210)competing in a global market(4210)
competing in a global market(4210)
 
promotion strategies(4210)
promotion strategies(4210)promotion strategies(4210)
promotion strategies(4210)
 
pricing strategies(4210)
pricing strategies(4210)pricing strategies(4210)
pricing strategies(4210)
 
Pharmasim
PharmasimPharmasim
Pharmasim
 
distribution strategies calyx and corolla(4210)
distribution strategies calyx and corolla(4210)distribution strategies calyx and corolla(4210)
distribution strategies calyx and corolla(4210)
 
distribution strategies(4210)
distribution strategies(4210)distribution strategies(4210)
distribution strategies(4210)
 
the birth of swatch(4210)
the birth of swatch(4210)the birth of swatch(4210)
the birth of swatch(4210)
 
product and brand strategies(4210)
product and brand strategies(4210)product and brand strategies(4210)
product and brand strategies(4210)
 
stp case jones blair(4210)
stp case jones blair(4210)stp case jones blair(4210)
stp case jones blair(4210)
 
stp(4210)
stp(4210)stp(4210)
stp(4210)
 
situational analysis(4210)
situational analysis(4210)situational analysis(4210)
situational analysis(4210)
 
quantitative analysis(4210)
quantitative analysis(4210)quantitative analysis(4210)
quantitative analysis(4210)
 
overview of marketing strategy(4210)
overview of marketing strategy(4210)overview of marketing strategy(4210)
overview of marketing strategy(4210)
 
Final exam review answer(networking)
Final exam review answer(networking)Final exam review answer(networking)
Final exam review answer(networking)
 
Midterm review questions ans(networking)
Midterm review questions ans(networking)Midterm review questions ans(networking)
Midterm review questions ans(networking)
 
IP adress and routing(networking)
IP adress and routing(networking)IP adress and routing(networking)
IP adress and routing(networking)
 
TCP/IP(networking)
TCP/IP(networking)TCP/IP(networking)
TCP/IP(networking)
 
Layer 2 switching fundamentals(networking)
Layer 2 switching fundamentals(networking)Layer 2 switching fundamentals(networking)
Layer 2 switching fundamentals(networking)
 

Recently uploaded

一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
zwunae
 
Literature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptxLiterature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptx
Dr Ramhari Poudyal
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
AJAYKUMARPUND1
 
basic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdfbasic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdf
NidhalKahouli2
 
Recycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part IIIRecycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part III
Aditya Rajan Patra
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
JoytuBarua2
 
Building Electrical System Design & Installation
Building Electrical System Design & InstallationBuilding Electrical System Design & Installation
Building Electrical System Design & Installation
symbo111
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
thanhdowork
 
Technical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prismsTechnical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prisms
heavyhaig
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Teleport Manpower Consultant
 
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单专业办理
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单专业办理一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单专业办理
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单专业办理
zwunae
 
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
ssuser7dcef0
 
一比一原版(Otago毕业证)奥塔哥大学毕业证成绩单如何办理
一比一原版(Otago毕业证)奥塔哥大学毕业证成绩单如何办理一比一原版(Otago毕业证)奥塔哥大学毕业证成绩单如何办理
一比一原版(Otago毕业证)奥塔哥大学毕业证成绩单如何办理
dxobcob
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
Massimo Talia
 
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressionsKuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
Victor Morales
 
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdf
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdfTutorial for 16S rRNA Gene Analysis with QIIME2.pdf
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdf
aqil azizi
 
PPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testingPPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testing
anoopmanoharan2
 
Hierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power SystemHierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power System
Kerry Sado
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
Kamal Acharya
 
DfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributionsDfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributions
gestioneergodomus
 

Recently uploaded (20)

一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
 
Literature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptxLiterature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptx
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
 
basic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdfbasic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdf
 
Recycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part IIIRecycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part III
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
 
Building Electrical System Design & Installation
Building Electrical System Design & InstallationBuilding Electrical System Design & Installation
Building Electrical System Design & Installation
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
 
Technical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prismsTechnical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prisms
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
 
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单专业办理
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单专业办理一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单专业办理
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单专业办理
 
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
 
一比一原版(Otago毕业证)奥塔哥大学毕业证成绩单如何办理
一比一原版(Otago毕业证)奥塔哥大学毕业证成绩单如何办理一比一原版(Otago毕业证)奥塔哥大学毕业证成绩单如何办理
一比一原版(Otago毕业证)奥塔哥大学毕业证成绩单如何办理
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
 
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressionsKuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
 
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdf
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdfTutorial for 16S rRNA Gene Analysis with QIIME2.pdf
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdf
 
PPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testingPPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testing
 
Hierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power SystemHierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power System
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
 
DfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributionsDfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributions
 

Solution5(database)

  • 1. 1 Ch 6: Problems and Exercises 1 CREATE TABLE STUDENT (StudentID NUMBER NOT NULL , StudentName VARCHAR2(25), CONSTRAINT STUDENT_PK PRIMARY KEY (StudentID)); CREATE TABLE FACULTY (FacultyID NUMBER NOT NULL, FacultyName VARCHAR2(25), CONSTRAINT FACULTY_PK PRIMARY KEY (FacultyID)); CREATE TABLE COURSE (CourseID CHAR(8) NOT NULL, CourseName VARCHAR2(15), CONSTRAINT COURSE_PK PRIMARY KEY (CourseID));
  • 2. 2 Ch 6: Problems and Exercises 1 (cont.) CREATE TABLE SECTION (SectionNo NUMBER NOT NULL, CourseID CHAR(8), CONSTRAINT SECTION_PK PRIMARY KEY (SectionNo), CONSTRAINT SECTION_FK FOREIGN KEY (CourseID) REFERENCES COURSE (CourseID)); CREATE TABLE QUALIFIED (FacultyID NUMBER NOT NULL , CourseID CHAR(8) NOT NULL, DateQualified DATE, CONSTRAINT QUALIFIED_PK PRIMARY KEY (FacultyID, CourseID) CONSTRAINT QUALIFIED_FK1 FOREIGN KEY (FacultyID) REFERENCES FACULTY (FacultyID) CONSTRAINT QUALIFIED_FK2 FOREIGN KEY (CourseID) REFERENCES COURSE (CourseID));
  • 3. 3 Ch 6: Problems and Exercises 1 (cont.) CREATE TABLE REGISTRATION (StudentID NUMBER NOT NULL, SectionNo NUMBER NOT NULL, Semester CHAR(7), CONSTRAINT REGISTRATION_PK PRIMARY KEY (StudentID, SectionNo), CONSTRAINT REGISTRATION_FK1 FOREIGN KEY (StudentID) REFERENCES STUDENT (StudentID), CONSTRAINT REGISTRATION_FK2 FOREIGN KEY (SectionNo) REFERENCES SECTION (SectionNo));
  • 4. 4 Ch 6: Problems and Exercises 2 CREATE VIEW Student_V AS SELECT * FROM STUDENT;
  • 5. 5 Ch 6: Problems and Exercises 3 (a) Referential integrity may be enforced when the SECTION table is created: CREATE TABLE SECTION (SectionNo NUMBER NOT NULL, CourseID CHAR(8), CONSTRAINT SECTION_PK PRIMARY KEY (SectionNo) CONSTRAINT SECTION_FK FOREIGN KEY (CourseID) REFERENCES COURSE (CourseID)); (b) Or, referential integrity may be enforced using the ALTER TABLE command: ALTER TABLE SECTION ADD CONSTRAINT SECTION_FK FOREIGN KEY (CourseID) REFERENCES COURSE(CourseID);
  • 6. 6 Ch 6: Problems and Exercises 4 (a) ALTER TABLE STUDENT ADD (Class VARCHAR2(6)); (b) DROP TABLE REGISTRATION; (c) ALTER TABLE FACULTY MODIFY (FacultyName VARCHAR2(40));
  • 7. 7 Ch 6: Problems and Exercises 5 (a) INSERT INTO STUDENT (StudentID, StudentName) VALUES (65798, ‘Lopez’); Alternatively: INSERT INTO STUDENT VALUES (65798, ‘Lopez’); (b) DELETE FROM STUDENT WHERE StudentID = 65798; (c) UPDATE COURSE SET CourseName=‘Introduction to Relational Databases’ WHERE CourseID=‘ISM 4212’;
  • 8. 8 Ch 6: Problems and Exercises 6 (a) SELECT StudentID, StudentName FROM STUDENT WHERE StudentID < 50000; (b) SELECT FacultyName FROM FACULTY WHERE FacultyID = 4756; (c) SELECT MIN(SectionNo) FROM REGISTRATION WHERE Semester= ‘I-2008’;
  • 9. 9 Ch 6: Problems and Exercises 7 (a) SELECT COUNT (*) FROM REGISTRATION WHERE SectionID=2714 AND Semester=‘I-2008’; (b) SELECT FacultyID, CourseID, DateQualified FROM QUALIFIED WHERE DateQualified >= ‘01-JAN-1993’;
  • 10. 10 Ch 6: Problems and Exercises 8 (a) SELECT StudentID, COUNT (*) FROM REGISTRATION WHERE SectionNo IN (2714, 2715) GROUP BY StudentID HAVING COUNT(*) = 2; (b) SELECT FacultyID, COUNT (*) FROM QUALIFIED WHERE CourseID IN (‘ISM 3113’, ‘ISM 3112’) GROUP BY FacultyID HAVING COUNT(*) = 1; Note: COUNT(*)>1 also ok.
  • 11. 11 Ch 6: Problems and Exercises 9 (a) SELECT DISTINCT CourseID FROM SECTION; (b) SELECT StudentName FROM STUDENT ORDER BY StudentName; (c) SELECT SectionNo, StudentID FROM REGISTRATION ORDER BY SectionNo, StudentID; (d) SELECT CourseID, CourseName FROM COURSE ORDER BY CourseID ;