Gamification, defined as the integration of game elements into non-gaming environments, is a promising approach to increase student engagement, motivation, and performance in Computer Science and Software Engineering education. This viewpoint encouraged the creation of QueryCompetition, a web system that allows students to practice SQL in a competitive environment. Our goal was to obtain empirical evidence on how gamifying elements, such as challenges, points, and leaderboards, integrated into QueryCompetition, affect student performance, motivation, and user experience. We carried out a quasi-experimental study with two groups in a Database course. One group used a gamified version of QueryCompetition having access to points and leaderboards, while the other used a non-gamified version with no access to the above mentioned elements. Quantitative and qualitative data were collected through tests and a survey. The results showed that there was a statistically significant improvement in student performance in the gamified group as compared to the non-gamified group. In addition, a higher motivation was observed in the gamified group. The empirical evidence presented in this article supports the claim that inclusion of challenges, points, and leaderboards, together with the competitive nature of QueryCompetition, impacts positively on student performance and motivation to practice SQL.