Practical SQL Guide : The Beginning

 Just to know it....

SQL or Structured Query Language as the name suggests is a Query Language which is structured language(meaning everything that you write has a proper logical order to it) and it is used for writing queries for fetching data from DBMS. That's a very lame introduction or definition. But that's all you need to understand to start with. That's how I started. Though some theory is important before hands-on and I will be providing theory and examples, but always remember not to get swayed away with only theory. Learning throughs hands-on is very important and "efficient" way of learn, because theory will only stick with you as long as you remember it. Too much blah-blah, now let's get onto the stuffs.

A Spoonful of DBMS

In the above paragraph I spoke of DBMS, so what it is? DBMS stands for Database Management System.
Vaguely speaking, Database or DB is just collection of data. Lots of lots of data. Nothing much. And its Management System is a specific piece of software that handles or manages these data, how they are stored and how they are fetched. Now, how data is stored in the DBMS makes it more specific type of DBMS. The famous two are R-DBMS & DO-DBMS.

R-DBMS

R-DBMS is Relational Database Management System. It stores data in tables. We will understand tables later on in detail but for now it looks like this 
Pretty and neat and looks like an excel sheet right? Easy.

DO-DBMS (NoSQL)

DO-DBMS (Document-oriented DBMS) it stores data as documents and have a different formats like JSON or XML(don't worry about these two).

 Heavy stuff, but just understand the basic difference between the two is that first stores data in tables(also called relations) and later one stores data in files. Since, DO-DBMS doesn't uses SQL for fetching its data, so its popularly called as a NoSQL DBMS.

Now which one is better depends on the use. Honestly speaking the popular ones are RDBMS :) They give a very "structured" way of storing and retrieving data. Nonetheless, NoSQL are also popular among the web development community, because of the ease of transferring data. We will stick to RDBMS here :)

Put it on the Table

Any work that you will do in SQL will be on tables, with table or through tables. So a basic understanding of tables is essential for working in SQL. We will dive deep into tables, how to create them, delete them, alter them etc., later, but to start right away I will just share a very basic intro to tables. Take it as just a starter, so that we can start coding in SQL.

Let me use the table in above image. A table in RDBMS is called entity. Why entity? you may ask. That is because it defines a real world object. It represents a collection of related information about a particular real-world object or concept. Now each table is made up of rows and columns. A column represents a specific part of the entity. A table will have multiple columns referring to multiple properties of entities that helps in describing the idea of that real-world idea or concept. For example, a table of "animals" will have columns like 'Name', 'BiologicalName',  'IsMammal', etc. These are some of the characteristics that defines an animal(to some extent). Now that's about columns of a table. Simply enough, a row is basically a record of the entity(table). For example a row in table "animals" will be a record for an animal, like a cat or dog, based on the characteristics(columns or properties) available in the table.
To summarize the idea of table, it is just a collection of rows and columns that defines the real-life entity or concept where each column define a specific property of that real-world entity / concept. And a row is just a instance or record of that entity.

Creating tables and handling them are a very essential and important task. Because in complex ideas, multiple tables can refer to different tables altogether to define a complete idea. In a job most of the time you will be working on a pre-built table. We will do the same here to begin with and then will move to creating tables and altering them or may be even deleting them!

This is the online SQL compiler that I am using and specifically I will be using MS-SQL for writing SQL. Don't worry all SQL are similar, they just vary minutely. So if you are proficient in one SQL you can write in another SQL

SQL Starters : Hello World

When you open the link I have given you will be seeing tables' definition in the left and tables with their data in the right. And the middle is your "playground". This is where you will write queries. 

Without going much into the tables and their architecture, lets just start with coding some SQL. This will end this blog too as I don't want to stretch this blog much. For our coding tradition, we write a specific program called "Hello World" program when we first write a program in a language. To write the same in SQL we need to write :

    SELECT 'Hello World'

 In the playground and run it and in the bottom you will see the result. The result is bit different to look but that's how it is in SQL. Now there are different of writing SELECT. Since I haven't told you about the terminologies related to it, I won't be going into much detail. We will cover more in the next blog. 

See ya!!!

    




Comments

Popular Posts