0% found this document useful (0 votes)
11 views3 pages

2DG1 AniagJohnRay Act5

This document creates databases and tables to store data about colleges, courses, and faculty members. It defines the structure of tables for College, Faculty, and Course and inserts sample data. Finally, it runs queries to select and display data from the tables, such as listing faculty members and their years of service by college.

Uploaded by

John Ray Aniag
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views3 pages

2DG1 AniagJohnRay Act5

This document creates databases and tables to store data about colleges, courses, and faculty members. It defines the structure of tables for College, Faculty, and Course and inserts sample data. Finally, it runs queries to select and display data from the tables, such as listing faculty members and their years of service by college.

Uploaded by

John Ray Aniag
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

create database AniagJohnRaySQL1

use AniagJohnRaySQL1

create table College(


CollegeCode varchar(20) constraint prim_key primary key,
CollegeName varchar(80) not null
)

create table Faculty (


EmpID int constraint empid_pk primary key,
FirstName varchar(50) not null,
MiddleName varchar(50),
LastName varchar(50) not null,
Bdate datetime,
EmpRank varchar(50),
Position varchar(20),
EmploymentStatus varchar(50),
HireDate datetime,
Salary decimal(10, 2),
RATA decimal(10, 2),
SupervisorID int constraint ssub_forkey references Faculty(EmpId),
ColCode varchar(20) constraint csub_forkey references College(CollegeCode)
)

create table Course(


CourseCode varchar(20),
CourseDescription varchar(80)not null,
ColCode varchar(20))

insert into College


values ('CAL', 'College of Arts & Letters'),
('CICT', 'College of Information & Communication Technology'),
('CIT', 'College of Industrial Technology'),
('COE', 'College of Engineering'),
('CON', 'College of Nursing')

insert into Course


values('BIT', 'Bachelor in Industrial Technology', 'CIT'),
('BLIS', 'Bachelor of Library Information Science', 'CICT'),
('BSCOE', 'Bachelor of Science in Computer Engineering', 'COE'),
('BSIT', 'Bachelor of Science in Information Technology', 'CICT'),
('BSN', 'Bachelor og Science in Nursing', 'CON')

insert into Faculty


values ('100', 'Keno', 'C.', 'Piad', '1985-05-04', 'Professor II', 'Dean', 'R', '2010-05-
06',102000.00, 15000.00, NULL, NULL),
('101', 'Digna', 'S.', 'Evale', '1980-06-25', 'Professor V', 'College Secretary', 'R',
'2000-06-06', 122000.00, 10000.00, '100', 'CICT'),
('102', 'Rose', 'C.', 'Mendoza', '1980-05-25', 'Professor II', 'Department Head', 'R',
'2001-06-10', 102000.00, 10000.00, '100', 'CICT'),
('103', 'Ana', 'S.', 'Cruz', '1989-05-25', 'Associate Professor II', 'Dean', 'R', '2010-
02-10', 54000.00, 15000.00, NULL, 'CON'),
('104', 'John', 'C.', 'De Vera', '1995-08-04', 'Instructor III', 'Faculty', 'R', '2011-
03-15', 38000.00, NULL, '103', 'CON'),
('105', 'Melanie', 'P.', 'Santos', '1981-03-28', 'Associate Professor II', 'Department
Head', 'R', '2001-06-10', 54000.00, NULL, '100', 'CICT'),
('106', 'Robert', 'C.', 'Gonzales', '1990-05-21', 'Instructor I', 'Faculty', 'C', '2015-
06-10', 22000.00, NULL, '103', 'CON'),
('107', 'Rina', 'C.', 'Delos Reyes', '1980-08-25', 'Professor III', 'Dean', 'R', '2002-
10-02', 112000.00, 10000.00, NULL, 'COE'),
('108', 'Gabriel', 'C.', 'Canlas', '1994-04-23', 'Instructor II', 'Faculty', 'R', '2007-
06-10', 32000.00, NULL, '107', 'COE'),
('109', 'Jay', 'P.', 'Zamora', '1991-02-25', 'Assistant Professor I', 'Faculty', 'C',
'2001-06-10', 42000.00, NULL, '107', 'COE'),
('110', 'Juan', null , 'Dela Cruz', '1997-02-19', null, null , null , '2021-06-15', null,
null, null, null )

select* from Faculty


select* from College
select * from Course

--1--
select CollegeName, LastName, Cast(Datediff("yy",HireDate,getdate())as varchar) as "Year
of Service" from College,Faculty
where ColCode = CollegeCode
order by CollegeName

--2--
select CollegeName,FirstName+ ' ' +MiddleName+ ' ' +LastName as "Faculty Name",
Cast(Datediff("yy",HireDate,getdate())as varchar) as "Year of Service" from
COLLEGE,FACULTY
where ColCode = CollegeCode and ColCode = 'CICT' or ColCode = CollegeCode and ColCode =
'CON'
order by HireDate

--3--
select z.FirstName + ' ' + z.LastName + ' is reporting to ' + x.FirstName + ' ' +
x.LastName as 'Reporters'
from Faculty as z, Faculty as x
where z.SupervisorID = x.EmpID

--4--
select College.CollegeName, Course.CourseDescription
from College left join Course
on College.CollegeCode = Course.ColCode

--5--
select Faculty.FirstName + ' ' + Faculty.LastName as 'Faculty' , College.CollegeName
from Faculty inner join College on Faculty.ColCode = College.CollegeCode

select College.CollegeCode , CollegeName


from Faculty right join College on CollegeName = College.CollegeCode

--6--
select Faculty.FirstName + ' ' + Faculty.LastName as 'Faculty', College.CollegeName
from Faculty right join College on Faculty.ColCode = College.CollegeCode

You might also like