module(lab)sql
module(lab)sql
CREATION OF DATABASE
1|Page
Command prompt (CMD)
CREATION OF DATABASE
Start these two modules in order to create a database in the cmd. After that you can start to
create database in the cmd.
2|Page
Command prompt (CMD)
CREATION OF DATABASE
After hitting the enter button you can see, what we type in the cmd. In order to access the
MariaDB or the phpMyAdmin. NOTE: that we can disregard the password and just hit enter on
the keyboard.
By default, there are no password in the MariaDB, if there is contact your instructor in the
subject and show him the results in your CMD.
3|Page
Command prompt (CMD)
CREATION OF DATABASE
The next step is to create database that you want to create. As you can see, we used the ‘SHOW
DATABASES’ to show all the bases that are available in the MariaDB. The next we type is
‘CREATE DATABASE modules’ to create the database named ‘modules’.
As you can see the in the ‘SHOW DATABASES’ we can see the list of databases that are available
in the MariaDB. We can see that the database we create named ‘modules’ has been added in
the list since we create it a while ago.
4|Page
Command prompt (CMD)
CREATION OF DATABASE
Now, we want to use ‘modules’ as our database. As you can see, we use the keyword ‘USE
modules’ to use the database named ‘modules’ now we can apply the CRUD operation that
we’re going to used in the next steps.
5|Page
Command prompt (CMD)
CREATION OF DATABASE
We used the keyword ‘SHOW TABLES’ to show the tables that are available in the database
‘modules’ that we create a while ago. As you can see, there are no available or database is
empty set since we did not create a table yet.
6|Page
Command prompt (CMD)
CREATION OF DATABASE
Now, we create the tables ‘users’ in the table ‘users’ we added ‘id’, ‘name’, ‘last_name’, ‘email’,
‘password’, and we added ‘id’ as the primary key of this table.
7|Page
Command prompt (CMD)
CREATION OF DATABASE
Now, we used the keyword ‘DESC users’ to describe the table users, what are the field that are
in the table ‘users’ type and what are the primary key of the table.
8|Page
Command prompt (CMD)
CREATION OF DATABASE
Now, we add or insert into users. The keyword is ‘INSERT INTO users (name, last_name, email,
password) VALUES’ after that the data that we want to insert in the table users. As you can see,
we insert ‘sonny’ in the name, ‘masanque’ in the last_name, ‘[email protected]’ in the email,
‘sonnypogi’ in the password.
9|Page
Command prompt (CMD)
CREATION OF DATABASE
Now, we used the keyword ‘SELECT * FROM users’ to show the data that has been inserted a
while ago. As you can see, we didn’t add ‘id’ in the last step but there is number 1, we can
understand this by going back what we do in creating this table. Remember that we add id and
put it as ‘AUTO_INCREMENT’ since we put this, we didn’t have to add value in the ‘id’ upon
inserting data. The ‘*’ means we select all the data that has been available in the table ‘users’.
10 | P a g e
Command prompt (CMD)
CREATION OF DATABASE
As you can see, we insert one more data in the table. As, we mentioned a while ago the
keyword ‘SELECT * FROM users’ means selecting all the available or inserted data in the table
named ‘users’
Now, we used the keyword ‘SELECT * FROM users WHERE id = 1’ we are pertaining now to the
id number 1 as shows. It will only show the id number 1, unlike the ‘SELECT * FROM users’
11 | P a g e
Command prompt (CMD)
CREATION OF DATABASE
12 | P a g e
Command prompt (CMD)
CREATION OF DATABASE
Now, we are using the keyword ‘DELETE FROM users WHERE id = 2’. In this keyword we are
deleting the id number 2 in the table. In the following image you can see that the deleted id will
not be available in the table anymore since it will be permanently deleted in the table.
As you can see the id number 2 is deleted in the table, and it will be deleted permanently. This
the simple way of creating database in the cmd with the power of MariaDB or XAMPP.
13 | P a g e
Command prompt (CMD)
CREATION OF DATABASE
If we want to drop the database, just hit the keyword ‘DROP DATABASE modules’ as we know
‘modules’ is the named of the database.
14 | P a g e