Hey there π
Hope you are doing well π
In the last blog we have discussed about basic introduction to SQL. In this blog we are going to see some of the basic commands of SQL. We will be discussing DDL (Data Definition Language) commands in this blog.
So let's get started π₯
SQL Commands
Before starting our discussion I want tell you that you can practice SQL on the available online SQL compilers. I am attaching link of one here π
https://www.programiz.com/sql/online-compiler/
In SQL, DDL (Data Definition Language) commands are used to define, modify, and manage the structure of database objects such as tables, indexes, and schemas. Hereβs a comprehensive list of all commonly used DDL commands:
CREATE
ALTER
DROP
TRUNCATE
RENAME
COMMENT
USE
SHOW
CREATE Command
The CREATE command is create new database objects such as tables, views, indexes, and databases.
Create a Database -:
Note -: The statement will throw an error when you are working on an online compiler.Create a Table -:
Example -:
So here we have created a table namedstudent_record
that contains three type of data student's name which will be a string of atmost 100 characters, student's age which will be of integer type and student's ID which will also be a string of atmost 30 characters.
Note that duplicate column names (same name and same type) are not allowed.
SHOW Command
Used to display the metadata about database objects, such as tables or databases.
Show Table Structure
This command DESCRIBE is used to see complete table structure it gives complete detail of all columns in table.
USE Command
This command is used to select a specific database to work with in a session.
COMMENT Command
It is used to add comments to database objects like tables or columns for documentation purposes.
ALTER Command
It is used to modify existing database objects such as tables, columns, and constraints.
- Add a Column For example, Suppose we have a table that stores customers' data. Now we will add an "Email" column here.
-Modify a Column
Here we are changing data type of column.
Note that the ALTER TABLE
syntax can vary depending on the SQL dialect (e.g., MySQL, PostgreSQL, SQL Server, etc.) you're using. Some may support a particular keyword some may throw error.
DROP Command
It is used to delete database objects such as tables, databases, or indexes. This operation removes the object and its data permanently.
RENAME Command
It is used to rename a database object, such as a table or a view.
TRUNCATE Command
It is used to remove all rows from a table without logging individual row deletions, resetting the table for new data. This does not affect the table structure. This means the table become empty.
So these were all DDL Commands of SQL. In the next blog we will see some DML commands and will run different queries on table.
I hope you liked my blog. Please leave some β€ and don't forget to follow me.
Also have you checked my Instagram page where I upload necessary resources for software engineers.
If not check it out here -:
π Instagram: https://www.instagram.com/fluxx_96/
π YouTube: https://www.youtube.com/@Fluxx-n4q/shorts
Thankyou π
Top comments (0)