Sei sulla pagina 1di 5

Kennardy Salim - 2301860255

LJ-11

MID TEST INTRODUCTION TO DATABASE SYSTEMS

Table: Staff
Attribute Name Data Type Constraints Note
StaffId Char (5) Must start with “ST” Primary key
follow up by 3 random
numbers, Ex: “ST001”
StaffName Varchar (20) NOT NULL
StaffAddress Varchar (25) Must start with “Jl.”
StaffPhone Varchar (15) NOT NULL
DateOfBirth Date NOT NULL
Position Varchar (20) Manager or Senior
Instructor or Instructors,
or Administrative staff,
NOT NULL
BranchId Char (5) Must start with “BR” Foreign key
follow up by 3 random ON UPDATE
numbers, Ex: “BR001” CASCADE ON
DELETE SET
NULL
VehicleId Char (5) Must start with “VH” Foreign key
follow up by 3 random ON UPDATE
numbers, Ex: “VH001” CASCADE ON
DELETE SET
NULL

Table: Student
Attribute Name Data Type Constraints Note
StudentId Char (5) Must start with “SU” Primary key
follow up by 3 random
numbers, Ex: “SU001”
StudentName Varchar (20) NOT NULL
StudentAddress Varchar (25) Must start with “Jl.”
StudentPhone Varchar (15) NOT NULL
Gender Varchar (10) Male or Female, NOT
NULL
InterviewReport Varchar (200) NOT NULL

LicenseType Varchar (15) Provisional or Full, NOT


NULL
LessonId Char (5) Must start with “LE” Foreign key
follow up by 3 random ON UPDATE
numbers, Ex: “LE001” CASCADE ON
DELETE SET
NULL
TestDate Date NOT NULL Foreign key
ON UPDATE
CASCADE ON
DELETE SET
NULL
TestStatus Varchar (5) Must be ‘Pass’ or ‘Fail’, Foreign key
NOT NULL ON UPDATE
CASCADE ON
DELETE SET
NULL

Table: Vehicle
Attribute Name Data Type Constraints Note
VehicleId Char (5) Must start with “VH” Primary key
follow up by 3 random
numbers, Ex: “VH001”
RegisNum Varchar (10) NOT NULL
CheckDate Date NOT NULL
VehicleFaults Varchar (40)

Table: Lesson
Attribute Name Data Type Constraints Note
LessonId Char (5) Must start with “LE” Primary key
follow up by 3 random
numbers, Ex: “LE001”
LessonTime Time Must be between 8 AM
and 8 PM
TestId Char (5) Must start with “TE”
follow up by 3 random
numbers, Ex: “TE001”
TestStatus Varchar (5) Must be ‘Pass’ or ‘Fail’

TestDate Date NOT NULL

StudentId Char (5) Must start with “SU” Foreign key


follow up by 3 random ON UPDATE
numbers, Ex: “SU001” CASCADE ON
DELETE SET
NULL
StaffId Char (5) Must start with “ST” Foreign key
follow up by 3 random ON UPDATE
numbers, Ex: “ST001” CASCADE ON
DELETE SET
NULL

Table: Branch

Attribute Name Data Type Constraints Note


BranchId Char (5) Must start with “BR” Primary key
follow up by 3 random
numbers, Ex: “BR001”
BranchAddress Varchar (20) Must start with “Jl.”
BranchPhone Varchar (15) NOT NULL

2. SQL Statement Using No.1


a. The names and the telephone numbers of the Managers of the office
SELECT StaffName, StaffPhone
FROM Staff
WHERE Position = ‘Manager’
b. The total number of staff at the office
SELECT COUNT(*)
FROM Staff
c. The total number of female and male client
SELECT COUNT(Gender) AS TotalMale
FROM Student
WHERE Gender = ‘Male’
SELECT COUNT(Gender) AS TotalFemale
FROM Student
WHERE Gender = ‘Female’
d. The registration number of cars that have had no faults found
SELECT RegisNum
FROM Vehicle
WHERE VehicleFaults IS NULL
e. The ID and name of staff who are Instructors and over 55 years old
SELECT StaffId, StaffName
FROM Staff
WHERE Position = ‘Instructor’ AND
DATEDIFF(YY,DateOfBirth,GETDATE()) >55
f. The names of clients who passed the driving test in January 2013
SELECT StudentName
FROM Student
WHERE LessonStatus = ‘Pass’ AND DATEPART(month,TestDate)
= ‘01’ AND DATEPART(year, TestDate) = ‘2013’
g. The details of interviews conducted by a given Instructor
SELECT InterviewReport, LicenseType
FROM Student

Berikut adalah link dari video saya:

https://drive.google.com/open?id=1TfJneT_DQmX4t57lJ3qrc1W-8QiNo_Qj

Potrebbero piacerti anche