In the dynamic world of databases, SQL commands serve as the guiding stars, illuminating the path to effective data management. As demand for SQL professionals escalates in the corridors of corporate giants, enticing with competitive pay packages and coveted roles, mastering these diverse command types becomes not just a skill but a gateway to unlocking boundless opportunities in the ever-expanding realm of data.
Let’s unravel the fascinating tapestry of SQL commands, each with its unique purpose and role.
What are Databases?
A database constitutes a methodically arranged assembly of data retained within a computer system, typically overseen by a database management system (DBMS). Within conventional databases, data is structured into tables, optimising the efficacy of querying and processing operations. Frequently employed for data querying and composition tasks, structured query language (SQL) plays a pivotal role in managing databases.
Databases permeate various facets of daily life, permeating activities ranging from banking transactions and railway operations to school administration and retail management. These scenarios exemplify instances wherein copious amounts of data necessitate centralised storage and effortless retrieval, underscoring the indispensability of databases in modern society.
Get curriculum highlights, career paths, industry insights and accelerate your technology journey.
Download brochure
What is SQL?
SQL is a full form of Structured Query Language that describes the foundation of data management and manipulation under relational databases. Since SQL languages are domain-specific languages, SQL helps to form seamless connections and communication within databases.
What is SQL Command?
SQL commands serve as directives utilized to interact with databases, facilitating communication and executing specific tasks and data queries. Through SQL, users can undertake a multitude of operations, such as creating tables, adding data to existing tables, dropping tables, modifying table structures, and setting permissions for user access. This language acts as the conduit through which users navigate the complexities of database management, empowering them to wield control over data structures, content, and security measures with precision and efficiency.
From the creation of tables to the insertion of data, from querying information to controlling access and security measures, basic SQL query commands encapsulate the essence of database management, acting as the guiding force behind every database operation. Categorised into distinct types, each SQL command fulfils a specific role in the intricate dance of data manipulation, ensuring that databases remain organised, efficient, and secure in the hands of proficient SQL practitioners.
Types of SQL Commands
There are five types of SQL commands. They are DDLs, DMLs, DCLs, TCLs and DQL.
1. Data Definition Language (DDL):
DDL, abbreviation for Data Definition Language, includes the actions that change the structure of tables, for example, the table’s creation, deletion, or updates. Essentially, all DDL commands are auto-committed, signifying that any alterations made are instantaneously and permanently saved within the database.
Here are some commands that come under DDL:
CREATE
ALTER
DROP
TRUNCATE
a. CREATE: It is used to create a new table in the database.
CREATE TABLE EMP
(
EMPNo VARCHAR2(20)s
EName VARCHAR2(20)s
Job VARCHAR2(20)s
DOB DATE
);
b.ALTER: This command is used to delete, modify or add constraints or columns in an existing table.
The ‘ALTER TABLE’ Statement
Users utilize this statement to add, remove, and make changes in columns in an existing table.
The ‘ALTER TABLE’ Statement with ADD/DROP COLUMN
You can use the ALTER TABLE statement with the ADD/DROP Column command according to your need. If you wish to add a column, then you will use the ADD command, and if you wish to delete a column, then you will use the DROP COLUMN command.
Syntax:
ALTER TABLE TableName ADD ColumnName Datatype;
ALTER TABLE TableName DROP COLUMN ColumnName;
Example
--ADD Column MobNo:
ALTER TABLE Emp ADD MobNo Number(10);
--DROP Column MobNo:
ALTER TABLE Emp DROP COLUMN MobNo ;
The ‘ALTER TABLE’ Statement with ALTER/MODIFY COLUMN
This statement is used to change the datatype of an existing column in a table.
Syntax
ALTER TABLE TableName ADD COLUMN ColumnName Datatype;
Example
--Add a column DOB and change the data type to Date.
ALTER TABLE Emp ADD DOB date;
c. TRUNCATE: This command is used to delete the information present in the table but does not delete the table. So, once you use this command, your information will be lost, but not the table.
Syntax:
TRUNCATE TABLE table_name;
Example:
TRUNCATE TABLE EMPLOYEE;
d.DROP : This statement is used to drop an existing database. When you use this statement, complete information present in the database will be lost. Syntax
DROP DATABASE DatabaseName;
Example
DROP DATABASE Employee;
The ‘DROP TABLE’ Statement
This statement is used to drop an existing table. When you use this statement, the complete information present in the table will be lost.
Syntax
DROP TABLE TableName;
Example
DROP Table Emp;
2. Data Control Language (DCL)
DCL commands are used to grant and test back authority from any database user.
Here are some commands that come under DCL:
Grant
Revoke
a. Grant: It is used to give user access privileges to a database.
Example
GRANT SELECT, UPDATE ON MY_TABLE TO SOME_USERs ANOTHER_USER;
b.Revoke: It is used to get permission from the user
Example
REVOKE SELECTs UPDATE ON MY_TABLE FROM USER1s USER2;
3. Data Manipulation Language (DML)
DML commands are utilised to alter the database, encompassing all types of modifications.
These commands do not automatically commit changes, implying they cannot permanently store alterations within the database. They are subject to rollbacks.
Below are several commands falling under DML:
INSERT
UPDATE
DELETE
a. INSERT: The INSERT statement is a SQL query. It is used to insert data into the row of a table.
Syntax:
INSERT INTO TABLE_NAME
(col1s col2s col3s.... col N)
VALUES (value1s value2s value3s .... valueN);
Or
INSERT INTO TABLE_NAME
VALUES (value1s value2s value3s .... valueN); For example: INSERT INTO EMP(ENamesJob) VALUES ("SCOTT"s "MANAGER");
For example: INSERT INTO EMP(ENamesJob) VALUES ("SCOTT"s "MANAGER");
b. DELETE: It is used to remove one or more rows from a table.
Syntax1:
DELETE FROM table_name;
Syntax1
DELETE FROM table_name WHERE condition;
Example1: Delete all rows from emp table
DELETE FROM Emp;
Example2: Delete all rows from emp table whose Ename is SCOTT
DELETE FROM EName WHERE EName="SCOTT";
c. UPDATE: This command is used to update or modify the value of a column in the table.
Syntax:
UPDATE table_name SET column1= values column2= values
columnN = value WHERE CONDITION;
For example:
UPDATE Emp SET Ename = 'SMITH' WHERE EmpNo = '1003';
4. Transaction Control Language (TCL)
TCL commands can only be used in conjunction with DML commands, such as INSERT, DELETE, and UPDATE.
These actions are automatically committed in the database, hence they cannot be employed during table creation or deletion.
Below are some examples of TCL commands:
COMMIT
ROLLBACK
SAVEPOINT
a. Rollback: The Rollback command is used to undo transactions that have not already been saved to the database.
Syntax:
ROLLBACK;
Example:
DELETE FROM CUSTOMERS WHERE AGE = 25;
ROLLBACK;
b. SAVEPOINT: It is used to roll the transaction back to a certain point
without rolling back the entire transaction.
Syntax:
SAVEPOINT SAVEPOINT_NAME;
c. Commit: The commit command is used to save all the transactions to the Database.
Syntax:
COMMIT;
Example:
DELETE FROM CUSTOMERS WHERE AGE = 25;
COMMIT;
5. Data Query Language (DQL)
DQL, or Data Query Language, statements are utilised to execute queries on data stored within schema objects. The primary objective of DQL commands is to fetch specific schema relations based on the provided query. DQL can be defined as a segment of SQL statements dedicated to fetching data from the database and arranging it in a specified order. This functionality is encapsulated within the SELECT statement.
SELECT allows the extraction of data from the database for subsequent operations. Upon executing a SELECT statement against one or more tables, the resulting dataset is typically compiled into a temporary table, which can then be displayed or accessed by the application, such as a front-end interface.
This was the SQL commands list. Now let us move on to learn about saving a SQL Command.
Saving a SQL Command
You have the option to store the SQL commands you input within SQL Commands.
Here’s how to save a SQL command:
Navigate to the Workspace home page and select SQL Workshop, then click on SQL Commands.
You’ll be directed to the SQL Commands page.
Input your command into the command editor.
Press the Save button to store the command.
You’ll be asked to provide a name and description for the command.
Choose to Save the command or click Cancel to go back to the command editor without saving.
The saved command will be displayed in the list area.
Long Story Short
Therefore, in today’s data-driven era, grasping SQL is essential. SQL’s seamless interaction with databases empowers both individuals and organisations to effectively handle, retrieve, and manipulate extensive datasets. Whether you’re a data analyst, software developer, or business professional, mastering SQL opens doors to diverse career paths and amplifies your capacity to draw informed conclusions from data insights. Choose Certificate Program in Application Development to gain hands-on experience, deepen your understanding of SQL principles, and sharpen your skills in handling complex queries.
FAQs
What is the SQL command?
SQL serves as a standardised language for interacting with databases. Its commands act as directives, facilitating various tasks, functions, and data queries within the database. These commands encompass searching the database and executing functions such as table creation, data insertion, modification, and table deletion.
Why is SQL used?
SQL helps as the medium for communication with databases, established as the standard language for relational database management systems by the American National Standards Institute (ANSI). SQL statements facilitate various tasks including updating data within a database or retrieving data from it.
What is DBMS in SQL?
Database Management Systems (DBMS) are software systems employed for the storage, retrieval, and execution of queries on data.
Is SQL a code?
Considering the criteria of a programming language, which involves possessing a defined vocabulary and syntax, SQL undeniably meets these qualifications. However, it falls short of being categorised as a General Purpose Language (GPL) and is instead recognised as a Domain-Specific Language (DSL).
Hero Vired is a leading LearnTech company dedicated to offering cutting-edge programs in collaboration with top-tier global institutions. As part of the esteemed Hero Group, we are committed to revolutionizing the skill development landscape in India. Our programs, delivered by industry experts, are designed to empower professionals and students with the skills they need to thrive in today’s competitive job market.