Database UAS

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

Name: Trimardi Aditya Nandian Saputra

Class: LH01

NIM: 2440075933
1.
SELECT *
FROM Participant PR
JOIN OnGoingCourse OGC
ON PR.Participant_id = OGC.Participant_id
JOIN Course CR
ON OGC.Course_ID = CR.Course_ID
WHERE Course_Name = 'SQL Server' AND [Level] = 'Advanced';

2.
SELECT *
FROM
Teacher TR
WHERE
Teacher_ID IN(
SELECT TR.Teacher_ID
FROM Teacher
JOIN Course CR
ON TR.Teacher_ID = CR.Teacher_ID
WHERE
Course_Name = 'Project Management dan Leadership'
)

3.
GO
CREATE VIEW Active_Participants_and_Courses_during_January_2022
AS
SELECT
*
FROM Participant PR
JOIN OnGoingCourse OGC
ON PR.Participant_ID = OGC.Participant_ID
JOIN Course CR
ON OGC.Course_ID = CR.Course_ID
WHERE [Status] = 'Active' AND MONTH([Start_Date]) = '1' AND MONTH(End_Date) = '1' AND
YEAR([Start_Date]) = '2022' AND YEAR(End_Date) = '2022'

4.
CREATE TRIGGER trigger_participant on Participant FOR UPDATE
as Declare @oldvalue varchar(50)
Declare @newvalue varchar(50)

SELECT @oldvalue = Participant_Email from deleted


SELECT @newvalue = Participant_Email from inserted

Print ('Data lama = ' + @oldvalue)


Print ('Data baru = ' + @newvalue)

Print ('Data has been recorded')


5. In this transaction, inconsistent analysis occurs, because the summary of T2 transactions is executed
simultaneously with T1 transactions. Transaction T2 adds up the balances of account x (150) and
account y (50). However, meanwhile, transaction T3 has increased balance x by 50 and transaction T1
has reduced balance y by 20 so T3 now has an incorrect result (now worth 200 where it should be worth
230). This problem is avoided by preventing transaction T6 from reading balx and baly after T1 and T3
have completed their transaction.

2PL is a transaction follows the two-phase locking protocol if all locking operations precede the first
unlock operation in the transaction.

According to the rules of this protocol, every transaction can be divided into two phases: first a growing
phase, in which it acquires all the locks needed but cannot release any locks, and then a shrinking phase,
in which it releases its locks but cannot acquire any new locks. There is no requirement that all locks be
obtained simultaneously. Normally, the transaction acquires some locks, does some processing, and
goes on to acquire additional locks as needed. However, it never releases any lock until it has reached a
stage where no new locks are needed. The rules are:

• A transaction must acquire a lock on an item before operating on the item. The lock may be read or
write, depending on the type of access needed.

• Once the transaction releases a lock, it can never acquire any new locks. If upgrading of locks is
allowed, upgrading can take place only during the growing phase and may require that the transaction
wait until another transaction releases a shared lock on the item. Downgrading can take place only
during the shrinking phase

T1 T2 T3 Balx Baly Sum


t1 Begin transaction 150 50 -
t2 Sum=0 Begin transaction 150 50 0
t3 Begin transaction Write_lock(balx) 150 50 0
t4 Write_lock(baly) Read_lock(balx) Read(balx)
t5 Read(baly) WAIT balx=balx+50 150 50 0
t6 baly=baly-20 WAIT Write balx 200 50 0
t7 Write(baly) WAIT Commit/Unlock(balx) 200 30 0
t8 Commit/Unlock(baly) Read (balx) 200 30 0
t9 Sum=Sum+balx 200 30 200
t10 Read_lock(baly) 200 30 200
t11 Read(baly) 200 30 200
t12 Sum=sum+baly 200 30 230
t13 Commit/Unlock 200 30 230
(balx, baly)
6. Striping is the process of dividing the body of data into so-called "block sizes" and writing those
blocks across the RAID one by one. A stripe consists of data distributed across a set of hard drives or
SSDs, and a stripe unit refers to a slice of data on a single drive.

