Introduction to SQL

July 27, 2016 by Arti Khedkar

Filed under Database, SQL

Last modified July 27, 2016

 

Introduction to SQL

Sql is database language which is used by most of the companies for storing the data in it. SQL stands for Structured Query Language.

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.

The first incarnation of SQL appeared in 1974, when a group in IBM developed the first prototype of a relational database. The first commercial relational database was released by Relational Software (later becoming Oracle).

When constructing SQL Queries (with the SELECT statement), it is very useful to know all of the possible options and the best or more efficient way to do things. This Tutorial will help provide you with those skills.

SQL commands:-

Sql work with their commands like create, Insert, select, drop, delete, alter, truncate ,rename, update, merge, commit, rollback, save point, grant, revoke etc.

SQL defines following data languages to manipulate data of RDBMS.

 

  1. Data Definition Language (DDL):
Command Description

Syntax

1 CREATE -.

 

Used to create a new table, a view of a table, or other object in database

create database database-name

 create table table-name{column-name1   datatype1,        column-name2 datatype2,               column-name3 datatype3,   column-name4 datatype4};

2 ALTER –

 

Used to modify an existing database object, such as a table. alter table table-name add(column-name datatype);
3 DROP –

 

Used to delete an entire table, a view of a table or other object in the database. It is used for drop the Database :
DROP DATABASE database_name;
It is used for drop the table:
DROP TABLE table_name;
TRUNCATE
Delete data from table

 

TRUNCATE TABLE table_name
5
RENAME
To rename a table      RENAME table old-table-name to new-table-nameRENAME table old-table-name to new-table-name

 

  1. Data Manipulation Language(DML):

DML commands are not auto-committed. It means changes are not permanent to database, they can be rolled back.

 

 

  Command Description Syntax
1 INSERT – To insert a new row INSERT into table-name values(data1,data2,..)
2 UPDATE- To update the existing  row UPDATE table_name
SET column1=value1,column2=value2,…
WHERE some_column=some_value;
3 DELETE- To delete a row  DELETE from table-name;
4 MERGE To merging two rows or two tables.
MERGE [INTO]
 (target table)
USING 
(source table or table expression|)
ON (join/merge predicate)
(semantics similar to outer join)
WHEN MATCHED
 (statement to run when
 match found in target)
WHEN [TARGET] NOT MATCHED
 (statement to run when no
 match found in target)
  1. Data Query Language(DQL):

 

 

Command
Description

Syntax

 

 

1

 

SELECT

 

retrieve records from one or more table

  SELECT column-name1, column-name2, column-name3, column-nameN from table-name;

 

4.      Transaction Control Language(TCL):

Command

Description

Syntax

1

COMMIT
to permanently save  commit;

2

ROLLBACK to undo change rollback to savepoint-name;

3

SAVEPOINT
to save temporarily  savepoint savepoint-name;

 

5.     Data Control Language(DCL):

Command

Description

Syntax

1

GRANT

grant permission of right grant create table to username;

2

REVOKE

take back permission. revoke create table from username

Leave a Comment