SQL for Beginners Part-3: Intro to SQL

  I hope you have gone through my previous Lessons on SQL - Part 1 and Part 2. This part would be a continuation of these parts. If you are a Non-Computer Science student, I strongly recommend you to go through Part 2 and do the steps shown in that. It is an essential basic knowledge you should know, and Ive put it in the simplest words I possibly could.
 So coming on to this Part, I will finally getting on to SQL, which you will realize is a pretty easy language to learn. As Ive said before, SQL - Structured Query Language is a Query Language, used for accessing and manipulation of Databases. So let's manipulate the Database - Student_details that we had made in Part 2. To start working with SQL, here is what you have to do -

Select New Query by Right Clicking on the Table you had created earlier(From Server Explorer). You will get the following popup to select the Table you want to Manipulate. Select the Table required by clicking on Add.

 Close the popup, and you will get the following Window. Its divided into 3 sections where you can see Selected Tables, Selected Columns(After executing Query), Result of Queries and the Query you give.

Now you have a place to enter your SQL Queries! So lets begin!
Getting onto the theoretical part and SQL Commands now. SQL Commands are mainly of two types.
  • Data Definition Language(DDL) : as the name suggests, it defines a table. 
  • Data Manipulation Language(DML): again as the name suggests, it is used to manipulate a table.
Confused? No worries! You will get the idea clear once you work with Examples. I know we get to manipulate a table only after defining it, but explaining the other way around would be easier to grasp. So I'l be handling a few basic DML Commands here.
These commands pretty much make the whole of SQL, easy isn't it? Lets begin with the easiest of the Commands - SELECT, as it denotes SELECT is used to select certain information from the database. But inorder to execute the command, we need information in the Table, right? So lets begin filling up the table(lets do it directly first , without using the Command - Insert Into). Take Server Explorer and Right Click on the Table, to select Show Table Data.
You will get the following window, where you can directly type down the values required.

Now get back to the previous window where you give the Query(Right Click on the Table and New Query). This is the general syntax of SELECT command.
SELECT column_name FROM table_name
Lets experiment our First Query, let it be to select all the details(all Columns) from the table. The SQL Query will be like this.
SELECT FROM student_details
* is a wildcard which selects all Columns. Now to execute it, press ALT+R. Tada! There you get the results in the Window!
That would be enough for this Part!
You learned in this Part
  • How to add data into the Table manually
  • Two types of SQL Commands - DDL and DML
  • SELECT command
  • Executing your First SQL Query!
Stay tuned for the next part!

SQL Tutorials

No comments:

Post a Comment