You are on page 1of 6

IM211:FUNDAMENTALS OF DATABASE SYSTEMS

Module #7

Name: _______________________________________________________________
Section: ____________ Date: ________________

Lesson title: Introduction to SQL Materials:


Lesson Objectives: Student Activity Sheet, MySQL
1. At the end of this module, I should be able to:
2. Explain the use of SQL in daily task in database operations References:
3. Describe all syntax used in SQL for DML, DDL, TCL and DCL https://www.guru99.com/relational-
data-model-dbms.html

MAIN LESSON

MySQL is one of the most popular relational database management systems. It is developed and maintained by the
Oracle Corporation. Other than Drupal, Joomla, and WordPress, MySQL is used by global brands like Facebook,
Flickr, Twitter, and YouTube.

What is SQL?

1. SQL stands for Structured Query Language, which is a standardized


language for interacting with RDBMS (Relational Database
Management System). Some of the popular relational database
example are: MySQL, Oracle, mariaDB, postgreSQL etc.
2. SQL is used to perform C.R.U.D (Create, Retrieve, Update & Delete)
operations on relational databases.
3. SQL can also perform administrative tasks on database such as
database security, backup, user management etc.
4. We can create databases and tables inside database using SQL

Types of Structured Query Language(SQL)

In the above section, we learned what we do with the database using SQL. SQL is basically combination of four
different languages, they are:
ü DQL (Data Query Language)
DQL is used to fetch the information from the database which is already stored there.
ü DDL (Data Definition Language)
DDL is used to define table schemas.
ü DCL (Data Control Language)
DCL is used for user & permission management. It controls the access to the database.
ü DML (Data Manipulation Language)
DML is used for inserting, updating and deleting data from the database.

What is a Query?
A Query is a set of instruction given to the database management system, which tells RDBMS what
information you would like to get from the database.
For e.g. to fetch the employee name from the database table EMPLOYEE, we write the SQL Query like this:

SELECT employee_name from EMPLOYEE;


DATA TYPES - Data types define the nature of the data that can be stored in a particular column of a table MySQL
has 3 main categories of data types namely:
IM211:FUNDAMENTALS OF DATABASE SYSTEMS
Module #7

Name: _______________________________________________________________
Section: ____________ Date: ________________

1.   Numeric - Numeric data types are used to store numeric values. It is very important to make sure range of
your data is between lower and upper boundaries of numeric data types

2.   Text - As data type category name implies these are used to store text values. Always make sure you
length of your textual data do not exceed maximum lengths.

3.   Date/time.

.
IM211:FUNDAMENTALS OF DATABASE SYSTEMS
Module #7

Name: _______________________________________________________________
Section: ____________ Date: ________________

List of Commands

DDL Commands DML Commands

Now that you differentiate the aspects of


communication ?. Let’s try a short activity to know how much you understand the our short introduction to our
lesson.

Activity 1: Skill-building Activities.

There you go! I’m expecting that you learn something today, I am excited to
hear your understanding with our lesson for today, Answer the following
question:

On this activity, you are going to follow the given instruction on how to access and create a database in MySQL and
MySQL Workbench.

The MySQL Create Database Statement


The CREATE DATABASE statement is used for creating a new database in the server. Its general syntax is:

CREATE DATABASE database_name


[CHARACTER SET charset_name]
[COLLATE collation_name]

You start a create database statement by specifying the database name. It must be unique within the MySQL server
instance. If you give a name to the database being created that has already been assigned to some other existing
database, then MySQL will generate an error.

It is possible to specify the character set as well as the collation for the new database at the creation time. However,
if you choose not to, then MySQL will use the default character and collation for the newly-created database.

Creating a MySQL Database Using:

(i) The MySQL Program


One way of creating a database in MySQL is using the mysql program and the CREATE DATABASE statement. For
creating a database in this manner, you need to:
IM211:FUNDAMENTALS OF DATABASE SYSTEMS
Module #7

Name: _______________________________________________________________
Section: ____________ Date: ________________

Step 1 - Log in to the MySQL as the root user. For this, use the following command:
>mysql -u root -p

