Database Languages in DBMS
- Data Definition Language (DDL)
- Data Manipulation Language (DML)
- Data Control Language (DCL)
- Transaction Control Language (TCL)
- Data Query Language (DQL)
- Data Definition Language (DDL)
DDL is used to define the database schema, i.e., the structure and organization of data in the database. It allows the user to create, modify, and delete database objects like tables, views, indexes, etc. Examples of DDL commands include CREATE, ALTER, and DROP.
For example, the following DDL command creates a table named “employees” with three columns: “id”, “name”, and “salary”.
CREATE TABLE employees ( id INT PRIMARY KEY, name VARCHAR(50), salary INT );
Some of the tasks that come under Data Definition Language (DDL) include:
- Creating tables: This involves defining the structure of the table, including the column names, data types, and constraints.
- Modifying tables: This includes adding, modifying, or dropping columns, changing data types, and adding or removing constraints.
- Creating indexes: This involves creating indexes on tables to improve performance.
- Defining views: This involves creating a virtual table that is derived from one or more existing tables.
- Creating sequences: This involves creating a sequence of numbers that can be used to generate unique values for primary key columns.
- Creating synonyms: This involves creating an alternative name for a table, view, sequence, or other database object.
- Granting or revoking permissions: This involves granting or revoking privileges to users or roles to perform specific actions on database objects.
These tasks are essential in creating and managing the database schema, which is the structure that defines the database objects and their relationships.
- Data Manipulation Language (DML):
DML is used to manipulate the data stored in the database. It allows the user to insert, update, retrieve, and delete data from tables. Examples of DML commands include SELECT, INSERT, UPDATE, and DELETE, Truncate: It is used to remove all records from a table, Rename: It is used to rename an object. Comment: It is used to comment on the data dictionary.
Some of the tasks that come under DML are:
- Inserting data into a table: This operation is used to add new data to an existing table in the database.
- Updating existing data: This operation is used to modify or update existing data in a table.
- Deleting data: This operation is used to remove data from a table.
- Retrieving data: This operation is used to retrieve data from one or more tables in the database.
- Sorting data: This operation is used to sort data in ascending or descending order based on one or more columns.
- Filtering data: This operation is used to filter data based on specific criteria.
- Joining tables: This operation is used to combine data from two or more tables in the database.
- Grouping data: This operation is used to group data based on one or more columns.
- Aggregating data: This operation is used to perform calculations on data, such as calculating the sum, average, or maximum value of a column.
For example, the following DML command inserts a new record into the “employees” table:
INSERT INTO employees (id, name, salary) VALUES (1, ‘John Smith’, 50000);
- Data Control Language (DCL):
DCL is used to control access to the database. It allows the user to grant or revoke privileges to other users or roles. Examples of DCL commands include GRANT and REVOKE.
For example, the following DCL command grants SELECT privilege on the “employees” table to a user named “user1”:
GRANT SELECT ON employees TO user1;
Here are some tasks that come under DCL:
- Grant: It is used to give user access privileges to a database.
- Revoke: It is used to take back permissions from the user.
- Transaction Control Language (TCL):
TCL is used to control transactions in the database. It allows the user to start, commit, or rollback transactions. Examples of TCL commands include COMMIT and ROLLBACK.
For example, the following TCL command commits a transaction:
Here are some tasks that come under TCL:
- Commit: It is used to save the transaction on the database.
- Rollback: It is used to restore the database to original since the last Commit.
- Data Query Language (DQL):
DQL is a subset of DML used specifically for querying data from the database. It allows the user to retrieve data from tables based on certain conditions. Examples of DQL commands include SELECT and FROM.
For example, the following DQL command retrieves all records from the “employees” table:
SELECT * FROM employees;
In conclusion, these different types of languages in DBMS provide a comprehensive set of tools to create, modify, manipulate, and control the data stored in a database. Understanding the purpose and usage of each type of language is important for efficient and effective management of a database.