https://en.wikipedia.org/wiki/Graz_school_shooting
The perpetrator legally owned both firearms used in the shooting through a firearms ownership card (Waffenbesitzkarte) but did not have a firearms carrying licence (Waffenpass ). The Glock semi-automatic pistol was purchased a few days before the shooting, while the shotgun had been in his possession for longer.[33] He had no prior criminal record, which is required to obtain a firearms ownership card in Austria.
So: background check before purchase? Didn't prevent a massacre. No permit to carry? Didn't prevent a massacre. I wonder if Austrian schools are "gun-free zones".
Afterwards he committed suicide by gunshot in the school lavatory.
Meaning all the criminal penalties that might have been applied after the fact were zero deterrent, as is usually the case.