A. Data Definition Language (DDL)
By using DDL we can change the structure of our tables. Since all the command of DDL are auto committed it permanently saves all the changes in the database.
1. CREATE
Let's suppose you want to create a table with information about the type of rooms in the listings. The command below allows you to create a new database or table.
1CREATE TABLE room_details(
2 room_type TEXT,
3 room_size INTEGER
4);
2. ALTER
Now let’s say you want to add a column to the airbnb_listings table which states if the property is reserved or not. The next command is used to modify (add, drop, rename, etc) the structure of the data in your database, it should be noted the data will remain unchanged.
1ALTER TABLE airbnb_listings
2ADD listings_reserved BOOLEAN;
3. DROP
So you’ve decided that the table you created no longer serves a purpose and you want to delete it. The DROP command deletes a database or table. Before running this command you should be aware that it will delete your whole table, including all data, indexes, and more, so make sure you are certain before you run.
1DROP TABLE room_details;
To delete a specific column we can combine the ALTER TABLE command with the DROP command.
1ALTER TABLE airbnb_listings
2DROP COLUMN listings_reserved;
4. TRUNCATE
This command is used to remove all data entries from a table in a database while keeping the table and structure in place.
1TRUNCATE TABLE airbnb_listings;