Vikas Rajput
Vikas Rajput

@vikasrajputin

9 Tweets 1 reads Jul 10, 2023
To master SQL, you need to have an extremely good understanding of SQL statements:
They're mainly divided into 5 categories: DDL, DQL, DML, DCL, TCL
Here's the simplest guide to learn DDL:
1. Create statements
This DDL statement is used to create a new table, database, view, or other database objects.
For example, to create Employees table we can use below query:
2. Alter statements
This statement helps in modifying the structure of a database object. For eg: we can add columns, changing their datatype, etc.
Let's add Salary column in the Employees table using below query:
We can also use ALTER to modify a column's datatype
As shown below, we've change Salary column to Decimal data type:
3. Truncate
This statement is used to delete all the data from a table, without removing the table structure:
For example, below query is to empty whole Employee table:
4. Drop
It is used to delete either a column from a table or the entire table.
Unlike TRUNCATE, DROP removes the table structure:
For example, below will remove entire table alongwith it's structure:
5. Rename
This statement is used to rename an existing database object.
For instance, we can rename Employees table to Staff using below query:
6. Comment
This DDL statement is used to add comments to the data dictionary.
Here's how to add a comment to a table:
Thanks for Reading!
Every week, I write about my experience and learning as a Backend Developer.
For more content like this, follow me @vikasrajputin
If you find this thread helpful, please like and retweet the first tweet below:

Loading suggestions...