LAB4
LAB4
Question1
CREATE TABLE Departments (
DeptID CHAR(2) PRIMARY KEY,
Name NVARCHAR(50) NOT NULL,
NoOfStudents INT
);
INSERT INTO Students (StudentID, LastName, FirstName, Sex, DateOfBirth, PlaceOfBirth, DeptID,
Scholarship, AverageScore) VALUES
('S001', 'Lê', 'Kim Lan', 'F', '1990-02-23', 'Hà nội', 'IS', 130000, NULL),
('S002', 'Trần', 'Minh Chánh', 'M', '1992-12-24', 'Bình Định', 'NC', 150000, NULL),
('S003', 'Lê', 'An Tuyết', 'F', '1991-02-21', 'Hải phòng', 'IS', 170000, NULL),
('S004', 'Trần', 'Anh Tuấn', 'M', '1993-12-20', 'TpHCM', 'NC', 80000, NULL),
('S005', 'Trần', 'Thị Mai', 'F', '1991-08-12', 'TpHCM', 'SE', 0, NULL),
('S006', 'Lê', 'Thị Thu Thủy', 'F', '1991-01-02', 'An Giang', 'IS', 0, NULL),
('S007', 'Nguyễn', 'Kim Thư', 'F', '1990-02-02', 'Hà Nội', 'SE', 180000, NULL),
('S008', 'Lê', 'Văn Long', 'M', '1992-12-08', 'TpHCM', 'IS', 190000, NULL);
INSERT INTO Results (StudentID, CourseID, Year, Semester, Mark, Grade) VALUES
('S001', 'DS01', 2017, 1, 3, NULL),
('S001', 'DS01', 2017, 2, 6, NULL),
('S001', 'AI01', 2017, 1, 4.5, NULL),
('S001', 'AI01', 2017, 2, 6, NULL),
('S001', 'CN01', 2017, 3, 5, NULL),
('S002', 'DS01', 2016, 1, 4.5, NULL),
('S002', 'DS01', 2017, 1, 7, NULL),
('S002', 'CN01', 2016, 3, 10, NULL),
('S002', 'DSA1', 2016, 3, 9, NULL),
('S003', 'DS01', 2017, 1, 2, NULL),
('S003', 'DS01', 2017, 3, 5, NULL),
('S003', 'CN01', 2017, 2, 2.5, NULL),
('S003', 'CN01', 2017, 3, 4, NULL),
('S004', 'DS01', 2017, 3, 4.5, NULL),
('S004', 'DSA1', 2018, 1, 10, NULL),
('S005', 'DS01', 2017, 2, 7, NULL),
('S005', 'CN01', 2017, 2, 2.5, NULL),
('S005', 'CN01', 2018, 1, 5, NULL),
('S006', 'AI01', 2018, 1, 6, NULL),
('S006', 'CN01', 2018, 2, 10, NULL);
UPDATE Students
Update Results
else 'Failed'
End
where Scholarship<=160000
Question 6.
from Departments
left join Students on
Departments.DeptID=Students. DeptID
C1:
C2:
UNION
from Departments
Show the list of students which are not in the department 'Information Systems' but having
Mark of Database Systems greater than at least one student of department 'Information
Systems'.
select students. StudentID, LastName, FirstName, DeptID