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 that no attributes, other than the grade, are allowed to be null in this relation, identify a suitable primary key, and indicate appropriate foreign key(s). Include not null constraints only on attributes where the domain is not already constrained to exclude nulls.
.
The Table can be created in two ways
Without Constraint Clause
CREATE TABLE Takes ( Id int,
Course_id Varchar2(10),
Sec_id int CHECK(Sec_id>=0),
Semester varchar(1) CHECK (Semester IN(‘F’,’S’)),
Year int,
Grade varchar2(5) NOT NULL DEFAULT ‘ABCDF’,
PRIMARY KEY (Id, Course_id, Sec_id, Semester, Year),
FOREIGN KEY(Id) REFERENCES Student(Id),
FOREIGN KEY ( Course_id, Sec_id, Semester, Year) REFERENCES (Section))
This SQL statement will create table with all the constraints but there is no CONSTRAINT clause.
With Constraint Clause
CREATE TABLE Takes ( Id int,
Course_id Varchar2(10),
Sec_id int,
Semester varchar(1),
Year int,
Grade varchar2(5) NOT NULL DEFAULT ‘ABCDF’,
CONSTRAINT secid CHECK(Sec_id>=0),
CONSTRAINT Sem_Val CHECK (Semester IN(‘F’,’S’)),
CONSTRAINT Takes_pk PRIMARY KEY (Id, Course_id, Sec_id, Semester, Year),
CONSTRAINT Takes_fk1 FOREIGN KEY(Id) REFERENCES Student(Id),
CONSTRAINT Takes_fk2
FOREIGN KEY ( Course_id, Sec_id, Semester, Year) REFERENCES (Section))
This has the CONSTRAINT Clause.
Constraint Clause is used to define the integrity constraint. If we name the constraint we will be able to alter the constraint in a easy way using alter table.
Thank You!!!
Assume that the takes relation has not yet been defined. Give an SQL statement that adds...
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...
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...
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...
Write appropriate PL/SQL statements to create a procedure to check that no section has more students than the capacity of the classroom in which the section is scheduled. Display the course_id, sec_id, semester, year, building, and room_number for the sections that have more students than the capacity of the classroom in which the section is scheduled. The following are the tables needed: classroom (building, room_number, capacity) section (course_id, sec_id, semester, year, building, room_number, time_slot_id) takes (student_id, course_id, sec_id, semester, year,...