DEV Community

jayson kibet
jayson kibet

Posted on

What really is DDL and DML and their comparision

Introduction

About three weeks ago,I jumped into learning SQL.I thought it's all about writing queries and getting results by running them and thats all.Yes i had a point but when i went deeper in learning SQL,I realized thereโ€™s a clear split in how SQL actually works.DDL (Data Definition Language) and DML (Data Manipulation Language).

DDL(Data Definition Language)

This is what you use to create and define your database.It deals with the structure of your table.When you run them,the table either exists or it doesn't.You can think of it as an empty house(empty rooms just walls)

DML(Data Manipulation Language)

This actually works with the data inside your table.You can think of it as the staff inside your house.

NOTE:DDL deals with the structure while DML deals with the data.

How I used CREATE, INSERT, UPDATE, and DELETE

1.Create

This command creates the table of your title choice

2.Insert

This command allows you to fill your table by inserting data into the table you created following the data type strictly.

The data type should corespond with the data you put in the table you created.

3.Update

The update command allows you to make changes in your table for instance if you made a mistake and you need to make immediate changes.

4.Delete/drop

The 'delete' command allows you to eliminate a specific rows of your choice while alter messes with the columns.

Filtering and Where

The where clause is actually one of the most important commands.Its actually my 'best friend'since I interact with it a lot.Without this you cannot execute the delete and update command since it will affect every row.

1.=(equals to)

=(equals to) only filters the data corresponding to your where clause.

It will only highlight the form 4 students.

2.>=(greater than or equals to)

This only selects the data that is above or equal the highlighted command in the where clause.

3.Like

It is done by adding a percentage before of after a character to give a hint that there is some characters but it's just not given.

subjects like computer studies will be highlighted.

4.Between

This gives the data that is in the range that you highlighted


Marks like 70s will be included.

5.In

This matches the list.After the function'In',it is then followed by brackets and data separated by a comma in between them inside the bracket

Case when

This is a condition inside a query.It's almost similar to the 'if' statement in Excel and power BI.I didn't expect myself to like this as much as i do at the moment.

What i found challenging while attempting my assignment

In a spreadsheet, you click a cell and type. In SQL,you describe exactly what you want to change and under what conditions. The approach feels rigid at first, but it is actually more precise. You cannot accidentally drag a formula into the wrong column.
Also while doing the assignment,I ran an UPDATE without a WHERE clause.Every data in the table immediately became 'Unknown'.That mistake reinforced two habits: always try to always write the WHERE clause first before anything else and always work inside a transaction when experimenting.

Conclusion

The past few weeks taught me that SQL isn't about memorizing commands.First,you set up the structure with DDL,you then work inside it with DML.Think of it like building a house from scratch.At one point I ran an UPDATE without a WHERE clause and watched every single row change at once.That really got me frustrated.Now 'WHERE' and 'CASE WHEN' don't feel like random syntax anymore,they feel like tools I actually want to use.
If you're just starting out,always remember to write your conditions before your changes.

Top comments (0)