Question

1) Add to a relational table DEPARTMENT information about the total number of employees in each...

1) Add to a relational table DEPARTMENT information about the total number of employees in each department.

Note, that if a department has not employee then for such a department the total number of employees must be set to zero (0).

The total number of employees must be a positive number no more than 999. Use SELECT statement to list the contents of an extended relational table DEPARTMENT in the descending order of the total number of employees. Finally, remove the new column that added in this subtask.

CREATE TABLE LPOSITION( position VARCHAR(20) NOT NULL, /* Position occupied */ salary_level CHAR NOT NULL, /* Salary level */ CONSTRAINT LPosition_PKey PRIMARY KEY (position) ); /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ CREATE TABLE DEPARTMENT ( name VARCHAR(50) NOT NULL, /* Department name */ code CHAR(8) NOT NULL, /* Code of department */ head DECIMAL(7), /* Head of department */ budget DECIMAL(10,2), /* Budget of department */ CONSTRAINT DEPARTMENT_PKey PRIMARY KEY (name) ); /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ CREATE TABLE EMPLOYEE( eno DECIMAL(7) NOT NULL, /* Employee number */ first_name VARCHAR(30) NOT NULL, /* First name */ last_name VARCHAR(30) NOT NULL, /* Last name */ email VARCHAR(50) NOT NULL, /* Email address */ bldg_no DECIMAL(5) NOT NULL, /* Building number of office */ room_no VARCHAR(5) NOT NULL, /* Office room number+suffix */ phone DECIMAL(4) NOT NULL, /* Office phone extension number */ dname VARCHAR(50) NOT NULL, /* Department name */ position VARCHAR(20) NOT NULL, /* Position occupied */ CONSTRAINT EMPLOYEE_PKey PRIMARY KEY(eno), CONSTRAINT EMPLOYEE_CKey1 UNIQUE(email), CONSTRAINT EMPLOYEE_CKey2 UNIQUE(phone), CONSTRAINT EMPLOYEE_FKey1 FOREIGN KEY (dname) REFERENCES DEPARTMENT(name), CONSTRAINT EMPLOYEE_FKey2 FOREIGN KEY (position) REFERENCES LPOSITION(position) ); /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ CREATE TABLE SUBJECT( code CHAR(7) NOT NULL, /* Subject code */ title VARCHAR(200) NOT NULL, /* Subject title */ credits DECIMAL(2) NOT NULL, /* Credit points */ description VARCHAR(2000) NOT NULL, /* Subject description */ CONSTRAINT SUBJECT_PKey PRIMARY KEY(code) ); /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ /* Association: RUNNING SUBJECT Is-instance-of SUBJECT */ CREATE TABLE RUNNINGSUBJECT( code CHAR(7) NOT NULL, /* Subject code */ rsession VARCHAR(7) NOT NULL, /* Session running */ ryear DECIMAL(4) NOT NULL, /* Year running */ enrolment DECIMAL(3) NOT NULL, /* Total enrolment */ CONSTRAINT RUNNINGSUBJECT_PKey PRIMARY KEY(code, rsession, ryear), CONSTRAINT RUNNINGSUBJECT_FKey1 FOREIGN KEY (code) REFERENCES SUBJECT(code) ); /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ CREATE TABLE TEACHES( code CHAR(7) NOT NULL, /* Subject code */ rsession VARCHAR(7) NOT NULL, /* Session running */ ryear DECIMAL(4) NOT NULL, /* Year running */ lecturer DECIMAL(7) NOT NULL, /* Lecturer */ CONSTRAINT TEACHES_PKey PRIMARY KEY(code, rsession, ryear, lecturer), CONSTRAINT TEACHES_FKey1 FOREIGN KEY (code, rsession, ryear) REFERENCES RUNNINGSUBJECT(code, rsession, ryear), CONSTRAINT TEACHES_FKey2 FOREIGN KEY (lecturer) REFERENCES EMPLOYEE(eno) );

Homework Answers

Answer #1

Query to Add to a relational table DEPARTMENT information about the total number of employees in each department

Solution: ALTER TABLE DEPARTMENT ADD total_number_of_employees(DECIMAL(7)) CHECK (total_number_of_employees>=0 AND total_number_of_empolyees<=999);

Query to list the contents of an extended relational table DEPARTMENT in the descending order of the total number of employees

SELECT * FROM DEPAERTMENT

ORDER BY total_number_of_empolyees DESC;

Query to remove the added column total_number_of_empolyees

ALTER TABLE DEPARTMENT DROP COLUMN total_number_of_employees ;

