Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

Name: Muhammad Omair

Reg. no: BSCS2019-58

Computer science (2nd year)

Database lab Report:

First of all open MySQL 8.0 Command Line Client. Enter your password.

By entering password, MySQL command line will be opened.


To create a database, type “create database [name of database];” Have a look it below picture.

Now the data is created. To check whether database is created or not, type “show databases;”

The highlighted “testdb” has been created.


Now we will make a connection by clicking on the small “+” button.

Type your connection name, and enter “store in vault”.

A password screen will be appeared. Type your password.


After entering the password, click on test connection. If appears “your connection is
successfully made” click ok otherwise you’ve made any error while creating connection.

Your connection is made successfully. Now click on that connection button.


After that, by writing the following piece of code, I used ‘testdb’ and created a table name
“customer”.

Now I have to insert the data. To insert the data, I used the query ‘INSERT INTO [table-
name]’ and ‘VALUES’ to insert values into the table. After that, I wrote a query, ‘SELECT *
FROM CUSTOMER’ to show all the data present in table. After all these queries, my table
looks like this.
Now here, I add another column of ‘ID_card’. The data to put in the ‘ID_card’ column will be
as integer. I used the query ‘ALTER TABLE [table name]’ to alter the table and add the
column as ‘ADD ID_card int’. After that, I added two customers’ data with ID_card using
‘INSERT INTO’ function.
After that, I write query to show the customer's name, ID_card, and his country. The query is
‘select CustomerName, ID_card, Country from CUSTOMER’. This query will only shows
the data of specific columns. You can see it as follow.

Using this query, I deleted the column “ID_card”. The query is “ALTER TABLE
CUSTOMER DROP COLUMN ID_card;”. You can clearly see in the following picture, the
ID_card column is deleted.
By using the query “TRUNICATE [table name]”, all the data in table has been deleted. You
can see it as follow:

By using a query “DROP TABLE [table name]”, this will delete the customer table as shown in
the following.
And at last, by using a query “DROP DATABASE testdb”, the database will be deleted.

You might also like