DAY 25 - Come Home with SQL Query Command Types
Mandy Glynn
Data Analyst | Business Analyst || What wisdom does your data hold? || SQL | Tableau | Python | Excel |
CLICK HERE for the "Learn Something New Every Day" 30-day project introduction
There are five types of SQL Query Command Types.?Knowing what the purpose of these are and what types of commands are included can help you to understand what you are really doing with your code (like not permanently deleting something when you didn't mean to).?It can also help you to read the code of others and understand what is going on.
I love to compare new things I learn with things I already know about.?This helps create multiple connections to new material and makes it easier to understand and access at a later time (if you have read many of my articles, you will know that I am HUGE on making connections).
For today I am comparing databases and data to your house.?The house is the database structure, and the data is all the things you put into it to make it your home.
SQL Query Command Types are how we interact with the house in our daily lives.
DDL: Data Definition Language
BUILDING/REMODELING THE HOUSE.?This is building the house based on blueprints.?It can also be building an addition or tearing down a deck -you still have what is in your house, but you have changed the structure.?In your database, this creates and modifies the structure, but doesn't necessarily change the data if you already have it there.
COMMANDS: CREATE, ALTER, DROP, TRUNCATE, COMMENT, RENAME
?
DML: Data Manipulation Language
FURNISHING THE HOUSE.?This is adding/removing/changing things like furniture or dishes to your home that will make it useful to live there.?In your database, this is how you modify the actual data.
COMMANDS: INSERT, UPDATE, MERGE, DELETE, LOCK, CALL, EXPLAIN PLAN
?
DQL: Data Query Language
USING YOUR STUFF. You use the items you have furnished your house with.?This is cooking on your stove, making new, exciting meals with the ingredients you placed there.?In your database, this is how you use your data, how you call it up and order it in ways that make sense and are useful to you.
领英推荐
COMMANDS: SELECT
?
TCL: Transaction Control Language
PERMANENCE.?This is making a change permanent in your home, like if you want to permanently install a bookshelf by screwing it into a wall instead of just placing it there.?In your database, since the updates that DML commands make can be canceled before the session is closed, this can help make the changes permanent as well as gives the opportunity to undo them and return to a previous state if completed in error.
COMMANDS: SET TRANSACTION, COMMIT, SAVEPOINT, ROLLBACK
?
DCL: Data Control Language
SECURITY. In your house it is how you keep intruders out and allow the people who have permission to come in.?It is the deadbolt on the front door and the selective distribution of keys. In your database, this is how you control access to the database.
COMMANDS: GRANT, REVOKE
?
I hope this helps you remember and understand the types that SQL commands are categorized into.?While this isn't necessary to learn how to use SQL, it is useful for setting a solid foundation of understanding to build your SQL house on!
?
As always, stay Inquisitive, my friends!