Wednesday, May 14, 2008

Intro to SQL

SQL is short for Structured Query Language and is a widely used database language, providing means of data manipulation (store, retrieve, update, delete) and database creation.

The SQL SELECT clause selects data from one or more database tables and/or views. In its basic form the SQL SELECT syntax looks like this:
SELECT ColumnName1, ColumnName2, …FROM Table1
Ex:
"SELECT fname from Employee"
If we want to select all the data (all columns) from the Employee
"SELECT *FROM Employee"

The SQL INSERT INTO clause facilitates the process of inserting data into a SQL table.
Ex: "INSERT INTO Weather (City, Date)VALUES (Delhi '05/10/2005') "

SQL WHERE clause works in conjunction with other SQL clauses like SELECT, INSERT and UPDATE to specify a search condition for these statements.
Ex: "SELECT * FROM Employee Where City = 'New Delhi' "

SQL DISTINCT command used along with the SELECT keyword retrieves only unique data entries depending on the column list you have specified after it.
Ex: "SELECT DISTINCT CityFROM Users "

SQL UPDATE clause serves to update data in database table. The Syntax is
"UPDATE Table1SET Column1 = Value1, Column2 = Value2, … "

SQL DELETE clause is used to delete data from a database table. The basic Syntax is
"DELETE FROM Table1"

SQL TRUNCATE TABLE clause deletes all rows from a database table. Syntax is
"TRUNCATE TABLE tablename"

SQL ORDER BY clause defines in what order to return a data set retrieved with a SQL SELECT statement.
"SELECT * FROM employee ORDER BY City "

The SQL GROUP BY clause is used along with the SQL aggregate functions and specifies the groups where selected rows are placed. WHEN one or more aggregate functions are presented in the SQL SELECT column list, the SQL GROUP BY clause calculates a summary value for each group.