Question

This is database system concept. 1.Find the ids of instructors who are also students using a...

This is database system concept.

1.Find the ids of instructors who are also students using a set operation. Assume that a person is identified by her or his id. So, if the same id appears in both instructor and student, then that person is both an instructor and a student. Remember: set operation means union, intersect or set difference.

2.Find the ids of instructors who are also students using the set membership operator.

3.Find the ids of instructors who are also students using a set comparison operator.

4. Find the ids of instructors who are also students using the exists construct.

5.Find the names and ids of the students who have taken all the courses that are offered by their departments. Notice, the table course contains information about courses offered by departments.

6.Find the names and ids of the students who have taken exactly one course in the Spring 2010 semester.

7.Find the names and ids of the students who have taken at most one course in the Spring 2010 semester.

8.Write a query that uses a derived relation to find the student(s) who have taken at least two courses in the Spring 2010 semester. Remember: derived relation means a subquery in the from clause.

9.Write a query that uses a scalar query in the select clause to find the number of distinct courses that have been taught by each instructor. Schema of the output should be (name, id, number_courses).

​10.Use an outer join to find names of instructors who did not teach any course in the Spring 2010 semester.

11.Write a query that uses the with clause or a derived relation to find the id and number of courses that have been taken by student(s) who have taken the most number of courses.

create table classroom
(building  varchar(15),
room_number  varchar(7),
capacity  numeric(4,0),
primary key (building, room_number)
);

create table department
(dept_name  varchar(20),
building  varchar(15),
budget          numeric(12,2) check (budget > 0),
primary key (dept_name)
);

create table course
(course_id  varchar(8),
title   varchar(50),
dept_name  varchar(20),
credits  numeric(2,0) check (credits > 0),
primary key (course_id),
foreign key (dept_name) references department
  on delete set null
);

create table instructor
(ID   varchar(5),
name   varchar(20) not null,
dept_name  varchar(20),
salary   numeric(8,2) check (salary > 29000),
primary key (ID),
foreign key (dept_name) references department
  on delete set null
);

create table section
(course_id  varchar(8),
         sec_id   varchar(8),
semester  varchar(6)
  check (semester in ('Fall', 'Winter', 'Spring', 'Summer')),
year   numeric(4,0) check (year > 1701 and year < 2100),
building  varchar(15),
room_number  varchar(7),
time_slot_id  varchar(4),
primary key (course_id, sec_id, semester, year),
foreign key (course_id) references course
  on delete cascade,
foreign key (building, room_number) references classroom
  on delete set null
);

create table teaches
(ID   varchar(5),
course_id  varchar(8),
sec_id   varchar(8),
semester  varchar(6),
year   numeric(4,0),
primary key (ID, course_id, sec_id, semester, year),
foreign key (course_id,sec_id, semester, year) references section
  on delete cascade,
foreign key (ID) references instructor
  on delete cascade
);

create table student
(ID   varchar(5),
name   varchar(20) not null,
dept_name  varchar(20),
tot_cred  numeric(3,0) check (tot_cred >= 0),
primary key (ID),
foreign key (dept_name) references department
  on delete set null
);

create table takes
(ID   varchar(5),
course_id  varchar(8),
sec_id   varchar(8),
semester  varchar(6),
year   numeric(4,0),
grade          varchar(2),
primary key (ID, course_id, sec_id, semester, year),
foreign key (course_id,sec_id, semester, year) references section
  on delete cascade,
foreign key (ID) references student
  on delete cascade
);

create table advisor
(s_ID   varchar(5),
i_ID   varchar(5),
primary key (s_ID),
foreign key (i_ID) references instructor (ID)
  on delete set null,
foreign key (s_ID) references student (ID)
  on delete cascade
);

create table time_slot
(time_slot_id  varchar(4),
day   varchar(1),
start_hr  numeric(2) check (start_hr >= 0 and start_hr < 24),
start_min  numeric(2) check (start_min >= 0 and start_min < 60),
end_hr   numeric(2) check (end_hr >= 0 and end_hr < 24),
end_min  numeric(2) check (end_min >= 0 and end_min < 60),
primary key (time_slot_id, day, start_hr, start_min)
);

create table prereq
(course_id  varchar(8),
prereq_id  varchar(8),
primary key (course_id, prereq_id),
foreign key (course_id) references course
  on delete cascade,
foreign key (prereq_id) references course
);

0 0
Add a comment Improve this question Transcribed image text
Answer #1

1.SQL> select id from instructor intersect select id from student;

OUTPUT

ID

-----

501

502

503

2.SQL> select id from instructor where id in(select id from student);

OUTPUT

ID

-----

503

501

502

3.SQL> select id from instructor where id= some (select id from student);

OUTPUT

ID

-----

503

501

502

4.SQL> select id from student where exists (select id from instructor);

OUTPUT

ID

-----

503

501

502

5.SQL> select name,id from student s,course c where s.dept_name=c.dept_name;

OUTPUT

NAME                 ID

-------------------- -----

madhu                501

madhu                501

smith                502

