The Wayback Machine - https://web.archive.org/web/20240822161842/https://www.geeksforgeeks.org/ddl-commands-syntax/
Open In App

DDL Commands & Syntax

Last Updated : 03 Apr, 2023
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

In this article, we will discuss the overview of DDL commands and will understand DDL commands like create, alter, truncate, drop. We will cover each command syntax with the help of an example for better understanding. Let’s discuss it one by one.

Overview :
Data Definition Language(DDL) is a subset of SQL and a part of DBMS(Database Management System). DDL consist of Commands to commands like CREATE, ALTER, TRUNCATE and DROP. These commands are used to create or modify the tables in SQL.

DDL Commands :
In this section, We will cover the following DDL commands as follows.

  1. Create
  2. Alter 
  3. truncate
  4. drop
  5. Rename 

Let’s discuss it one by one.

Command-1 :
CREATE :
This command is used to create a new table in SQL. The user has to give information like table name, column names, and their datatypes.

Syntax –

CREATE TABLE table_name
(
column_1 datatype,
column_2 datatype,
column_3 datatype,
....
);

Example –
We need to create a table for storing Student information of a particular College. Create syntax would be as below.

CREATE TABLE Student_info
(
College_Id number(2),
College_name varchar(30),
Branch varchar(10)
);

Command-2 :
ALTER :
This command is used to add, delete or change columns in the existing table. The user needs to know the existing table name and can do add, delete or modify tasks easily.

Syntax –
Syntax to add a column to an existing table.

ALTER TABLE table_name
ADD column_name datatype;

Example –
In our Student_info table, we want to add a new column for CGPA. The syntax would be as below as follows.

ALTER TABLE Student_info
ADD CGPA number;

Command-3 :
TRUNCATE :
This command is used to remove all rows from the table, but the structure of the table still exists.

Syntax –
Syntax to remove an existing table.

TRUNCATE TABLE table_name;

Example –
The College Authority wants to remove the details of all students for new batches but wants to keep the table structure. The command they can use is as follows.

TRUNCATE TABLE Student_info;

Command-4 :
DROP :
This command is used to remove an existing table along with its structure from the Database.

Syntax –
Syntax to drop an existing table.

DROP TABLE table_name;

Example –
If the College Authority wants to change their Database by deleting the Student_info Table. 

DROP TABLE Student_info;

Command -5

RENAME:

It is possible to change name of table with or without data in it using simple RENAME command.

We can rename any table object at any point of time.

Syntax –

RENAME TABLE <Table Name> To <New_Table_Name>;

Example:

If you want to change the name of the table from Employee to Emp we can use rename command as 

RENAME TABLE Employee To EMP;


Similar Reads

SQL Commands | DDL, DQL, DML, DCL and TCL Commands
SQL commands are very used to interact with the database. These commands allow users to perform various actions on a database. This article will teach us about SQL commands or SQL sublanguage commands like DDL, DQL, DML, DCL, and TCL. All important SQL commands with their syntax and examples are covered in this article. But before heading to the SQ
6 min read
DDL Full Form
DDL stands for Data Definition Language. These commands are used to change the structure of a database and database objects.For example, DDL commands can be used to add, remove, or modify tables with in a database.The DDL commands are: CREATEALTERDROPTRUNCATERENAME 1. CREATE : This command is used to create table in the relational database . This c
4 min read
Difference between DDL and TCL
Prerequisite – SQL Commands 1 Data Definition Language (DDL) is a set of SQL (Structured Query Language) commands used to create, modify, and delete database objects such as tables, indexes, views, and constraints. DDL statements are used to define the schema or structure of a database, including its data types, relationships between tables, and ru
2 min read
Difference Between DDL and DML in DBMS
DDL is a Data Definition Language that is used to define data structures. For example: creating a table, and altering a table are instructions in SQL. DML is a Data Manipulation Language that is used to manipulate data itself. For example: insert, update, and delete are instructions in SQL. Data Definition Language DDL is used to specify a database
3 min read
SQL | DDL, DML, TCL and DCL
Data Definition Language (DDL), Data Manipulation Language (DML), Transaction Control Language (TCL), and Data Control Language (DCL) form the backbone of SQL. Each of these languages plays a critical role in defining, managing, and controlling data within a database system, ensuring both structural integrity and user access control. In this articl
6 min read
Adding &amp; Editing &amp; Deleting &amp; Searching Records with Data Form
Overview :To manage records using Data Form, it will give you the following options like adding data, deleting data, searching data using data from. Let's discuss Adding, Deleting, Searching Records with Data Form as follows. Steps to implement operations with data form :Here, we will discuss how you can add, delete and search data using data form
4 min read
SQLite Statements and Syntax
SQLite is a self-contained, file-based SQL database that follows a specific syntax. Statements in SQLite are used to query the database and are essential for database management. Every statement follows a fixed syntax in SQLite. In this guide, we will look at some important SQLite statements and syntaxes. We have divided the statements into several
3 min read
SQL Syntax
Structured Query Language (SQL) is a standardized Query language essential for managing and manipulating relational databases. Mastery of SQL syntax is crucial for writing effective SQL queries and ensuring proper interaction with database management systems (DBMS). This guide will provide a thorough understanding of SQL syntax, enhancing clarity a
3 min read
Useful and time saving bash commands in Linux
There are many useful bash scripts that can make things easier. Many things can be done just using the terminal. Here is a list of some of such useful bash scripts through which we can do things that cannot be done manually. 1. Counting the number of files(or directory) in a given directory: Go to the directory in which you want to count the number
3 min read
halt, poweroff and reboot Commands in Linux
Below are typical uses of halt, poweroff and reboot. halt : Instructs hardware to stop CPU functions. poweroff : Instructs the system to power down. reboot : Restarts or reboots the system. The above mentioned commands can only be run by super user as these involve the actions to stop the system hardware. If the user is not logged in as super user
2 min read
How to run Linux Commands on Windows 10?
It is a dilemma when you want to switch from one operating system to another. This is a common case when you switch from Windows to Linux. Either you store your data and then uninstall Windows to install Linux and then transfer your data or you can have a dual boot system where you encounter an option as to which OS to choose in the beginning. Don'
2 min read
Auto-commit commands and Compensating transactions in SQL
As the name suggests, the auto-commit statement is used to avoid the explicit mention of the commit command after each SQL statement. The commit statement itself gets executed by the server after each SQL statement. Each SQL statement is treated as a different transaction. An SQL statement executed in autocommit mode cannot be rolled back. Auto-com
3 min read
Basic SQL Commands
QUESTION: Consider the following table ITEM given below, write the commands in SQL for 1 – 10 and output for 11 – 20 TABLE: ITEM S_NoItem_NameCompanyCostPurchase_QtyDOP1MonitorABC6300202010-05-302CPUCDF8000302010-07-233MouseFGH250252010-08-044UPSHIJ2100102010-06-195PrinterJKL840042010-11-276ScannerJKL450062010-08-14 Write the SQL commands for 1. to
2 min read
Basic Linux Commands for day to day life
This article will explore the basic Linux commands and how to use them. 1. ls: How would we know what a folder contains? With a graphical interface, you'd do this by opening a folder and inspecting its contents. From the command line, you use the command ls instead to list a folder's contents. By default, ls will use a very compact output format. M
7 min read
Network configuration and troubleshooting commands in Linux
Computers are often connected to each other on a network. They send requests to each other in the form of packets that travel from the host to the destination. Linux provides various commands from network configuration and troubleshooting.  Network Configuration and Troubleshooting Commands in Linux Using Ping (Packet Internet Groper) Command Using
5 min read
SQL | Intersect &amp; Except clause
1. INTERSECT clause : As the name suggests, the intersect clause is used to provide the result of the intersection of two select statements. This implies the result contains all the rows which are common to both the SELECT statements. Syntax : SELECT column-1, column-2 …… FROM table 1 WHERE….. INTERSECT SELECT column-1, column-2 …… FROM table 2 WHE
1 min read
Categories of Two Phase Locking (Strict, Rigorous &amp; Conservative)
Now that we are familiar with what is Two-Phase Locking (2-PL) and the basic rules which should be followed which ensures serializability. Moreover, we came across problems with 2-PL, Cascading Aborts, and Deadlocks. Now, we turn towards the enhancements made on 2-PL which try to make the protocol nearly error-free. Briefly, we allow some modificat
4 min read
Trigonometry &amp; Height and Distances | Set-2
Question 1: Find the maximum value of (2sinθ + 3 cosθ) Solution : Max value of (asinθ + bcosθ) = √(a2 + b2)) So, max value = √(22 + 32) = √(4 + 9) = √13 Question 2: Find the minimum value of the 4tan2θ + 9cot2θ Solution : Minimum value = √ab Here a = 4 and b = 9 Minimum value = √(4x9) = √36 = 6 Question 3: If θ be an acute angle and 7sin2θ + 3cos2θ
5 min read
How to find Segmentation Error in C &amp; C++ ? (Using GDB)
What is Segmentation Error ? - It is the runtime error caused because of the memory access violation. For Eg :-Stackoverflow, read violation etc.. We often face this problem when working out with pointers in c++/c. In this example we will see how to find the segmentation error in the program. We will find which lines causes the segmentation fault e
3 min read
LOG() &amp; LOG10() in SQL Server
The LOG() function could be used to calculate the natural logarithm of a specific number. 1. LOG() : Syntax : SELECT LOG(number); Note : Parameter number is mandatory. The number must be greater than 0. Example - SELECT LOG(2); Output - 0.69314718055994529 2. LOG10() : The LOG10() function could be used to calculate the natural logarithm to base 10
1 min read
Parametric &amp; Geometric Continuity of Curves in Computer Graphics
Prerequisite: B-spline curve, Bezier curve The continuity condition represents that how smoothly a curve transit from one curve segment to another segment. Consider you are given a curve as shown below: There are three kinds of Parametric continuities that exist: (a) Zero-order parametric continuity(_C0 ) : A curve is said to be zero-order parametr
2 min read
Flat &amp; Nested Distributed Transactions
Introduction : A transaction is a series of object operations that must be done in an ACID-compliant manner. Atomicity - The transaction is completed entirely or not at all.Consistency - It is a term that refers to the transition from one consistent state to another.Isolation - It is carried out separately from other transactions.Durability - Once
6 min read
Django ORM - Inserting, Updating &amp; Deleting Data
Django lets us interact with its database models, i.e. add, delete, modify, and query objects, using a database-abstraction API called ORM(Object Relational Mapper). This article discusses all the functional operations we can perform using Django ORM. Prerequisite: Django models Django ORM Django's Object-Relational Mapping (ORM) system, a fundamen
3 min read
Samsung R&amp;D, Bangalore Interview (1 Year Experienced)
Samsung R&amp;D, Bangalore was recently hiring 1 year experienced for position of software Engineer Round 1 (3 hrs) online : Check whether graph is bipartite and prints all elements of one set Round 2 (15 mins) : Interviewer went through my cv and asked questions on my projects Round 3 (45 mins) : Interviewer asked me questions related to ML algori
1 min read
JavaScript setTimeout() &amp; setInterval() Method
JavaScript SetTimeout and SetInterval are the only native function in JavaScript that is used to run code asynchronously, it means allowing the function to be executed immediately, there is no need to wait for the current execution completion, it will be for further execution. JavaScript setTimeout() MethodThis method executes a function, after wai
3 min read
Palindromic Tree | Introduction &amp; Implementation
Palindromic Tree is a tree-based data structure designed for efficient string processing tasks such as pattern matching, string searching, and spell-checking. It is an advanced data structure based on a trie that is optimized for palindromic strings. A Palindromic Tree is a trie-like data structure that stores all the substrings of a given string i
15+ min read
DBMS Tutorial – Learn Database Management System
Database Management System is a software or technology used to manage data from a database. Some popular databases are MySQL, Oracle, MongoDB, etc. DBMS provides many operations e.g. creating a database, Storing in the database, updating an existing database, delete from the database. DBMS is a system that enables you to store, modify and retrieve
7 min read
SQL Tutorial
In this SQL tutorial, you’ll learn all the basic to advanced SQL concepts like SQL queries, SQL join, SQL injection, SQL insert, and creating tables in SQL. SQL is easy to learn, there are no prerequisites to learning SQL. So, SQL is a standard database language used to access and manipulate data in databases. SQL stands for Structured Query Langua
11 min read
SQL Interview Questions
SQL is a standard database language used for accessing and manipulating data in databases. It stands for Structured Query Language and was developed by IBM Computer Scientists in the 1970s. By executing queries, SQL can create, update, delete, and retrieve data in databases like MySQL, Oracle, PostgreSQL, etc. Overall, SQL is a query language that
15+ min read
Introduction of ER Model
Peter Chen developed the ER diagram in 1976. The ER model was created to provide a simple and understandable model for representing the structure and logic of databases. It has since evolved into variations such as the Enhanced ER Model and the Object Relationship Model The Entity Relational Model is a model for identifying entities to be represent
10 min read
Article Tags :
Practice Tags :
three90RightbarBannerImg