Hello everyone,
MySQL is starting to get fun. All of this thanks to this new semester project "Designing and programming a database".
It's been great so far because we started learning the basic commands like CREATE, ALTER or DROP. When it refers to creating a table inside the database it's so simple, you just type something like this:
CREATE TABLE PRODUCT (
Product_ID int NOT NULL UNIQUE,
Product_Name varchar (50),
Unit int,
Stock_Alert bool,
PRIMARY KEY (Product_ID)
);
Now you're ready to create your first table (you'll have to run the code otherwise the table won't be created). I took this example because it's in our first activity where we have to transform a relational model (which we had to create in a previous activity from another subject in the first semester) using code.
ALTER, as the name itself, is used to modify the structure of the database.
For example, if we want to add a new column for the stock of our products (the amount, for example 10.5 kg) to our table product, we could add a new column named Stock. We'll do this using ALTER like this:
ALTER TABLE PRODUCT
ADD Stock float;
Run the code and know you have the new column in your table (easy peasy lemon squeezy 🍋)
So let's imagine you want to delete the table because you don't need anymore. How'd you do that?
The answer is DROP. You just type this code:
DROP TABLE PRODUCT;
After you've run your code, the table product will no longer exist (unless you create it again 😆).
I hope you liked my explanation with first contact with MySQL. I liked it so much, and I'm looking forward to learning how to use other instructions like SELECT, INSERT, UPDATE, etc.
This is going to be interesting.
Salut, Jordi.
Cover image credit to @iswanto