john                 503

john                 503

smith                502

6 rows selected.

Add a comment
Know the answer?
Add Answer to:
This is database system concept. 1.Find the ids of instructors who are also students using a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Database concepts Find the names and ids of the students who have taken at most one...

    Database concepts Find the names and ids of the students who have taken at most one course in the Spring 2010 semester. Notice, at most one means one or zero. So, the answer should include students who did not take any course during that semester The data: create table classroom     (building       varchar(15),      room_number        varchar(7),      capacity       numeric(4,0),      primary key (building, room_number)     ); create table department     (dept_name      varchar(20),      building       varchar(15),      budget      numeric(12,2) check (budget > 0),      primary key (dept_name)     ); create...

  • Assume that the takes relation has not yet been defined. Give an SQL statement that adds...

    Assume that the takes relation has not yet been defined. Give an SQL statement that adds the takes relation to the database. Assume that: •Id is an integer •course_id is a string of up to10 characters. •sec_id should be a non-negative integer. •the semester is a one-character field, equal to either ‘F’ or ‘S’, and the •year is an integer. •grade can be null, but if not, it should be a letter in the string ‘ABCDF’. Your statement must ensure...

  • Consider the Schema diagram for a university database a. Find the IDs of all students who...

    Consider the Schema diagram for a university database a. Find the IDs of all students who have taken all of the CMPSC courses. Use the division operation. b. Do the same operation as in problem a, using only fundamental operations. student takes ID course id sec id semester 1er 4112 dept_name tot cred grade advisor section course_id sec id semester year building TOOM_10 time_slof_id course course id title dept name credits department dept name building budget time slot time slot...

  • SQL question, you can right-click the picture and select open in a new tab for a...

    SQL question, you can right-click the picture and select open in a new tab for a better-looking experience. Write an SQL query using the university schema to find the ID of each student who has never taken a course at the university. Do this using no subqueries and no set operations (use an outer join) University Schema student takes ID ID пате course_id sec id semester уеar grade dept_name tot_cred section course |department course id sec_id semester advisor course_id title...

  • I am trying to delete these tables from my data base and I keep getting: "mysql>...

    I am trying to delete these tables from my data base and I keep getting: "mysql> DROP TABLE Courses; ERROR 1217 (23000): Cannot delete or update a parent row: a foreign key constraint fails" I am using the command DROP TABLE Courses; Below is my sql file use sdev300; // Create a student table CREATE TABLE Students ( PSUsername varchar(30) primary key, FirstName varchar(30), LastName varchar(30), EMail varchar(60) ); CREATE TABLE Courses( CourseID int primary key, CourseDisc varchar(4), CourseNum varchar(4),...

  • SQL Query Question: I have a database with the tables below, data has also been aded...

    SQL Query Question: I have a database with the tables below, data has also been aded into these tables, I have 2 tasks: 1. Add a column to a relational table POSITIONS to store information about the total number of skills needed by each advertised position. A name of the column is up to you. Assume that no more than 9 skills are needed for each position. Next, use a single UPDATE statement to set the values in the new...

  • Using SQL and the following info Question 3: Find the people who do not have Viper...

    Using SQL and the following info Question 3: Find the people who do not have Viper Certification but are still assigned to Viper class ship Find the fname, lname, and ship_instance_id for all people who do not have Viper certification but are assigned to at least one instance of a Viper class ship (this includes all variants of Viper class ships). Return a row for every ship/person combination. Order your results by fname in ascending order. Use the BSG database...

  • Using SQL and the following info Question 3: Find the people who do not have Viper...

    Using SQL and the following info Question 3: Find the people who do not have Viper Certification but are still assigned to Viper class ship Find the fname, lname, and ship_instance_id for all people who do not have Viper certification but are assigned to at least one instance of a Viper class ship (this includes all variants of Viper class ships). Return a row for every ship/person combination. Order your results by fname in ascending order. Use the BSG database...

  • Suppose a student is taking IS 620 section 1 and HCC 629 section 1 for spring...

    Suppose a student is taking IS 620 section 1 and HCC 629 section 1 for spring 2019. Use an explicit cursor to print out the titles and prices of textbooks for these two courses. Sample code to create the tables: drop table textbook_schedule cascade constraints; drop table textbook_author cascade constraints; drop table schedule cascade constraints; drop table course cascade constraints; drop table textbook cascade constraints; drop table author cascade constraints; drop table teacher cascade constraints; drop table program cascade constraints;...

  • Based on reference below. Write a relational algebra expression to return those users who have posted...

    Based on reference below. Write a relational algebra expression to return those users who have posted “excellent” reviews but never “poor” reviews. CREATE TABLE Users (             userId varchar (30) NOT NULL,             pass varchar (30),             fname varchar (50),             lname varchar (50),             email varchar (50),             gender char(1),             age integer,             banned boolean,             PRIMARY KEY (userId),             UNIQUE(email)) CREATE TABLE FavSellers (             userId varchar (30),             sellerId varchar (30),             PRIMARY KEY (userId, sellerId),...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT