Sunday, 10 February 2013

What is SQL and its Syntax

What is SQL and its Syntax with Examples
SQL stands for Structured Query Language, is used for storing, manipulating and retrieving data stored in relational database.

SQL is the standard language for Relation Database System. All relational database management systems like MySQL, MS Access, Oracle, Sybase, Informix, postgres and SQL Server use SQL as standard database language.

SQL Syntax:
SQL is Structured Query Language, which is a computer language for storing, manipulating and retrieving data stored in relational database.
SQL is the standard language for Relation Database System. All relational database management systems like MySQL, MS Access, Oracle, Sybase, Informix, Postgres and SQL Server use SQL as standard database language.

SQL SELECT Statement:
SELECT Column1, Column2....ColumnN
FROM Table_Name;

SQL DISTINCT Clause:
SELECT DISTINCT Column1, Column2....ColumnN
FROM Table_Name;

SQL WHERE Clause:
SELECT Column1, Column2....ColumnN
FROM Table_Name
WHERE CONDITION;

SQL AND/OR Clause:
SELECT Column1, Column2....ColumnN
FROM Table_Name
WHERE CONDITION-1 {AND|OR} CONDITION-2;

SQL IN Clause:
SELECT Column1, Column2....ColumnN
FROM Table_Name
WHERE Column_name IN (Val-1, Val-2,...Val-N);

SQL BETWEEN Clause:
SELECT Column1, Column2....ColumnN
FROM Table_Name
WHERE Column_name BETWEEN val-1 AND val-2;

SQL LIKE Clause:
SELECT Column1, Column2....ColumnN
FROM Table_Name
WHERE Column_name LIKE { PATTERN };

SQL ORDER BY Clause:
SELECT Column1, Column2....ColumnN
FROM Table_Name
WHERE CONDITION
ORDER BY Column_name {ASC|DESC};

SQL GROUP BY Clause:
SELECT SUM(Column_Name)
FROM Table_Name
WHERE CONDITION
GROUP BY Column_Name;

SQL COUNT Clause:
SELECT COUNT(Column_Name)
FROM Table_Name
WHERE CONDITION;

SQL HAVING Clause:
SELECT SUM(Column_Name)
FROM Table_Name
WHERE CONDITION
GROUP BY Column_Name
HAVING (Arithematic Function Condition);

SQL CREATE TABLE Statement:
CREATE TABLE Table_Name( Excel Kingdom Easy Macros Learning

Column1 DataType,
Column2 DataType,
Column3 DataType,
.....
ColumnN DataType,
PRIMARY KEY( One or More Columns )
);

SQL DROP TABLE Statement:
DROP TABLE Table_Name;

SQL CREATE INDEX Statement:
CREATE UNIQUE INDEX Index_Name
ON Table_Name ( Column1, Column2,...ColumnN);

SQL DROP INDEX Statement:
ALTER TABLE Table_Name
DROP INDEX Index_Name;

SQL DESC Statement:
DESC Table_Name;

SQL TRUNCATE TABLE Statement:
TRUNCATE TABLE Table_Name;

SQL ALTER TABLE Statement(Add/Drop/Modify):
ALTER TABLE Table_Name {ADD|DROP|MODIFY} Column_Name {Data_Type};

SQLALTER TABLE Statement (Rename):
ALTER TABLE Table_Name RENAME TO new_Table_Name;

SQL INSERT INTO Statement:
INSERT INTO Table_Name( Column1, Column2....ColumnN)
VALUES ( Value1, Value2....ValueN);

SQL UPDATE Statement:
UPDATE Table_Name Excel Kingdom Easy Macros Learning

SET Column1 = Value1, Column2 = Value2....ColumnN=ValueN
[ WHERE CONDITION ];

SQL DELETE Statement:
DELETE FROM Table_Name
WHERE {CONDITION};

SQL CREATE DATABASE Statement:
CREATE DATABASE Database_Name;
SQL DROP DATABASE Statement:
DROP DATABASE Database_Name;

SQL USE Statement:
USE DATABASE Database_Name;

SQL COMMIT Statement:
COMMIT;

SQL ROLLBACK Statement:
ROLLBACK;

Types of SQL Commands:
The standard SQL commands to interact with relational databases are CREATE, SELECT, INSERT, UPDATE, DELETE and DROP. These commands can be classified into groups based on their nature:

DDL - Data Definition Language:

CREATE
To Create a new table, a view of a table, or other object in database.

ALTER

To Modify an existing database object, such as a table.

DROP

To Delete an entire table, a view of a table or other object in the database.

DML - Data Manipulation Language:

SELECT
Retrieves certain records from one or more tables.

INSERT INTO

To Create records.

UPDATE

To Modify records.

DELETE

To Delete records

DCL - Data Control Language:

GRANT
To Give a privilege to user.

REVOKE

To Take back privileges granted from user

No comments:

Post a Comment

Follow Me by Email

ExcelKingdom-Popular Posts

ExcelKingdom-Random Posts