I did the work for the Army biz scenario#44
Conversation
ghost
left a comment
There was a problem hiding this comment.
Excellent work! See comments, fix and resubmit.
| constraint c_Soldiers_soldier_last_name_cannot_be_blank check(SoldierLastName <> ''), | ||
| SoldierFirstName varchar(25) not null | ||
| constraint c_Soldiers_soldier_first_name_cannot_be_blank check(SoldierFirstName <> ''), | ||
| SoldierSSN char(10) not null |
There was a problem hiding this comment.
SSN must be in specific format. It should be 8 digits followed by a hyphen followed by one digit.
There was a problem hiding this comment.
done. I deleted the not blank constraint also.
| constraint c_Soldiers_soldier_SSN_cannot_be_blank check(SoldierSSN <> '') | ||
| constraint u_Soldiers_soldier_SSN_ unique, | ||
| SoldierDOB date not null | ||
| constraint c_Soldiers_soldier_DOB_cannot_be_blank check(SoldierDOB <> ''), |
There was a problem hiding this comment.
Why don't you allow a soldier to be born on 01/01/1900? This is the date returned from a blank date.
There was a problem hiding this comment.
I deleted the DOB cannot be blank constraint
| SoldierRank varchar(25) not null | ||
| constraint c_Soldier_soldier_rank_cannot_be_blank check(SoldierRank <> ''), | ||
| SoldierIQ int not null | ||
| constraint c_Soldiers_soldier_IQ_cannot_be_blank check(SoldierIQ <> ''), |
There was a problem hiding this comment.
I'm confused here. Do you allow 0 IQ? This constraint blocks 0 but the next one allows.
Why do you even have this constraint? This is a int column and this constraint is for varchars.
There was a problem hiding this comment.
I deleted the not blank constraint.
| constraint c_Soldier_soldier_rank_cannot_be_blank check(SoldierRank <> ''), | ||
| SoldierIQ int not null | ||
| constraint c_Soldiers_soldier_IQ_cannot_be_blank check(SoldierIQ <> ''), | ||
| constraint c_Soldiers_soldier_IQ_cannot_be_negative check(SoldierIQ >= 0), |
There was a problem hiding this comment.
Ok I switched this constraint to soldier IQ must be greater than 0.
| SoldierIQ int not null | ||
| constraint c_Soldiers_soldier_IQ_cannot_be_blank check(SoldierIQ <> ''), | ||
| constraint c_Soldiers_soldier_IQ_cannot_be_negative check(SoldierIQ >= 0), | ||
| SoldierAgeAtEnlistment as datepart(year, SoldierDateOfEnlistment) - datepart(year, SoldierDOB) persisted not null, |
There was a problem hiding this comment.
Tip: Use datediff(). You don't need the extra not null constraint, both columns don't allow null and this is a computed column.
| constraint c_Soldiers_soldier_IQ_cannot_be_blank check(SoldierIQ <> ''), | ||
| constraint c_Soldiers_soldier_IQ_cannot_be_negative check(SoldierIQ >= 0), | ||
| SoldierAgeAtEnlistment as datepart(year, SoldierDateOfEnlistment) - datepart(year, SoldierDOB) persisted not null, | ||
| constraint c_Soldiers_soldier_date_of_enlistment_cannot_be_before_17_years_after_soldier_DOB check(datepart(year, SoldierDateOfEnlistment) >= datepart(year, SoldierDOB) + 17) |
There was a problem hiding this comment.
This can be a constraint on the computed column not to allow an age less than 17.
There was a problem hiding this comment.
Ok thank you. I fixed it.
| (This should be done by using a union select and adding a literal column for year range.) | ||
| */ | ||
|
|
||
| select concat('2017-2019', ' ', s.SoldierFirstName, ' ', s.SoldierLastName, ' - ', s.SoldierSSN, ' (', s.SoldierDateOfEnlistment, ')', ', ', s.ServiceUnit) |
|
|
||
| select concat('2017-2019', ' ', s.SoldierFirstName, ' ', s.SoldierLastName, ' - ', s.SoldierSSN, ' (', s.SoldierDateOfEnlistment, ')', ', ', s.ServiceUnit) | ||
| from Soldiers s | ||
| where datepart(year, s.SoldierDateOfEnlistment) between 2017 and 2019 |
ChanaCohen3896
left a comment
There was a problem hiding this comment.
Hi, I went through all the comments and fixed the table and reports.
| (This should be done by using a union select and adding a literal column for year range.) | ||
| */ | ||
|
|
||
| select concat('2017-2019', ' ', s.SoldierFirstName, ' ', s.SoldierLastName, ' - ', s.SoldierSSN, ' (', s.SoldierDateOfEnlistment, ')', ', ', s.ServiceUnit) |
|
|
||
| select concat('2017-2019', ' ', s.SoldierFirstName, ' ', s.SoldierLastName, ' - ', s.SoldierSSN, ' (', s.SoldierDateOfEnlistment, ')', ', ', s.ServiceUnit) | ||
| from Soldiers s | ||
| where datepart(year, s.SoldierDateOfEnlistment) between 2017 and 2019 |
| constraint c_Soldiers_soldier_last_name_cannot_be_blank check(SoldierLastName <> ''), | ||
| SoldierFirstName varchar(25) not null | ||
| constraint c_Soldiers_soldier_first_name_cannot_be_blank check(SoldierFirstName <> ''), | ||
| SoldierSSN char(10) not null |
There was a problem hiding this comment.
done. I deleted the not blank constraint also.
| constraint c_Soldiers_soldier_SSN_cannot_be_blank check(SoldierSSN <> '') | ||
| constraint u_Soldiers_soldier_SSN_ unique, | ||
| SoldierDOB date not null | ||
| constraint c_Soldiers_soldier_DOB_cannot_be_blank check(SoldierDOB <> ''), |
There was a problem hiding this comment.
I deleted the DOB cannot be blank constraint
| SoldierRank varchar(25) not null | ||
| constraint c_Soldier_soldier_rank_cannot_be_blank check(SoldierRank <> ''), | ||
| SoldierIQ int not null | ||
| constraint c_Soldiers_soldier_IQ_cannot_be_blank check(SoldierIQ <> ''), |
There was a problem hiding this comment.
I deleted the not blank constraint.
| constraint c_Soldier_soldier_rank_cannot_be_blank check(SoldierRank <> ''), | ||
| SoldierIQ int not null | ||
| constraint c_Soldiers_soldier_IQ_cannot_be_blank check(SoldierIQ <> ''), | ||
| constraint c_Soldiers_soldier_IQ_cannot_be_negative check(SoldierIQ >= 0), |
There was a problem hiding this comment.
Ok I switched this constraint to soldier IQ must be greater than 0.
| SoldierIQ int not null | ||
| constraint c_Soldiers_soldier_IQ_cannot_be_blank check(SoldierIQ <> ''), | ||
| constraint c_Soldiers_soldier_IQ_cannot_be_negative check(SoldierIQ >= 0), | ||
| SoldierAgeAtEnlistment as datepart(year, SoldierDateOfEnlistment) - datepart(year, SoldierDOB) persisted not null, |
| constraint c_Soldiers_soldier_IQ_cannot_be_blank check(SoldierIQ <> ''), | ||
| constraint c_Soldiers_soldier_IQ_cannot_be_negative check(SoldierIQ >= 0), | ||
| SoldierAgeAtEnlistment as datepart(year, SoldierDateOfEnlistment) - datepart(year, SoldierDOB) persisted not null, | ||
| constraint c_Soldiers_soldier_date_of_enlistment_cannot_be_before_17_years_after_soldier_DOB check(datepart(year, SoldierDateOfEnlistment) >= datepart(year, SoldierDOB) + 17) |
There was a problem hiding this comment.
Ok thank you. I fixed it.
No description provided.