Sunday, April 20, 2014

SQL - Structured Query Language


 
SQL


Structured Query Language and it also spell as Structured English Query Language (SEQUEL). The Main features of SQL are
  •  SQL stands for structured Query language
  •   SQL lets you access and manipulate databases
  •   SQL is an ANSI (American National Standards Institute) Standard
  •   SQL is a standard interactive and programming language for querying and modifying data and managing databases
  •   SQL can execute queries against the database 
  •   SQL ca set permissions on tables, procedures and views
  •   SQL can create stored procedures in a database
  •   The basis of SQL is RDBMS, it stands for Relational Database Management System
  •  The data in RDBMS is stored in database objects called tables and tables is nothing a collection of related data entries which is present in columns and rows





The following SQL statement will select all the records in the Customers Table

SELECT * FROM CUSTOMERS

(SQL is not case sensitive)

SQL is divided into two parts:

(1) The Data Manipulation Language (DML)
(2) The Data Definition Language (DDL)



The Main DML statements are given below
(1) SELECT
(2) UPDATE
(3) DELETE
(4) INSERT INTO
(5) SELECT INTO
The DDL part of SQL permits database tables to be created or deleted. It also defines indexes (keys), specified links between tables, and imposes constraints between tables. 

The most important DDL statements are given below
(1) Create Database
(2) Alter Database
(3) Create Table
(4) Alter Table
(5) Create INDEX
(6) Drop Index
(7) Drop table
(8) Drop Database


-----------------------------------------------------------------------------------------------------

SQL Select Statement

SELECT statement is used to select data from a database
The result is stored in a result table, called result-set
Syntax of the SQL Select Statement is

SELECT COLUMN_NAME FROM TABLE_NAME

for example.,

(1) SELECT * FROM CUSTOMERS: Selecting complete list of records and columns



CUST_ID CUST_NAME
CUST001 ASHWIN


(2) SELECT CUST_ID FROM CUSTOMERS: Selecting complete list of records with only cust_id column

CUST_ID
CUST001

 (3) SELECT DISTINCT PERSON_NAME FROM PERSONS

Persons Table is as follows


ID
PERSON_NAME
Address
City
Mobile
1
Sachin
10th Main Road
Mumbai
9845012345
2
Henry
11th Main Road
Bengaluru
9945012345
3
Sachin
8th Main Road
Mumbai
9845012345

Now ABOVE query will get you

PERSON_NAME
SACHIN
HENRY
  
In above table one of records is having duplicate values. If we need to display or extract only different values or the records, we can use "Select Distinct statement"

 

-----------------------------------------------------------------------------

 Creating Database

CREATE DATABASE <<DATABASE_NAME>>

If we want to create the database  of customers

CREATE DATABASE CUSTOMERS
 Now the DATABASE OF CUSTOMERS will be created....