Know the answer?
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
Similar Questions
The queries listed below must be implemented with a set algebra operation. 1)Find the department name...
The queries listed below must be implemented with a set algebra operation. 1)Find the department name and code for all departments that only offered subjects that worth 6 credits. Note that a subject offered by a department means a lecturer of the department has been assigned to teach the subject. CREATE TABLE LPOSITION(    position       VARCHAR(20)   NOT NULL,   /* Position occupied       */    salary_level   CHAR   NOT NULL,       /* Salary level   */    CONSTRAINT LPosition_PKey PRIMARY KEY (position)...
I get Error code 1215 Cannot add foreign key constraint in MySQL work bench lines 10,...
I get Error code 1215 Cannot add foreign key constraint in MySQL work bench lines 10, 11 & 14. I've tried to correct it and it's still wrong. I'm new to SQL and about to give up. Create Table Employee( EmployeeNumber   Int           NOT NULL AUTO_INCREMENT, FirstName       Char(25)   NOT NULL, LastName       Char(25)   NOT NULL, Department       Char(35)   NOT NULL DEFAULT 'Human Resources', Position       Char(35)   NULL, Supervisor       Int           NULL, OfficePhone       Char(12)   NULL, EmailAddress  ...
Create table employee( Employeenumber int NOT NULL IDENTITY (1,1), Firstname Char (25) Not null, lastname Char...
Create table employee( Employeenumber int NOT NULL IDENTITY (1,1), Firstname Char (25) Not null, lastname Char (25) Not null, department Char (35) Not null default "Human Resources", position Char (35) Not null, supervisor int Not null, officephone Char (12) Not null, emailaddress varchar (100) Not null unique, Constraint employee_pk primary key(employeenumber), Constraint Emp_depart_fk foreign key (department) References department(departmentname) on update cascade, constraint emp_super_fk foreign key (Supervisor) references employee(employeenumber) ); Bolded section Line 2 is coming back with an error
Find the total number of employees and the total number of dependents for every department (the...
Find the total number of employees and the total number of dependents for every department (the number of dependents for a department is the sum of the number of dependents for each employee working for that department). Return the result as department name, total number of employees, and total number of dependents Based on the following table: -- drop tables DROP TABLE EMPLOYEE CASCADE CONSTRAINTS; DROP TABLE DEPARTMENT CASCADE CONSTRAINTS; DROP TABLE DEPT_LOCATIONS CASCADE CONSTRAINTS; DROP TABLE PROJECT CASCADE CONSTRAINTS;...
Space X Bank CREATE TABLE Branch(BranchIDNumber VARCHAR(15) PRIMARY KEY NOT NULL, BranchName VARCHAR(6) NOT NULL, Address...
Space X Bank CREATE TABLE Branch(BranchIDNumber VARCHAR(15) PRIMARY KEY NOT NULL, BranchName VARCHAR(6) NOT NULL, Address VARCHAR(50) NOT NULL, City TEXT NULL, State CHAR(2) NULL, ZipCode INT(11) NOT NULL, OfficeNum VARCHAR(15) NOT NULL, FaxNum VARCHAR(15) NOT NULL); CREATE TABLE Employee(EmployeeIDNumber VARCHAR(15) NOT NULL,FirstName VARCHAR(35) NOT NULL, LastName VARCHAR(35) NOT NULL, Email VARCHAR(100) NOT NULL, BranchIDNumber VARCHAR(11) NOT NULL, FOREIGN KEY(BranchIDNumber) REFERENCES Branch(BranchIDNumber), JobTitle ENUM("Manager","Staff") NOT NULL, Salary DECIMAL(8, 2) NOT NULL, HomeNumber VARCHAR(13) NULL, CellNumber VARCHAR(13) NOT NULL); CREATE TABLE...
Perform SQL queries in the given data structure. write an SQL query that gives the number...
Perform SQL queries in the given data structure. write an SQL query that gives the number of courses taken for every student in the student table. For each instructor, show the instructor name and the number of sections that have been taught by that instructor. You do not need to include instructors who have never taught a section. List in order of decreasing the number of sections taught. Give the number of semester/year combinations in which sections have been offered....
Consider the following relational database:               STUDENT     (STDNO, SNAME, DEPTNO#)             &n
Consider the following relational database:               STUDENT     (STDNO, SNAME, DEPTNO#)               DEP                 (DEPTNO, DNAME)               COURSE        (CORSNO, CNAME, DEPTNO#, CMAX)               ENROLMENT       (STDNO#, CORSNO#, GRADE, EDATE) STUDENT.DEPTNO is the department number of the student. COURSE.DEPTNO is the department number that offers the course. ENROLMENT models the registrations of students in courses (M:M relationship) where the GRADE is the grade obtained by the student in the course. PART I : DATA DESCRIPTION LANGUAGE (DDL) Write DDL commands to create the four...
This is my code but I am having trouble with the SECTION and REGISTRATION table. The...
This is my code but I am having trouble with the SECTION and REGISTRATION table. The error for section says course id isn't a column and with registration, it says there are no foreign key but that is all that is in the registration table. CREATE TABLE STUDENT(StudentID integer, StudentName char(25) NOT NULL, primary key(StudentName)) CREATE TABLE FACULTY(FacultyID integer, FacultyName char(25) NOT NULL, primary key(FacultyID)) CREATE TABLE COURSE(CourseID integer, CourseName char(15) NOT NULL, primary key(CourseID)) CREATE TABLE QUALIFIED(DateQualified date, FacultyID...
Assignment Instructions (MY WORK IN MYSQLBENCH)- Follow instructions in class to download and build a database...
Assignment Instructions (MY WORK IN MYSQLBENCH)- Follow instructions in class to download and build a database in your DBMS. Write and demonstrate queries (in-class) that do the following: Download the appropriate attached SQL file for your DBMS. Load the file into your database design tool and run it to build the Pine Valley Furniture Company database. This is the database that is used in the textbook examples for both Chapters 5 and 6. Write a query to show the price...
This is my code, but when I try to create my "Qualified" Table it won't let...
This is my code, but when I try to create my "Qualified" Table it won't let me enter foreign keys and I don't know why. CREATE TABLE STUDENT(StudentID integer, StudentName char(25) NOT NULL, primary key(StudentName)) CREATE TABLE FACULTY(FacultyID integer, FacultyName char(25) NOT NULL, primary key(FacultyID)) CREATE TABLE COURSE(CourseID integer, CourseName char(15) NOT NULL, primary key(CourseID)) CREATE TABLE QUALIFIED(DateQualified date, foreign key(FacultyID) references FACULTY(FacultyID), foreign key(CourseID) references COURSE(CourseID))
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT