What is the full form of DDL? DDL stands for data description language. It is used in SQL, where SQL stands for Standard Query Language similar to other database management languages. It is a means of creating a database and its management. Data description language is also called data definition language.
Whichever website we visit or hover in has a set of the database for example let us consider amazon’s website. It is a place where we create our accounts and purchase products. And sellers can sell their products here. So, here amazon maintains a huge database of its customers (their names, age, address, etc.) and of its sellers (their business, products they sell, pickup locations, type of product), and many others. And storing such a huge database requires many terabytes of space. And these require a huge physical space also to accommodate such storage devices. So, to create these databases amazon uses Amazon DynamoDB, Amazon Aurora, etc. which are subtypes of SQL. These databases are created or modified using DDL Commands or Sentences.
What is a data description/definition language?
Data description language (DDL), also known as data definition language, is a SQL syntax for updating data structures including tables, indices, and users. And is used in defining the description of a database schema. DDL commands/statements are used to define data structures, particularly database schemas, in a way that is analogous to a computer programming language. CREATE, ALTER, and DROP are all examples of DDL commands. These commands are not usually used by a general user, who is just accessing the database to view it. It is used by a creator of the database as these commands form the basic outline of a database structure.
In the market, many languages are available, particularly for creating the database and some languages that are particularly made for modifying it. But in SQL, both operations are covered under one language, the DDL.
Commands of DDL with examples
- CREATE TABLE command
As the command itself suggests it is a command to create a table in a database. And the syntax for it is:
CREATE TABLE table_name (
column1 datatype,
column2 datatype,
column3 datatype,
….
);
For example,
CREATE TABLE employees (
Employee_serial_no INTEGER PRIMARY KEY,
first_name VARCHAR(25) not null,
last_name VARCHAR(25) not null,
address VARCHAR(150) not null,
city VARCHAR(50) not null
);
DROP Command
Drop Command is a command to destroy the whole table or a particular data.
Syntax:
DROP objecttype objectname.
For Example,
Drop Table Employee;
Or
Drop Table Student_List;
TRUNCATE command
Truncate command is a command used to delete the data inside the table except for the table itself. However, a difference between the DROP table and the TRUNCATE command is that in a DROP command the whole table/structure can get deleted but in the TRUNCATE the structure remains intact and the data inside the table only gets deleted.
Syntax:
TRUNCATE TABLE table_name;
For Example,
TRUNCATE TABLE Student_Data;
Or
TRUNCATE TABLE Employee;
ALTER Command
Alter command is a command used to modify the particular table and its data. And in RDBMS (relational database management system) it can change the properties of an object inside the table. Objects such as that depend on RDBMS.
Syntax:
ALTER TABLE table_name
ADD column_name datatype;
For example,
ALTER TABLE Student_Data
ADD Roll_No Integer;
Or
ALTER TABLE Employee
DELETE Address;
COMMENT
This is another important command used to comment in a data structure. Similar to any programming language it is of three types, namely the Single-line command, multi-Line command, and Inline command.
Syntax:
Single Line
— comment_1
— comment_2
SELECT * FROM Students;
Multiple Line
/* Comment_1
Comment_2 */
SELECT * FROM Students;
Inline
SELECT * FROM /* Customers;
For example,
Single Line
–Comment:
SELECT * FROM Students;
Multiline
/* SELECT * FROM Students;
SELECT * FROM Student_Data;
SELECT * FROM Employee; */
SELECT * FROM Business;
Inline
SELECT * FROM Students;
SELECT * FROM /* Student_Data;
SELECT * FROM Employee;
SELECT * FROM */ Business;
RENAME Command
This command is used to rename a particular table or its data. For this purpose, ALTER TABLE can also be used.
Syntax:
For renaming a table,
ALTER TABLE table_name
RENAME TO new_table_name;
For example,
Renaming a column
ALTER TABLE Student_Data
RENAME COLUMN roll_number TO serial_number;
CONCLUSION
To sum up, In view of SQL (Structured Query Language) DDL stands for Data description language, also known as Data Definition Language. There are a set of sentences or commands particularly used for creating or managing a database. CREATE, ALTER, DROP, RENAME, COMMENT, and TRUNCATE are a few examples of DDL commands. It works in the basic outline of a database and is used by a database creator.