SQL Commands | DDL, DQL, DML, DCL and TCL Commands

Share IT

SQL,or standard query language is a standardized programming language used to manage and manipulate relational databases
It is. SQL is used to perform tasks like querying data, updating records, inserting new data and deleting existing data within a database. To initiate different operations the commands are classified in different types which are as follows:-

  • DDL
  • DML
  • DQL
  • DCL
  • TCL

DDL(Data definition language)

DDL commands or Data definition language are a set of commands in SQL which are used to tables and structures in a database. Primary commands within DDL commands are CREATE, ALTER, DROP, TRUNCATE, COMMENT, RENAME. Each of these commands serve a specific purpose.

CREATE

Purpose of create commands is to create new databases objects such as tables, indexes, views and schema. Create is the fundamental to creating a structure of a database. Following is an example.

CREATE TABLE employees (
    id INT PRIMARY KEY,
    name VARCHAR(50),
    position VARCHAR(50),
    salary DECIMAL(10, 2)
);

ALTER

The ALTER command is used to edit the structure of an existing database object. It allows you to add delete or modify columns, change datatype, RENAME object and perform other schema altering operations. Alter command is necessary for adopting the database schema to evolving requirements. Following is an example.

ALTER TABLE employees
ADD COLUMN email VARCHAR(100);

DROP

Drop command in sql is used to delete existing database objects such as tables, views, indexes, schemas and databases. When an object is dropped it Is completely removed from the database including all the data. Following is an example.

DROP TABLE employees;

TRUNCATE

The TRUNCATE command in SQL is used to quickly remove all rows from a table, effectively resetting the table to its initial state. It is different from delete command as it deletes one row at a time. Following is an example.

TRUNCATE TABLE employees;

COMMENT

Comment command is used to add descriptive text to database objects such as tables, columns, views, indexes and constraints. This helps to document the schema, making g it more understandable to the developer. Following is an example.

COMMENT ON TABLE employees IS 'Table to store employee details including personal and job-related information';

RENAME

The RENAME command in SQL is used to change the name of existing database objects such as tables, columns, indexes, views, and schemas. Renaming improves the clarity of object, making it easier to understand and maintain. Following is an example.

ALTER TABLE employees RENAME TO staff;

DML(DATA MANIPULATION LANGUAGE)

DML commands are fundamental for interacting with the data in a relational database. They are used to manipulate or manage data within database objects like tables. These commands work on existing records of a table. Following are some basic DML commands.

INSERT

Insert command in sql is used to add new rows to a table. It can handle singular or multiple rows and can draw data from another table. Following is the syntax.

INSERT INTO table_name (column1, column2, column3, ...)
VALUES (value1, value2, value3, ...);

UPDATE

Update command in sql is used to modify existing records in a table. It allows you to change the values of one or more columns for all rows that meet certain conditions.

UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;

DELETE

Delete command is used to remove rows from table.it is a crucial command for data manipulation ,allowing you to manage and clean up your database by removing incorrect data.

DELETE FROM table_name
WHERE condition;

SELECT

the select command is used to fetch data from one or more tables in a database. It is the most commonly used SQL command and allows you to query and display data according to specific criteria.

SELECT column1, column2, ...
FROM table_name
WHERE condition;

DQL(DATA QUERY LANGUAGE)

DQL commands are those which help to fetch data data from a database. In SQL DQL commands primarily encompass the SELECT statement, which is used extensively to query and retrieve data based on specific criteria.

SELECT

The select statement in SQL is the core DQL command used to retrieve data from one or more tables. By mastering these commands and understanding their various clauses and functions, you can efficiently query and analyze data to meet specific business requirement. following is the basic syntax.

SELECT column1, column2, ...
FROM table_name;

DCL(DATA CONTROL LANGUAGE)

DCL commands in SQL are used to grant or revoke permissions to users to perform certain action in the database. The two main DCL commands are GRANT and REVOKE. These commands are used to maintain data integrity and security within the database environment.

GRANT

Grant command is used to give certain privileges or permissions to the user. These privileges allow users to perform certain actions on the database objects like tables, views, procedures etc.

GRANT privileges
ON object
TO {user | role | PUBLIC}
[WITH GRANT OPTION];

REVOKE

Revoke command is used to revoke the granted privileges from a user. It removes the permissions restricting users from performing those actions on a database object. Following is the syntax.

REVOKE privileges
ON object
FROM {user | role | PUBLIC};

TCL(TRANSACTION CONTROL LANGUAGE)

TCL commands are used to manage transactions within a database.these commands play crucial role in ensuring the ACID( ATOMICITY, CONSISTENCY, ISOLATION, DURABILITY) properties of transactions in a database.

COMMIT