Now, you will be prompted to enter the root user password, like this:
Enter password: _

Type the root user password and hit Enter


Step 2 - To check and ensure that you are not actually creating a database with a name that has already been
assigned to some other existing database in the MySQL server instance, you can use the SHOW DATABASES
command. It will return with all the database names that are currently in use

Step 3 - Now, use the CREATE DATABASE command for creating a new database in the MySQL server instance
as demonstrated below:
mysql> CREATE DATABASE database_name;
For reviewing the newly created database, you can use the SHOW CREATE DATABASE command:
mysql> SHOW CREATE DATABASE database_name;
It will return the database details along with the character set and collation for the same.
Step 4 - To access the newly created database, use the USE command, demonstrated as follows:
mysql> USE database_name;

Database changed
You can start creating tables, storing values, etc. in the newly created database from here on.

Download Mysql Community Server her : https://downloads.mysql.com/archives/community/

Here is the other options:

The MySQL Workbench


MySQL Workbench brings together SQL administration, development, database management, et cetera: all
accessible from a single access point. It is a great way for streamlining everything that you do with MySQL.

Obviously, you can also create a database in MySQL using the MySQL Workbench. However, in doing so, you don’t
need to use the CREATE DATABASE command. Instead, you will create a database graphically i.e. by entering
some details and doing a lot of clicking.

Here is the step-by-step procedure for creating a new database with the MySQL Workbench:

 Step 1 - Launch the MySQL Workbench and click on the Setup New Connection button (It is the one with
the ‘+ contained in a circle’ symbol)
 Step 2 - Enter name for the connection followed by clicking the Test Connection button
 Step 3 - You will now be prompted with a dialogue box, requesting the root password. Enter it, check the
Save password in vault checkbox (if not done already) and hit the Ok button
 Step 4 - Next, double-click the Local connection name in order to connect to the MySQL server instance.
Now you will be taken to the main MySQL Workbench window consisting 4 sections, namely Information,
Navigator, Output, and Query
 Step 5 - Click on the create a new schema in the connected server button present in the toolbar (In MySQL,
the schema is just another name for referring a database)
 Step 6 - A window will now pop up. Supply it with the schema name and change the character set and
collation settings, if needs be. Finally, click on the Apply button
IM211:FUNDAMENTALS OF DATABASE SYSTEMS
Module #7

Name: _______________________________________________________________
Section: ____________ Date: ________________

 Step 7 - Next, MySQL Workbench will open a window displaying the SQL script that will be executed. You
will notice a CREATE SCHEMA command here, which is equivalent to the CREATE DATABASE command.
As such, it is followed by the database name. To continue, click on the Apply button
 Step 8 - The newly created database will be reflected in the SCHEMAS tab present in the Navigator section
of the MySQL Workbench window
 Step 9 - To select the newly created database, right-click on it and select the Set as Default Schema option

Now, you are able to work with the newly created database via the MySQL Workbench. You can now add new
tables and data to the database from here or from the MySQL program as you find suitable.

Download here the MySQL Workbench - https://downloads.mysql.com/archives/workbench/

Create this database. :

CREATE TABLE IF NOT EXISTS `MyFlixDB`.`Members` (


`membership_number` INT AUTOINCREMENT ,
`full_names` VARCHAR(150) NOT NULL ,
`gender` VARCHAR(6) ,
`date_of_birth` DATE ,
`physical_address` VARCHAR(255) ,
`postal_address` VARCHAR(255) ,
`contact_number` VARCHAR(75) ,
`email` VARCHAR(255) ,
PRIMARY KEY (`membership_number`) )
ENGINE = InnoDB;
IM211:FUNDAMENTALS OF DATABASE SYSTEMS
Module #7

Name: _______________________________________________________________
Section: ____________ Date: ________________

Activity 1: Check for Understanding

Define the Following :

DQL (Data Query Language)

DDL (Data Definition Language)

DCL (Data Control Language)

DML (Data Manipulation Language)

What is a Query

Activity 2: Answer the following questions below.

1. What is Normalization in a Database?

You might also like