SQL Commands

 

SQL Commands

  • SQL commands are instruction. It is used to communicate with the database. It also used to perform Specific tasks, function and queries of data.
  • SQL can performs various tasks like create a table. add data to tables. drop the table, modify the table set permission for users
Types of SQL Commands

There are five types of SQL commands:-
  • DDL (Create Drop Alter Truncate)
  • DML (Insert Update Delete)
  • DCL (Grant revoke)
  • TCL (Commit Roll back Save point)
  • DQL (Select)

Data Definition Language (DDL) :- 

  • DDL changes the Structure of the table like creating a table. Deleting a table , altering a table etc
  • All the commands of DDL are auto committed that means it permanently save all the changes in the database
Here are some commands that come under DDL:
  • CREATE
  • ALTER
  • DROP
  • TRUNCATE

Create :- It is used a new table in the database

Syntax :- CREATE TABLE_NAME(COLOUMN_NAME DATATYPE)
Example :- CREATE TABLE EMPLOYEE (Name VARCHAR2(20),Email

Drop:- It is used to delete both the structure and record stored in the table

Syntax:- DROP TABLE table.name
Example:- DROP TABLE EMPLOYEE

Alter:- It is used to alter the structure of the database. This could be either the modify the characteristics of an existing attribute or probably to add a new attribute.

Example:- ALTER TABLE STU.DETAILS ADD(ADDRESS VARCHAR 2(20)
                  ALTER TABLE STU.DETAILS MODIFY(NAME VARCHAR 2 (20)

Truncate:- It is used to delete all the rows from the table and free the space containing the table

  Syntax:-
             TRUNCATE TABLE table.name
Example :- TRUNCATE TABLE EMPLOYEE;

Data Manipulation Language (DML)

DML commands are used to modify the database .It is responsible for all from of changes in the database. The command of DML is not auto-committed 
  • INSERT
  • UPDATE
  • DELETE

Insert:- The insert statement is SQL Query. It is used to insert data into the row of a table

Syntax:-
           INSERT INTO TABLE.NAME
           VALUE (Value1, Value2, Value3, ..........Value N):

Update:- This command is used to update or modify the value of column in the table.

Syntax:-
            UPDATE table.name SET [column-name1:value1....column]

Delete:- It is used to remove one or more row from table.

Example:-
DELETE FROM javalpoint
WHERE Author:"sunno"

Data Control Language:-

DCL commands are used to grant and revoke authority from any database user.
  • Grant :- It is used to give user access privileges to database ex:- Grant, SELECT, UPDATE, ON MY.TABLE TO SOME_USER,
  • Revoke:- It is used to take back permissions from the user.

Transaction Control language:-

TCL commands  can only use with DML commands like INSERT , DELETE and UPDATE only.
  • Commit :- Commit commands is used to save all transaction to the database. ex:-DELETE From CUSTOMERS WHERE AGE = 25; Commit
  • Rollback:- Rollback commands is used to undo transaction that have not already been saved to the database
Syntax:- 
             SAVEPOINT SAVEPOINT_NAME

Data Query Language:-

DQL is used to fetch the data from the database
     SELECT :- This is same as the projection operations on of relational algebra. It is used to select the attribute based on the condition
Syntax:-         SELECT expression
                       FROM  TABLES
                       WHERE conditions:




Comments

Popular Posts