SQL Commands are categorized into 5 categories as below
- DDL - Data Definition Language
- DML - Data Manipulation Language
- DQL - Data Query Language
- DCL - Data Control Language
- TCL - Transaction Control Language
Within these SQL commands there are many sub-commands as below.
- CREATE
- DROP
- ALTER
- TRUNCATE
- COMMENT
- RENAME
CREATE - this command is used to create database, table or stored procedure
Example:
CREATE DATABASE Test-RPA;
Example:
ID INT PRIMARY KEY AUTO_INCREMENT, EmpId INT,
F_Name VARCHAR(255) NOT NULL, L_Name VARCHAR(255), Dept VARCHAR(255)
);
DROP - This command used to remove the database, table and stored procedure
Example:
DROP DATABASE Test-RPA;
Example:
DROP TABLE EMP;
ALTER - This command is used to modify the structure of the database or its objects.
Add new column to the table
Example:
ALTER TABLE EMP ADD EMAIL_ID VARCHAR(250);
Modify the datatype of existing column
Example:
ALTER TABLE EMP ALTER L_Name VARCHAR(512);
Remove the existing column from the table
Example:
ALTER TABLE EMP DROP COLUMN EMAIL_ID;
TRUNCATE - This command is used to remove all the records from a table
Example:
TRUNCATE TABLE EMP;
COMMENT - This command is used to add comments to the data table
"--"
Example:
SELECT * FROM EMP;
RENAME - This command is used to Rename an existing object in the database.
Example:
ALTER DATABASE "Test-RPA" RENAME TO "TestNew-RPA"
- INSERT
- UPDATE
- DELETE
- LOCK
- CALL
- EXPLAIN PLAN
- SELECT
Fetch Selected Column from a Table
Select F_Name, L_Name where EmpId >1223 AND Age < 27;
Fetch Maximum of 10 row from a table
Select * From EMP where EmpId = 1234 AND Age < 30 LIMIT 10;
Fetch Count of record from a table
Select Count(*) from EMP;
Fetch Maximum Salary from a table
Select Max(Salary) from EMP;
Fetch Minimum Salary from a table
Select Min(Salary) from EMP;
Fetch Sum of Salary from a table
Select Sum(Salary) from EMP;
Fetch Average of Salary from a table
- GRANT
- REVOKE
- COMMIT
- ROLLBACK
- SAVEPOINT
- SET TRANSACTION
0 Comments