SlideShare a Scribd company logo
1 of 2
Problem 1. Please create the following tables with appropriate primary keys & foreign keys.
The list of tables is:
• Student table with 2 columns: sid (student ID), sname (student name).
• Teacher table with 2 columns: tid (teacher ID), tname (teacher name)
• Class table with 6 columns: cid (class ID), cname (class name), year (year of class), semester
(semester of class, e.g., fall, spring), credit (number of credits), tid (teacher ID).
• Grades table with 3 columns: sid (student ID), cid (class ID), grade (grade, 4 is A, 3 is B, 2 is
C, 1 is D, 0 is F).
Problem 2. Insert at least three rows of data to each table. Make sure you keep the primary key
and foreign key constraints.
Problem 3. Please write ONE SQL statement for each of the following tasks using tables created
in Problem 1.
Task 1: Return the total number of students
Task 2: Return the names of classes offered in Spring 2016 (spring is semester, 2016 is year).
Task 3: Return the names of classes taught by Dr. Chen in 2016.
Task 4: Return the IDs of classes with at least 2 students taking the class.
Task 5: Return the names of students who ever took Dr. Chen’s classes.
Task 6: Return the average grade of class IS 633 offered in spring 2016.
Solution
Question: Problem 1:
Table creations are given below: We have used CREATE TABLE syntax for table creation
i) CREATE TABLE Student (sid int NOT NULL, sname varchar(255), PRIMARY KEY (sid))
ii) CREATE TABLE Teacher (tid int NOT NULL, tname varchar(255), PRIMARY KEY (tid))
iii) CREATE TABLE Class (cid int NOT NULL, cname varchar(255), year int, semester
varchar(255), credit int, tid int NOT NULL, PRIMARY KEY (cid), FOREIGN KEY (tid)
REFERENCES Teacher(tid) )
iv) CREATE TABLE Grades (sid int NOT NULL, cid int NOT NULL, grade int)

More Related Content

Similar to Problem 1- Please create the following tables with appropriate primary.docx

Similar to Problem 1- Please create the following tables with appropriate primary.docx (10)

Project3
Project3Project3
Project3
 
C24
C24C24
C24
 
Algebra
AlgebraAlgebra
Algebra
 
DATABASE MANAGEMENT SYSTEM LAB.pdf
DATABASE MANAGEMENT SYSTEM LAB.pdfDATABASE MANAGEMENT SYSTEM LAB.pdf
DATABASE MANAGEMENT SYSTEM LAB.pdf
 
Sequencing (Formulating the nth term rule) Explicit lesson plan grade VI
Sequencing (Formulating the nth term rule) Explicit lesson plan grade VISequencing (Formulating the nth term rule) Explicit lesson plan grade VI
Sequencing (Formulating the nth term rule) Explicit lesson plan grade VI
 
AECT 2010 - Homemade PowerPoint Games in a High School Science Setting
AECT 2010 - Homemade PowerPoint Games in a High School Science SettingAECT 2010 - Homemade PowerPoint Games in a High School Science Setting
AECT 2010 - Homemade PowerPoint Games in a High School Science Setting
 
Excel Notes - Block #3
Excel Notes - Block #3Excel Notes - Block #3
Excel Notes - Block #3
 
Business statistics (4)
Business statistics (4)Business statistics (4)
Business statistics (4)
 
Data structures; arrays By ZAK
Data structures; arrays By ZAKData structures; arrays By ZAK
Data structures; arrays By ZAK
 
CMI2012 CCSS for Mathematics
CMI2012 CCSS for MathematicsCMI2012 CCSS for Mathematics
CMI2012 CCSS for Mathematics
 

More from shawnk7

An Institutional Review Board (IRB) is concerned with how human partic.docx
An Institutional Review Board (IRB) is concerned with how human partic.docxAn Institutional Review Board (IRB) is concerned with how human partic.docx
An Institutional Review Board (IRB) is concerned with how human partic.docx
shawnk7
 
Although objectives- functional tactics- and action items are included.docx
Although objectives- functional tactics- and action items are included.docxAlthough objectives- functional tactics- and action items are included.docx
Although objectives- functional tactics- and action items are included.docx
shawnk7
 
Project 3 is based on the materials from Freakonomics Radio Podcast- H.docx
Project 3 is based on the materials from Freakonomics Radio Podcast- H.docxProject 3 is based on the materials from Freakonomics Radio Podcast- H.docx
Project 3 is based on the materials from Freakonomics Radio Podcast- H.docx
shawnk7
 

More from shawnk7 (13)

An IP datagram has arrived with the following information in the heade.docx
An IP datagram has arrived with the following information in the heade.docxAn IP datagram has arrived with the following information in the heade.docx
An IP datagram has arrived with the following information in the heade.docx
 