Source: https://storagetutorials.com/storage/2013/03/RAID-Striping.png

There is no redundancy or fault tolerance for disk striping without parity data. That is, if a drive fails, all
data on that drive will be lost. Disk stripping also known as RAID 0 is best used for storage that is
noncritical but requires fast reads and writes. Livestreaming video caching and video editing are
common uses for disk stripping. Non-redundant disk striping can be used in situations where temporary
data, memory, or a master copy of data can be easily recovered from another storage device. The main
advantage of RAID 0 and disk striping is improved performance. For instance, striping data to three hard
drives provides three times the bandwidth of one drive. If each drive is running at 200 I / O operations
per second, disk striping provides up to 600 IOPS for reading and writing data. However, low resiliency is
the disadvantage of disk striping. Disk striping. does not use data redundancy, so the failure of any
physical drive in the striped disk set results in the loss of the data on the striped unit and, consequently,
the loss of the entire data set stored across the set of striped hard disks. It should not be used for
mission-critical storage.

Disk mirroring is the replication of data to two or more disks. As the name implies, which means 'to
reflect', the principle of mirroring will copy data on another hard disk with the exact same contents in
real time.
Source: https://www.prepressure.com/images/raid-level-1-mirroring.svg

Because both drives are operational, data can be read from them simultaneously, which makes read
operations quite fast. The RAID array will operate if one drive is operational. Write operations, however,
are slower because every write operation is done twice. Disk (drive) mirroring is particularly
advantageous for disaster recovery scenarios as it provides instantaneous failover for data required by
mission-critical applications. If primary drives in the array are damaged or unable to operate, traffic is
switched to secondary or mirrored backup drives. The mirror copy is able to become operational on
failover because the operating system and application software are replicated to the mirror along with
the data used by the applications.
We can choose RAID 10 (or RAID 0 + 1) as the most suitable RAID type GoTraining database because it
combines the advantages of RAID 0 and RAID 1 in one single system. This is a nested or hybrid RAID
configuration. It provides security by mirroring all data on secondary drives while using striping across
each set of drives to speed up data transfers. In GoTraining database, it is a centralized database that is
physically located in Jakarta and can be accessed by its branches in Bandung and Surabaya. Therefore,
we need a RAID that can be read and write fast simultaneously because GoTraining branches have to
access the database that centralized physically in Jakarta. Not only that, GoTraining also need RAID that
can duplicate the database if something terrible happen. If primary drives in the array are damaged or
unable to operate, traffic is switched to secondary or mirrored backup drives. The mirror copy is able to
become operational on failover because the operating system and application software are replicated to
the mirror along with the data used by the applications.

7. The most suitable fragmentation is mixed fragmentation. Mixed fragmentation consists of a


horizontal fragment that is subsequently vertically fragmented, or a vertical fragment that is then
horizontally fragmented. In this case, we use a mixed fragmentation with vertical fragmentation first
then horizontal fragmented because we must split the tuple into:

S1: Π Participant id
, Pfirst Name , Plast Name , Phone Number , Participant email (Participant )

S2: Π Participant id
,Client id (Participant)

We could now horizontally fragment S2 according to Client_id

S21: σ Client id =‘ C 10‘

S22: σ Client id =‘ C 11‘

S23: σ Client id =‘ C 12‘

I choose this fragmentation because the database would be resided in several branches. I also choose
this fragmentation because it makes it easier to categorize client_Id according to the branch

Fragment S1

Participant_id PFirst_Name Plast_Name Phone_Number Participant_email


PP152 David Ford ++62861617 17 [email protected]
om
PP514 Matthew Lee +628561716 11 Matthew.Lee@mail.
com
PP432 Maria White +628156254 16 Maria.White@mail.
com
PP651 Susan Susan +628161617 19 [email protected]
om
Fragment S21

Participant_Id Client_Id
PP651 C10

Fragment S22

Participant_Id Client_Id
PP432 C11

Fragment S23

Participant_Id Client_Id
PP152 C12
PP514 C12

8. Here is the link about my video, thank you

https://www.loom.com/share/768d75eb421a4c7aaa7994c988630cda

You might also like