Tuesday, 8 April 2014

SQL Server 2005

 SQL stands for Structured Query Language. This language is used to retrieve,update,insert and delete data from an database object called Table.A table consists of rows and columns.

In fact whole SQL is based on RDBMS(Relational Database Management System).

At this point of time I am going to show some basic queries used in SQL.Although these are very basic but very much crucial in day to day job.

Suppose there is a table "Customer" which is used o store the Name of customer,Phone No.,Address, State,Country and Product.The table will look like,


 CustomerID
 CustomerName
 PhoneNO
 Address
 State
Country
Product
 1
 John
 10000
 Luciana
 Alabama
 USA
Watch
 2
 Mr. Naidu
 20000
 Lucknow
 U.P
 India
TV
 3
 Miss. Filomena
 30000
 Chennai
 Kerela
 India
Book
 4
 Mr. Meverick
 50000
 Singapore
 Singapore
 Singapore
Computer
 5
 Mr. Gaurav
 60000
 Gorakhpur
 U.P
 India
Cloth


Suppose  a client needs to get a report of the his/her customer and you are a SQL expert. So you will write a query like

SELECT * FROM  Customer

This query will fetch you all the data of the  table.But most of the time we need some specific data which may come from a single table or from a combination of one or more table.For the time being I am going to explain how to fetch data from a single table with some given constraints.


 CustomerID
 CustomerName
 PhoneNO
 Address
 State
Country
Product
 1
 John
 10000
 Luciana
 Alabama
 USA
Watch
 2
 Mr. Naidu
 20000
 Lucknow
 U.P
 India
TV
 3
 Miss. Filomena
 30000
 Chennai
 Kerela
 India
Book
 4
 Mr. Meverick
 50000
 Singapore
 Singapore
 Singapore
Watch
 5
 Mr. Gaurav
 60000
 Gorakhpur
 U.P
 India
Watch

If you want to get the info about the customers buying Watch then you should write like

SELECT * FROM Customer WHERE Product= 'Watch'

This will fetch you
 CustomerID
 CustomerName
 PhoneNO
 Address
 State
Country
Product
 1
 John
 10000
 Luciana
 Alabama
 USA
Watch
 4
 Mr. Meverick
 50000
 Singapore
 Singapore
 Singapore
Watch
 5
 Mr. Gaurav
 60000
 Gorakhpur
 U.P
 India
Watch