Introduction To SQL And SQL Commands
Introduction
In this chapter, we will learn about SQL and SQL Commands.
SQL
SQL stands for Structured Query Language. SQL is used to create, remove, alter the database and database objects in a database management system and to store, retrieve, update the data in a database. SQL is a standard language for creating, accessing, manipulating database management system. SQL works for all modern relational database management systems, like SQL Server, Oracle, MySQL, etc.
Different types of SQL commands
SQL commands can be categorized into five categories based on their functionality.
DDL
DDL stands for data definition language. DDL commands are used for creating and altering the database and database object in the relational database management system, like CREATE DATABASE, CREATE TABLE, ALTER TABLE, etc. The most used DDL commands are CREATE, DROP, ALTER, and TRUNCATE.
- CREATE
CREATE command is used to create a database and database object like a table, index, view, trigger, stored procedure, etc.SyntaxCREATE TABLE Employee (Id INT, Name VARHCAR(50), Address VARCHAR (100));
- ALTER
ALTER TABLE Employee ADD Salary INT;
- TRUNCATE
The TRUNCATE command is used to remove all the data from the table. TRUNCATE command empties a table.TRUNCATE TABLE Employee;
- DROP
DROP TABLE Employee;
DML
DML stands for Data Manipulation Language. DML commands are used for manipulating data in a relational database management system. DML commands are used for adding, removing, updating data in the database system, like INSERT INTO TableName, DELETE FROM TableName, UPDATE tableName set data, etc. The most used DML commands are INSERT INTO, DELETE FROM, UPDATE.
- INSERT INTO
INSERT INTO command is used to add data to the database table.INSERT INTO Employee (Id, Name, Address, Salary) VALUES (1, ‘Arvind Singh’, ‘Pune’, 1000);
- UPDATE
UPDATE Employee SET Address = ‘Pune India’, Salary = 100 WHERE Id =1;
- DELETE
DELETE command is used to remove data from the database table. A condition can be added using the WHERE clause to remove a specific row that meets the condition.DELETE FROM Employee WHERE Id =1;
DQL
DQL stands for the Data Query Language. DQL command is used for fetching the data. DQL command is used for selecting data from the table, view, temp table, table variable, etc. There is only one command under DQL which is the SELECT command.
SELECT * FROM Employee;
DCL
DCL stands for Data Control Language. DCL commands are used for providing and taking back the access rights on the database and database objects. DCL command used for controlling user’s access to the data. Most used DCL commands are GRANT and REVOKE.
-
GRANT
GRANT INSERT, DELETE ON Employee TO user;
- REVOKE
REVOKE ALL ON Employee FROM user;
TCL
TCL stands for transaction control language. TCL commands are used for handling transactions in the database. Transactions ensure data integrity in the multi-user environment. TCL commands can rollback and commit data modification in the database. The most used TCL commands are COMMIT, ROLLBACK, SAVEPOINT, and SET TRANSACTION.
- COMMIT
- ROLLBACK
- SAVEPOINT
Syntax
Just write COMMIT or ROLLBACK or SAVEPOINT;
Summary
In this chapter, we discussed SQL commands and their fundamentals.
Author
Arvind Singh
321
5.7k
781.6k