0% found this document useful (0 votes)
19 views7 pages

Database Languages

Uploaded by

Ila Naqvi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views7 pages

Database Languages

Uploaded by

Ila Naqvi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Database Languages

A database language is a specialized programming language designed for


managing and interacting with a database management system
(DBMS). These languages allow users to perform various operations,
including defining the database structure, manipulating data, controlling
access, and managing transactions.

1. DDL (Data Definition Language)

2. DCL (Data Control Language)

3. DML (Data Manipulation Language)

4. TCL (Transaction Control Language)


DDL (Data Definition Language)
The DDL stands for Data Definition Language, Which is used to define the
database's internal structure and Pattern of the Database. It is used to define
and modify the structure of the database itself, including the tables, views,
indexes and other schema-related objects. It deals with the creation and
modification of database schema, but it doesn't deal with the data itself.
Following are the five DDL commands in SQL:

 CREATE: Used to create database objects like tables, indexes or views.

 ALTER: Used to modify the structure of an existing database object,


such as adding a new column to a table.

 DROP: Used to delete database objects.

 TRUNCATE: Used to remove all rows from a table, without affecting


the structure.

 RENAME: Used to change the name of a database object.

DML (Data Manipulation Language)


The DML (Data Manipulation Language) is used toto manage and manipulate
data within a database. With DML, you can perform various operations such
as inserting, updating, selecting and deleting data. These operations allow
you to work with the actual content in your database tables. Here are the key
DML commands:

 SELECT: Retrieves data from the table based on specific criteria.

 INSERT: Adds new rows of data into an existing table.

 UPDATE: Modifies existing data in a table.

 DELETE: Removes data from a table.

 MERGE: Performs an "upsert" operation, which means updating


existing records or inserting new ones if they don’t exist.

 CALL: Executes stored procedures or functions.

 LOCK TABLE: Prevents other users from accessing the table while
changes are being made.

DCL (Data Control Language)


DCL stands for Data Control Language. It is used to control the access
permissions of users to the database. DCL commands help grant or revoke
privileges to users, determining who can perform actions like reading or
modifying data. DCL commands are transactional, meaning they can be
rolled back if necessary. The two main DCL commands are:

 Grant: Gives user access to the database

 Revoke: Removes access or permissions from the user

TCL ( Transaction Control Language )


The TCL full form is Transaction Control Language commands are used to
manage and control transactions in a database, grouping them into logical
units. These commands help ensure the integrity of data and consistency
during complex operations. Here are the two main commands in this
category:

 Commit: Saves all the changes made during the current transaction to
the database. These are very useful in the banking sector.

 Rollback: used to restore the database to its original state from the
last commit. This command also plays an important role in Banking
Sectors.

Data Definition Language


1.1 CREATE Command

The CREATE is a DDL command used to create databases,


tables, triggers and other database objects.

Syntax:

CREATE TABLE Students (


column1 INT,
column2 VARCHAR(50),
column3 INT
);

1.2 Alter Command

ALTER is a DDL command which changes or modifies the existing structure of


the database and it also changes the schema of database objects. We can
also add and drop constraints of the table using the ALTER command.

Syntax:

ALTER TABLE Students ADD column_name;

1.3 Drop Command


DROP is a DDL command used to delete/remove the database objects from
the SQL database. We can easily remove the entire table, view or index from
the database using this DDL command.

Syntax:

DROP Table Table_name;

1.4 Truncate Command

The TRUNCATE command is used to delete all the records from a table
without removing the structure. Unlike the DELETE command, which can
remove specific rows and can be rolled back, TRUNCATE is a more efficient
way to delete all rows in a table without logging individual row deletions.

Syntax:

TRUNCATE TABLE table_name;

1.5 Rename Command

The RENAME command in a Database Management System (DBMS) is used


to change the name of a database object, such as a table, column or index.
This command is helpful when we want to give a more meaningful or
appropriate name to an object without needing to recreate it.

Syntax:

ALTER TABLE Old_Table_Name RENAME TO New_Table_Name;

DML (Data Manipulation Language)


2.1 SELECT Command

The SELECT command in SQL (Structured Query Language) is used to


retrieve data from one or more tables in a database. It is the most commonly
used commands in SQL, allowing users to specify which columns and rows of
data they want to retrieve and how they want that data organized. The
SELECT statement can be used in various ways, such as selecting all data
from a table, filtering records based on conditions or sorting the results.

Syntax:

SELECT * FROM Table_Name

2.2 Insert Command

The INSERT command in SQL (Structured Query Language) is used to add


new records or rows to a table in a database. It is a key operation in
database management, essential for populating tables with new data. This
command can insert data into all columns or specific columns of a table.

Syntax:

INSERT INTO Table_Name (Column 1, Column 2, Column 3, Column 4) VALUES


(Value 1, Value 2,Value 3, Value 4);

2.3 Update Command

The UPDATE command in SQL (Structured Query Language) is used to modify


existing records in a table. This command enables users to change the
values of one or more columns for specific rows based on a condition
(criteria). It is important for maintaining and adjusting data in a database
when necessary.

Syntax:

UPDATE Table_Name SET Name = 'New_Value' WHERE Name = 'Ola_Value';

2.4 Delete Command

The DELETE command in SQL (Structured Query Language) is used to


remove one or more existing records from a table in a database. It is an
essential operation for managing data, enabling users to delete specific rows
that meet certain conditions or criteria.

Syntax:

DELETE FROM Table_Name WHERE Column = Value;

2.5 Merge Command

The Merge command in SQL is used to perform an upsert operation, which


combines both UPDATE and INSERT actions. It allows you to insert new rows
if they do not exist or update existing rows if they match a certain condition.
This command is particularly useful for synchronizing two tables by inserting
new records and updating existing ones in a single operation.

Syntax:

MERGE INTO target_table AS target


USING source_table AS source
ON (target.id = source.id)
WHEN MATCHED THEN
UPDATE SET target.name = source.name
WHEN NOT MATCHED THEN
INSERT (id, name) VALUES (source.id, source.name);
Example:

MERGE INTO Employees AS target


USING New_Hires AS source
ON target.EmployeeID = source.EmployeeID
WHEN MATCHED THEN
UPDATE SET target.Name = source.Name, target.Salary = source.Salary
WHEN NOT MATCHED THEN
INSERT (EmployeeID, Name, Salary)
VALUES (source.EmployeeID, source.Name, source.Salary);
2.6 CALL Command

The Call command is used to invoke a stored procedure or user-defined


function, which is a set of precompiled SQL statements. It allows you to
execute complex operations within a database as a single unit.

Syntax:

CALL user_defined_function(parameter 1, parameter 2);

Example:

CALL UpdateEmployeeSalary(101, 55000);

2.7 LOCK TABLE

The lock table command is used to lock the table for preventing access from
others, ensuring no other operations (like insertions, updates or deletions)
can be performed on the table while it's locked. Useful for transactional
operations where consistency is important.

Syntax:

LOCK TABLE your_table IN EXCLUSIVE MODE;

Example:

LOCK TABLE ClassMembers IN EXCLUSIVE MODE;

You might also like