Lab 2
Lab 2
Lab 2
Table: Publisher
PublisherID Name Address
P01 Pearson Bukit Jalil
P02 Deitel Puchong
P03 Rainbow Subang
P04 MacHill Kuala Lumpur
Table: Book
BookID Name Author Price PublishedDat PublisherID
e
B01 Maths J.Wenton 50.60 10 Jan 2016 P01
B02 Science S.Hanson 100.00 12 Feb 2016 P01
B03 English K.Vince 89.30 9 March 2016 P02
B04 Biology K.Vince 150.80 24 April 2016 P03
B05 Computi J.Denzin NULL NULL NULL
ng
*for decimal data type, we can only insert 10 digits (including decimal point)
Correct: 12345678.91
Wrong: 123456789.91
However if we insert 3 decimal point (eg: 12345678.456)
It will automatically round off to 2 decimal points
4. Try to insert a new row in Book Table where PublisherID does not exist in
Publisher table. Can or cannot? Why?
Cannot PublisherID in Book Table is foreign key
While we cannot insert more than 1 value in the fk column even though the
values are valid
5. Try to delete the row for Publisher named Deitel. Can or cannot? Why
Cannot
Because there is related data in the same row (‘P02’) which is used in the FK
of Book Table
6. Try to delete the row for Publisher named MacHill. Can or cannot? Why
Can
Because its PK (‘P04’) is not used in the FK of Book Table
Reference:
https://www.w3schools.com/sql/default.asp