An Institutional Review Board (IRB) is concerned with how human partic.docx
An Institutional Review Board (IRB) is concerned with how human partic.docxAn Institutional Review Board (IRB) is concerned with how human partic.docx
An Institutional Review Board (IRB) is concerned with how human partic.docx
 
An economy is characterized by the following behavioral equations- C -.docx
An economy is characterized by the following behavioral equations- C -.docxAn economy is characterized by the following behavioral equations- C -.docx
An economy is characterized by the following behavioral equations- C -.docx
 
An auditor examines a sample of cancelled checks to verify that the ch.docx
An auditor examines a sample of cancelled checks to verify that the ch.docxAn auditor examines a sample of cancelled checks to verify that the ch.docx
An auditor examines a sample of cancelled checks to verify that the ch.docx
 
All of the following are false regarding apportionment except- a Ap.docx
All of the following are false regarding apportionment except-    a Ap.docxAll of the following are false regarding apportionment except-    a Ap.docx
All of the following are false regarding apportionment except- a Ap.docx
 
Also indicate all zero-force members- Check all that apply- Check all.docx
Also indicate all zero-force members- Check all that apply- Check all.docxAlso indicate all zero-force members- Check all that apply- Check all.docx
Also indicate all zero-force members- Check all that apply- Check all.docx
 
Although objectives- functional tactics- and action items are included.docx
Although objectives- functional tactics- and action items are included.docxAlthough objectives- functional tactics- and action items are included.docx
Although objectives- functional tactics- and action items are included.docx
 
