I did the work#37
Conversation
ghost
left a comment
There was a problem hiding this comment.
Excellent! See comments, fix and resubmit.
|
|
||
| create table dbo.confectionary( | ||
| confectionaryID int not null identity primary key, | ||
| FullName varchar(30) not null, |
| constraint ck_confectionary_branch_can_only_be_lakewood_or_brooklyn check(branch in ('Lakewood', 'Brooklyn')), | ||
| DateOrdered date not null | ||
| constraint ck_confectionary_DateOrdered_cant_be_before_january_1_2021 check(DateOrdered >= '01/01/2021'), | ||
| TypeOfBase varchar(25) not null, |
| TypeOfBase varchar(25) not null, | ||
| Item varchar(8) not null | ||
| constraint ck_confectionary_item_can_only_be_cake_cupcake_or_cookie check (item in ('cake', 'cupcake', 'cookie')), | ||
| Topping varchar(15) not null, |
| Item varchar(8) not null | ||
| constraint ck_confectionary_item_can_only_be_cake_cupcake_or_cookie check (item in ('cake', 'cupcake', 'cookie')), | ||
| Topping varchar(15) not null, | ||
| Picture varchar(3) not null |
| Picture varchar(3) not null | ||
| constraint ck_confectionary_picture_must_eitehr_be_yes_or_no check(picture in ('yes', 'no')), | ||
| Specifics varchar(100) null, | ||
| Occasion varchar(35) not null, |
| Specifics varchar(100) null, | ||
| Occasion varchar(35) not null, | ||
| Amount int not null | ||
| constraint ck_confectionary_amount_cannot_be_more_than_Five_hundred check(amount <= 500), |
There was a problem hiding this comment.
Instead of doing 2 check constraints. Combine them together using between or and.
| constraint ck_confectionary_amount_cannot_be_more_than_Five_hundred check(amount <= 500), | ||
| PricePerItem as | ||
| case | ||
| when item = 'Cookie' then 3.50 |
There was a problem hiding this comment.
You need to include in logic the price for those with pictures. That would be price per item.
There was a problem hiding this comment.
The way you did it now won't work because the line when item = 'Cookie' then 3.50 is executed first so it will return 3.50 whether it has a picture or not.
| when item = 'cupcake' then 3.00 | ||
| end, | ||
|
|
||
| PriceOfOrder as |
There was a problem hiding this comment.
This can use same case statement as PricePerItem. Just add * amount after doing the case.
There was a problem hiding this comment.
After end of case do * amount to make all cases * amount.
| @@ -0,0 +1,29 @@ | |||
| use ConfectionaryDB | |||
| go | |||
|
|
|||
|
I made the changes. |
ghost
left a comment
There was a problem hiding this comment.
Excellent improvements! See comments, fix and resubmit.
| constraint ck_confectionary_item_can_only_be_cake_cupcake_or_cookie check (item in ('cake', 'cupcake', 'cookie')), | ||
| Topping varchar(15) not null | ||
| constraint c_must_be_specific_topping check(Topping in ('Fondant', 'Frosting', 'Royal icing', 'chocolate peanut butter', 'vanilla', 'chocolate', 'caramel', 'strawberry', 'coconut', 'peanut butter', 'none')), | ||
| Picture bit, |
| constraint ck_confectionary_amount_cannot_be_more_than_Five_hundred check(amount <= 500), | ||
| PricePerItem as | ||
| case | ||
| when item = 'Cookie' then 3.50 |
There was a problem hiding this comment.
The way you did it now won't work because the line when item = 'Cookie' then 3.50 is executed first so it will return 3.50 whether it has a picture or not.
| when item = 'cupcake' then 3.00 | ||
| end, | ||
|
|
||
| PriceOfOrder as |
There was a problem hiding this comment.
After end of case do * amount to make all cases * amount.
ghost
left a comment
There was a problem hiding this comment.
Excellent! 100% See comments, no need to resubmit.
| Specifics varchar(100) null, | ||
| Occasion varchar(35) not null, | ||
| Amount int not null | ||
| constraint ck_confectionary_amount_cannot_be_more_than_Five_hundred check(amount <= 500), |
There was a problem hiding this comment.
Instead of doing 2 check constraints. Combine them together using between or and.
| when picture =1 and item = 'cookie' then 3.50 +1.50*amount | ||
| when picture = 1 and item = 'cake' and typeOfBase = 'Strawberry Shortcake' then 55.00+8.00*amount | ||
| when picture = 1 and item = 'cake' and typeOfBase <> 'Strawberry Shortcake' then 50.00+8.00*amount | ||
| end * amount, |
There was a problem hiding this comment.
If you're doing * amount here, you should remove it from inside the case statement. I just recommended to do it here instead of doing it multiple times.
confectionary