0% found this document useful (0 votes)
32 views9 pages

Tugas Basis Data

This document contains the name and student ID of a student followed by SQL statements to create tables, insert, update, delete and select data from the tables. The tables created are for courses, faculty, student registration and qualifications. Several queries are written to select data from the tables based on certain conditions, counts, groups and orderings.

Uploaded by

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

Tugas Basis Data

This document contains the name and student ID of a student followed by SQL statements to create tables, insert, update, delete and select data from the tables. The tables created are for courses, faculty, student registration and qualifications. Several queries are written to select data from the tables based on certain conditions, counts, groups and orderings.

Uploaded by

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

TUGAS BASIS DATA

NAMA : LELY MONALISA

NIM : 16/395402/TK/44694

1.
CREATE TABLE `course` (
`CourseID` int(8) NOT NULL,
`courseNAME` varchar(15) NOT NULL,
PRIMARY KEY (`CourseID`)
)
CREATE TABLE `faculty` (
`FacultyID` int(11) NOT NULL,
`FacultyName` varchar(25) NOT NULL,
PRIMARY KEY (`FacultyID`)
)
CREATE TABLE `qualified` (
`FacultyID` int(11) NOT NULL,
`CourseID` int(11) NOT NULL,
`DateQualified` varchar(25) NOT NULL,
KEY `FacultyID_idx` (`FacultyID`),
KEY `CourseID_idx` (`CourseID`),
CONSTRAINT `CourseID` FOREIGN KEY (`CourseID`) REFERENCES `course` (`CourseID`) ON DELETE
CASCADE ON UPDATE CASCADE,
CONSTRAINT `FacultyID` FOREIGN KEY (`FacultyID`) REFERENCES `faculty` (`FacultyID`) ON
DELETE NO ACTION ON UPDATE NO ACTION
)
CREATE TABLE `section` (
`SectionNo` int(11) NOT NULL,
`Semester` varchar(25) NOT NULL
)
REATE TABLE `student` (
`id` int(11) NOT NULL,
`Name` varchar(25) NOT NULL,
PRIMARY KEY (`id`)
)

2.

EROR.. karena terdapat primery key dengan isi/data yang sama padahal primery key hanya boleh
mempunyai 1 ID/no.

3.

CREATE TABLE COURSE ( CourseID CHAR(8) NOT NULL, CourseName VARCHAR(15) NOT NULL,
CONSTRAINT Course_PK PRIMARY KEY (CourseID) );

Namun bisanya untuk foreign key membutuhkan inputan yang berupa restrict, set null,cascade,

Restrict : Nothing gonna be delete if there is a child row

Cascade : the child row will be delete / update too

Set Null : the child column will be set to null if you delete the parent

No action : The child row will not be concern of the delete / update
Stack Exchange.2017. Mysql workbench foreign key options [Restrict, Cascade, Set Null, No
Action], what do they do?. http://stackoverflow.com/questions/16163301/mysql-
workbench-foreign-key-options-restrict-cascade-set-null-no-action-wh (diakses 28 April
2017)
4.
a. INSERT INTO `schema`.`students` (`StudentID`, `StudentName`) COURSE ('ID_Course', 'Name_Course');
b. DROP TABLE IF EXISTS REGISTRATION;

c. ALTER TABLE `new_schema1234`.`new_table`

CHANGE COLUMN `nama` `nama` VARCHAR(45) NOT NULL ;

5.

a. INSERT INTO STUDENTS (StudentID,StudentName) VALUES (65798, 'Lopez');

INSERT INTO STUDENTS VALUES (65798, 'Lopez');

b. DELETE FROM STUDENTS WHERE StudentID = 65798;

c. UPDATE COURSE SET CourseName = ' Introduction to Relational Databases ' WHERE CourseID = 'ISM
4212' ;

6.

a. SELECT StudentID, StudentName


FROM STUDENT

WHERE StudentID < 50000;

b. SELECT FacultyName
FROM FACULTY

WHERE FacultyID = 4756;


c. SELECT MIN(SectionNo)
FROM REGISTRATION

WHERE Semester= 'I-2008';

a. 7. SELECT COUNT(*)

FROM REGISTRATION

WHERE SectionNo=2714 AND Semester='I-2008';

b. SELECT FacultyID, CourseID, DateQualified


FROM QUALIFIED

WHERE DateQualified >= '1993-01-01';

8.a. SELECT StudentID, COUNT(*)


FROM REGISTRATION
WHERE SectionNo IN (2714, 2715)
GROUP BY StudentID

HAVING COUNT(*) = 2;

b. SELECT FacultyID, COUNT(*)


FROM QUALIFIED

WHERE CourseID IN ('ISM 3112', 'ISM 3113')


GROUP BY FacultyID

HAVING COUNT(*) = 1;

9.a. SELECT DISTINCT CourseID


FROM SECTION;
b. SELECT StudentName
FROM STUDENT

ORDER BY StudentName;

c. SELECT SectionNo, StudentID


FROM REGISTRATION

ORDER BY SectionNo, StudentID

d. SELECT CourseID, CourseName

FROM COURSE

ORDER BY CourseID

You might also like