prove or disprove that H - {n e(element) Z- n is divisible by both 8.docx
prove or disprove  that H - {n e(element) Z- n is divisible by both 8.docxprove or disprove  that H - {n e(element) Z- n is divisible by both 8.docx
prove or disprove that H - {n e(element) Z- n is divisible by both 8.docx
 
Project 3 is based on the materials from Freakonomics Radio Podcast- H.docx
Project 3 is based on the materials from Freakonomics Radio Podcast- H.docxProject 3 is based on the materials from Freakonomics Radio Podcast- H.docx
Project 3 is based on the materials from Freakonomics Radio Podcast- H.docx
 
Problem 9-11A Time Value of Money Concept The following situations inv.docx
Problem 9-11A Time Value of Money Concept The following situations inv.docxProblem 9-11A Time Value of Money Concept The following situations inv.docx
Problem 9-11A Time Value of Money Concept The following situations inv.docx
 
Problem 5- -9 points- A red laser of wavelength 670 nm is directed thr.docx
Problem 5- -9 points- A red laser of wavelength 670 nm is directed thr.docxProblem 5- -9 points- A red laser of wavelength 670 nm is directed thr.docx
Problem 5- -9 points- A red laser of wavelength 670 nm is directed thr.docx
 
Problem 3-32 Internal and Sustainable Growth Rates (LG3-6) Use the fol.docx
Problem 3-32 Internal and Sustainable Growth Rates (LG3-6) Use the fol.docxProblem 3-32 Internal and Sustainable Growth Rates (LG3-6) Use the fol.docx
Problem 3-32 Internal and Sustainable Growth Rates (LG3-6) Use the fol.docx
 
Problem 11-6A Problem 11-6A Irwin Corporation has been au.docx
Problem 11-6A             Problem 11-6A  Irwin Corporation has been au.docxProblem 11-6A             Problem 11-6A  Irwin Corporation has been au.docx
Problem 11-6A Problem 11-6A Irwin Corporation has been au.docx
 

Recently uploaded

The basics of sentences session 4pptx.pptx
The basics of sentences session 4pptx.pptxThe basics of sentences session 4pptx.pptx
The basics of sentences session 4pptx.pptx
heathfieldcps1
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
中 央社
 
MSc Ag Genetics & Plant Breeding: Insights from Previous Year JNKVV Entrance ...
MSc Ag Genetics & Plant Breeding: Insights from Previous Year JNKVV Entrance ...MSc Ag Genetics & Plant Breeding: Insights from Previous Year JNKVV Entrance ...
MSc Ag Genetics & Plant Breeding: Insights from Previous Year JNKVV Entrance ...
Krashi Coaching
 

Recently uploaded (20)

ANTI PARKISON DRUGS.pptx
ANTI         PARKISON          DRUGS.pptxANTI         PARKISON          DRUGS.pptx
ANTI PARKISON DRUGS.pptx
 
Including Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdfIncluding Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdf
 
The Ball Poem- John Berryman_20240518_001617_0000.pptx
The Ball Poem- John Berryman_20240518_001617_0000.pptxThe Ball Poem- John Berryman_20240518_001617_0000.pptx
The Ball Poem- John Berryman_20240518_001617_0000.pptx
 
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
 
Mattingly "AI and Prompt Design: LLMs with Text Classification and Open Source"
Mattingly "AI and Prompt Design: LLMs with Text Classification and Open Source"Mattingly "AI and Prompt Design: LLMs with Text Classification and Open Source"
Mattingly "AI and Prompt Design: LLMs with Text Classification and Open Source"
 
The basics of sentences session 4pptx.pptx
The basics of sentences session 4pptx.pptxThe basics of sentences session 4pptx.pptx
The basics of sentences session 4pptx.pptx
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
 
Chapter 7 Pharmacosy Traditional System of Medicine & Ayurvedic Preparations ...
Chapter 7 Pharmacosy Traditional System of Medicine & Ayurvedic Preparations ...Chapter 7 Pharmacosy Traditional System of Medicine & Ayurvedic Preparations ...
Chapter 7 Pharmacosy Traditional System of Medicine & Ayurvedic Preparations ...
 
Dementia (Alzheimer & vasular dementia).
Dementia (Alzheimer & vasular dementia).Dementia (Alzheimer & vasular dementia).
Dementia (Alzheimer & vasular dementia).
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT VẬT LÝ 2024 - TỪ CÁC TRƯỜNG, TRƯ...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT VẬT LÝ 2024 - TỪ CÁC TRƯỜNG, TRƯ...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT VẬT LÝ 2024 - TỪ CÁC TRƯỜNG, TRƯ...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT VẬT LÝ 2024 - TỪ CÁC TRƯỜNG, TRƯ...
 
MSc Ag Genetics & Plant Breeding: Insights from Previous Year JNKVV Entrance ...
MSc Ag Genetics & Plant Breeding: Insights from Previous Year JNKVV Entrance ...MSc Ag Genetics & Plant Breeding: Insights from Previous Year JNKVV Entrance ...
MSc Ag Genetics & Plant Breeding: Insights from Previous Year JNKVV Entrance ...
 
Word Stress rules esl .pptx
Word Stress rules esl               .pptxWord Stress rules esl               .pptx
Word Stress rules esl .pptx
 
MOOD STABLIZERS DRUGS.pptx
MOOD     STABLIZERS           DRUGS.pptxMOOD     STABLIZERS           DRUGS.pptx
MOOD STABLIZERS DRUGS.pptx
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...
 
The Liver & Gallbladder (Anatomy & Physiology).pptx
The Liver &  Gallbladder (Anatomy & Physiology).pptxThe Liver &  Gallbladder (Anatomy & Physiology).pptx
The Liver & Gallbladder (Anatomy & Physiology).pptx
 
philosophy and it's principles based on the life
philosophy and it's principles based on the lifephilosophy and it's principles based on the life
philosophy and it's principles based on the life
 
An Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge AppAn Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge App
 
Championnat de France de Tennis de table/
Championnat de France de Tennis de table/Championnat de France de Tennis de table/
Championnat de France de Tennis de table/
 
Envelope of Discrepancy in Orthodontics: Enhancing Precision in Treatment
 Envelope of Discrepancy in Orthodontics: Enhancing Precision in Treatment Envelope of Discrepancy in Orthodontics: Enhancing Precision in Treatment
Envelope of Discrepancy in Orthodontics: Enhancing Precision in Treatment
 

Problem 1- Please create the following tables with appropriate primary.docx

  • 1. Problem 1. Please create the following tables with appropriate primary keys & foreign keys. The list of tables is: • Student table with 2 columns: sid (student ID), sname (student name). • Teacher table with 2 columns: tid (teacher ID), tname (teacher name) • Class table with 6 columns: cid (class ID), cname (class name), year (year of class), semester (semester of class, e.g., fall, spring), credit (number of credits), tid (teacher ID). • Grades table with 3 columns: sid (student ID), cid (class ID), grade (grade, 4 is A, 3 is B, 2 is C, 1 is D, 0 is F). Problem 2. Insert at least three rows of data to each table. Make sure you keep the primary key and foreign key constraints. Problem 3. Please write ONE SQL statement for each of the following tasks using tables created in Problem 1. Task 1: Return the total number of students Task 2: Return the names of classes offered in Spring 2016 (spring is semester, 2016 is year). Task 3: Return the names of classes taught by Dr. Chen in 2016. Task 4: Return the IDs of classes with at least 2 students taking the class. Task 5: Return the names of students who ever took Dr. Chen’s classes. Task 6: Return the average grade of class IS 633 offered in spring 2016. Solution Question: Problem 1:
  • 2. Table creations are given below: We have used CREATE TABLE syntax for table creation i) CREATE TABLE Student (sid int NOT NULL, sname varchar(255), PRIMARY KEY (sid)) ii) CREATE TABLE Teacher (tid int NOT NULL, tname varchar(255), PRIMARY KEY (tid)) iii) CREATE TABLE Class (cid int NOT NULL, cname varchar(255), year int, semester varchar(255), credit int, tid int NOT NULL, PRIMARY KEY (cid), FOREIGN KEY (tid) REFERENCES Teacher(tid) ) iv) CREATE TABLE Grades (sid int NOT NULL, cid int NOT NULL, grade int)