Commit is used to save all the changes made during the current transaction permanently. If one operation fails, none of the operations are committed to the database and if transaction is committed, the changes are permanent even if the system crashes.

COMMIT;

ROLLBACK

Rollback command is used to undo the changes made during the current transaction.it reverts the database to its state before the transaction. It is ensured that the data remain in a constant state if a transaction fails for any reason. By rolling back a transaction the changes made are not visible to other transactions ensuring isolation.

ROLLBACK ;

SAVEPOINT

Savepoint command sets a point within a transaction to which you can later roll back to, allowing partial rollback of the transaction. Multiple savepoints can be set and the transaction can be rolled back to any savepoint. it is usefull for complex transactions where partial rollback is needed.

SAVEPOINT savepoint_name;

RELEASE SAVEPOINT

Release savepoint command deletes a savepoint, invalidating the ability to rollback a transaction. It frees up resources associated with the savepoint, as maintaining multiple savepoints can consume system resources.

RELEASE SAVEPOINT savepoint_name;

SET TRANSACTION

Set transaction command sets the characteristics of the current transaction such as its isolation level. Different isolation levels control the visibility of changes made by one transaction to other concurrent transactions. Common isolation levels include:

  • READ UNCOMMITTED: Allows dirty reads; changes made by one transaction can be seen by others before the transaction is committed
  • READ COMMITTED: Prevents dirty reads; a transaction sees only committed changes.
  • REPEATABLE READ: Ensures that if a transaction reads a row, no other transaction can modify that row until the first transaction is complete.\
  • SERIALIZABLE: The highest isolation level; transactions are completely isolated from each other.
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;
Layer 1 And Layer 2 Tokens

What are Layer 1 and Layer 2 Tokens on Binance?

June 18, 2024

Binance is one of the leading cryptocurrency exchanges in the world, offering a wide range of trading options and services for its users. One feature that makes Binance stand out is its support for layer 1 and layer 2 tokens.…

Tealstreet.io

Tealstreet.io Review-Best Trading Terminal?

June 15, 2024

If you are looking for a new and exciting way to trade crypto derivatives, you might want to check out Tealstreet.io, a web-based trading terminal with advanced features and security. In this article, We will review Tealstreet.io based on its…

Xm Review

XM Review: Forex and CFD Broker

March 27, 2024

Founded in 2009, XM is a well-known Forex and CFD broker. The company’s parent organization, Trading Point of Financial Instruments Ltd., is headquartered in Cyprus.XM focuses on delivering online trading solutions and specializes in a variety of financial products such as…

How To Trade Gold

How to Trade Gold

July 1, 2024

This is an extensive beginner’s guide to provide the necessary knowledge that would be helpful for a beginner to start on. Understanding Gold Trading 1.Why Gold? 2. Gold Trading Strategies a. Fundamental Analysis: b. Sentiment Analysis: c. Technical Analysis: Example…

Sql Commands | Ddl, Dql, Dml, Dcl And Tcl Commands

What is the DLS Method in Cricket? In-Depth Look

July 1, 2024

 2007 Cricket World Cup Final: How The Duckworth-Lewis-Stern method (DLS) Shaped Australia vs Sri Lanka. The match between Australia and Sri Lanka, held at Kensington Oval, Bridgetown on 28th April 2007. Role of DLS: Pre-DLS Methods in Cricket: A Historical Overview…

Sql Commands | Ddl, Dql, Dml, Dcl And Tcl Commands

Best Conversation Intelligence Software: Skyrocket Sales And profits

July 1, 2024

A major bank was facing a puzzling problem: their customer satisfaction scores were plummeting, but they couldn’t pinpoint the reason. In a bid to understand what was happening, they decided to try a Conversation Intelligence (CI) software. CI software is…

Australian Taxation Office Clarifies Capital Gains Tax Treatment For Wrapped Crypto Tokens

Australian Tax Office to Impose Capital Gains Tax for Wrapped Crypto Tokens

July 1, 2024

Key Takeaways  The Australian Taxation Office (ATO) has clarified its position on the capital gains tax (CGT) treatment of decentralized finance (DeFi) and the wrapping of crypto tokens, emphasizing its commitment to taxing Australians on capital gains during the wrapping…

Sql Commands | Ddl, Dql, Dml, Dcl And Tcl Commands

The Ultimate Guide To Marketing Strategies & Types

July 1, 2024

Seth Godin: “Marketing is no longer about the stuff that you make, but about the stories you tell.” What is marketing? Marketing is the process of promoting, selling, and distributing a product or service. It encompasses a wide range of…

Share IT
Prabal Khanna
Prabal Khanna

Can’t find what you’re looking for? Type below and hit enter!