Practical SQL Guide : 4D1T

What is 4D1T?

Do you think that this some kind of new way of writing EDIT? Well it could be, but here we are talking about SQL. This is my way of remembering different kinds/types of statements or commands used in SQL. You might be anticipating that we need to do hands-on, and that's true 99% but that 1% says that lets have some theory first :) Don't worry much, this theory won't be long. As I promised myself that I will keep the theories to bare minimum and hands-on to maximum, I will finish this theory blog as quickly as I can. Let's begin, shall we?

1st D for DQL 

The word 4D1T contains of D D D D T, and here we will focus on the first D. 

That stands for DQL. What the HECK is DQL now? you may ask. Data Query Language. In simple words DQL is used for querying for data from the database. These are very simple types of commands and statements. Remember SELECT from my previous blog? It belongs to this category of statement. Plus point : SELECT is the core DQL statement. Anything else is based upon SELECT only. There are statements like FROM, WHERE, GROUP BY, ORDER BY that are used in conjunction with SELECT to fetch the data. Don't worry much about the other statements, I will tell about them later in this Guide. Have Faith. Have Patience :)

2nd D for DML

DML stands for  Data Manipulation Language. As the name suggests, it is used for manipulating the data. Not only the data, but also the table structure. You want to Alter a value in a row of a table, you will use DML. You want to insert values into a table, you will use DML. You want to change the remove few data from the data table, guess what, you will use DML. This is the second most used type of commands to be used in SQL. The most famous ones are UPDATE, INSERT, and DELETE. They do the work as their name suggests. DML commands are to be used wisely as they manipulate the data itself. So use them only if you are confident in yourself about what you are doing.

3rd D for DDL

DDL stands Data Definition Language. It is used primarily used to alter the structure of the tables or in bigger picture, the database itself. This is a riskier "language" compared to other two. As altering the structure of tables or the database will heavily effect the operations. In the process you may loose data. So it has to be used with expertise and knowledge of what you are doing. By saying these things I don't want to scare you about DDL. Its just that you should be aware of the risk level associated with a particular task before doing it. So what you can do in DDL? You can CREATE table, ALTER them, remove or DROP them. Just have some precautions before using them.

4th D for DCL

DCL refers to Data Control Language. This is the least used queries in any practical scenario. This is used for granting access of the database to the users. This is only used by higher professionals and usually there's GUI for doing the same. Don't worry so much, we won't dealing with it anyway. The famous commands are GRANT & REVOKE.

Finally the T...

T stands for TCL. Transaction Control Language. You don't need understand about transactions and their related theory right now. Just have a knowledge that transaction are very helpful and integral tool in some database operations (esp. we use them in DML). Let's not hassle much about TCL right now. When the right time comes, I will share everything there is to know about TCL from a practical perspective.

Summary

So to summarize the whole blog, we have 4 D's as DQL, DML, DDL, DCL and 1 T as TCL. They have been presented in the order of their usage and risk associated to them(except TCL). I will share about each of them one by one from now on. Thank you!

SEE YA!!!


Comments

Popular Posts