Avoid Making These 5 Mistakes to Score Better in SQL Assignments

in #sql5 years ago

SQL Assignment Mistakes.png

SQL assignments are tough. Not because they have complicated queries but because you need to be extra conscious while preparing them because you stand at major chances of making minor mistakes. The program that you prepare for your assignment might not run in real if you miss placing a semi-colon at the end or misspell a command. Hence, every student should check their work meticulously before making the final submission. To aid you in this process, we have compiled a list of mistakes that you are most likely to make in your SQL assignment. Avoid making these or rectify these, you will surely score brilliantly.

1. Forgetting to place semi-colon at the end: Starting with the most basic and the most common mistake that people make. We have already talked about this in the introduction. It happens when people forget to put a semi-colon at the end of their command. No command will function accurately if you miss placing this semi-colon mark “;”. This is like the key of all SQL commands.

2. Writing codes as a translation of the requests given: While it comes as a first action to write the commands as they happen to appear in your mind in first thought, you might be wrong sometimes.
For instance, to fetch details of all employees whose name starts with “H” from left, the command:
Select employee_name
From Employee
Where left (employee_name, 1) = ‘H’;
might seem intuitive. But the correct command is,
Select employee_name
From Employee
Where employee_name like ‘H%’;

3. Getting confused in the order of predicates in the command: In case you have several predicates to mention in one command, you need to follow a certain order. Most of the students get confused with this order and make mistakes. The correct order is:
FROM
WHERE
GROUP BY
HAVING
SELECT

4. Incorrect use of SELECT *: This is the easiest yet the most misunderstood command of SQL. The function of SELECT * is to select and retrieve the list of all columns present in a table. But what do most students do? They use it to bring in front all the columns of the table, which is totally not the function of SELECT *. In short, never use the SELECT * syntax while you perform the production code.

5. Forgetting Primary key: This is an in-built function of SQL that it will not work until and unless you start with defining the primary key. No matter how good syntaxes you write, if you miss the primary key syntax, none of them will work. Almost all beginners make this mistake. If you are working on an SQL assignment for the first time, make sure that you do not give this command. Also, only the unique columns in your table can be used as a primary key. This function of Primary key is to speed up SQL’s response to your queries. For example: In a table containing the data about students studying in class 7, the column depicting their Roll No. can be used as the primary key because no two students can ever have the same roll number.

Make sure that you cross-check your assignment before submitting it to your professor using the above list. All the best!

Summary: People with in-depth knowledge of SQL are high in demand these days and recognizing this, many universities have included it in their courses. It is essential for students to not make any mistakes in their SQL assignments to score well. This article has all the errors that students generally make. A thorough revision of this will help them in avoiding these in their further assignments.

Sort:  

I think one key mistake I've seen a lot of people make in the industry is when creating complex queries with joins.
Also, one other thing to note is if you are creating the database schema, a badly defined schema can lead to very inefficient and deformed queries that will cause more harm than good.

Great article btw :)