Background:
I am junior developer (about 1 year of experience) who was recently hired at a company smaller than 150 people less than 6 months ago. The web software team is made up of less than 5 people, and everyone in it is focused on front-end web development besides the senior who does all the back-end work to keep the website running.
The senior engineer has been with the company for more than 20 years and wrote most of the website and all of the back-end framework code that we use to serve the website (without which the website would break). I generally try to avoid asking him questions because I can tell he is stressed, and from his body language, replies, and tone I have interpreted that he finds my questions very annoying and a waste of time.
Main issue:
Today I was trying to fix an issue with a web page I was updating, and this page was not showing any information from the database. I was asking a coworker (not the senior) if they could look at my code to see where I was making a mistake.
They started to explain what I was doing wrong, at which point the senior engineer walked over from his office, and started to ask me questions about the code I had written into the page and what the mistake I had made was. I tried to answer all of his questions but he was getting angry because I was taking a long time to explain.
When I explained the mistake, he angrily yelled at me and said "If you use a comma delimited string as a SQL parameter on the website again, I will beat you senseless". I replied that I understood and will not use it. He then told me to look up another object type to pass to the database and then he left.
I understand that I am a junior developer and that I need to respect and listen to the more knowledgeable superior. However after the discussion I felt very sad and angry because what he had said to me. I felt like quitting right there. I am afraid that the senior engineer might ask for me to be fired (he said he has done it to others in the past), which would look bad on my record. But I feel like quitting so soon could be bad too.
Should I stay and accept that I need to write better code to avoid events like this? Is what the senior engineer said normal?