AMANI SINAN 120011757 Assignment 4
1. Write the following queries in SQL, using the university schema. (2.75 M)
A. Create a new course“CS-001”, titled “Weekly Seminar”, with 0 credits.
insert into Course ( course_id , title,dept_name , credits)
values ('CS-001' , 'Weekly Seminar ', 'Comp. Sci' , 0);
B. Create a section of this course in Autumn 2009, with sec id of 1.
insert into Section ( course_id , sec_id , semester,year)
values ('CS-001','1','Fall',2009);
C. Enroll every student in the Comp. Sci. department in the above section.
Insert into takes(id,course_id,sec_id,semester,year)
Select id,'CS-001','1','Fall',2009
m
er as
From student
co
Where dpet_name='Comp. Sci'
eH w
D. Delete enrollments in the above section where the student’s name is Chavez.
o.
rs e
Delete from takes
ou urc
Where course_id ='CS-001'
and sec_id ='1'
o
and semester ='Fall'
aC s
vi y re
and year ='2009'
and id in (select id from student where name='Chavez')
E. Delete the course CS-001. What will happen if you run this delete statement without first
ed d
deleting offerings (sections) of this course.
ar stu
delete from course
where course_id = 'CS-001'
• Table section have foreign key course_id
is
• When delete CS-001 from course which is reference by section, tuples in section that have
Th
course_id as CS-001 will be direct delete.
F. Delete all takes tuples corresponding to any section of any course with the word “database” as
a part of the title; ignore case when matching the word with the title.
sh
delete from takes
where course_id in ( select course_id
from course
where lower(title) like '%database%' )
This study source was downloaded by 100000812803557 from CourseHero.com on 08-23-2021 10:38:02 GMT -05:00
https://www.coursehero.com/file/13231356/Assignment-4-IT244/
AMANI SINAN 120011757 Assignment 4
2. Name the built-in data types in SQL? (1m).
• char(n): A fixed-length character string with user-specified length n. The full form, character, can
be used instead.
• varchar(n): A variable-length character string with user-specified maximum length n. The full
form, character varying, is equivalent.
• int: An integer (a finite subset of the integers that ismachine dependent). The full form, integer,
is equivalent.
• smallint: A small integer (a machine-dependent subset of the integer type).
• numeric(p, d):Afixed-point number with user-specified precision. The number consists of p digits
(plus a sign), and d of the p digits are to the right of the decimal point. Thus, numeric(3,1) allows
44.5 to be stored exactly, but neither 444.5 or 0.32 can be stored exactly in a field of this type.
m
er as
real, double precision: Floating-point and double-precision floating-point numbers with
machine-dependent precision.
co
eH w
• float(n): A floating-point number, with precision of at least n digits.
o.
The book ch3 page 59
rs e
ou urc
References:
o
Silberschatz, A., Korth, H., & Sudarshan, S. (2011). DATABASE SYSTEM CONCEPTS 6th edition. United
aC s
States: McGraw-Hill.
vi y re
ed d
ar stu
is
Th
sh
This study source was downloaded by 100000812803557 from CourseHero.com on 08-23-2021 10:38:02 GMT -05:00
https://www.coursehero.com/file/13231356/Assignment-4-IT244/
Powered by TCPDF (www.tcpdf.org)