0% found this document useful (0 votes)
12 views7 pages

CSE 210 Lab 01

Database and PL/SQL in MySQL

Uploaded by

RAKIBUL ISLAM
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views7 pages

CSE 210 Lab 01

Database and PL/SQL in MySQL

Uploaded by

RAKIBUL ISLAM
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Department of

Computer Science and Engineering

Title: Introduction to Database and PL/SQL in


MySQL

Databse System Lab


CSE 210

Green University of Bangladesh


1 Objective(s)
• To install MySQL Database Server.
• To introduce Data Types used in Database System.
• PL/SQL lets you write code once and deploy it in the database nearest the data.
• PL/SQL can simplify application development, optimize execution, and improve resource utilization in
the database.

2 Problem analysis
Database is a key course of computer science. At the beginner level, most of the students are not familiar with
how to use database in computer system. This section helps you get started with a very common database
system named MySQL. We will start installing MySQL, and creating a database in the MySQL server for
practicing.
PL/SQL was developed by modeling concepts of structured programming, static data typing, modularity,
exception management, and parallel (concurrent) processing found in the Ada programming language. The Ada
programming language, developed for the United States Department of Defense, was designed to support military
real-time and safety-critical embedded systems, such as those in airplanes and missiles. The Ada programming
language borrowed significant syntax from the Pascal programming language, including the assignment and
comparison operators and the single-quote delimiters.

3 Procedure
If you want to install MySQL on Windows environment, using MySQL installer is the easiest way. MySQL
installer provides you with an easy-to-use wizard that helps you to install MySQL with the following components:
• MySQL Server
• All Available Connectors

• MySQL Workbench with Sample Data Models


• MySQL Notifier
• Tools for Excel and Microsoft Visual Studio

• MySQL Sample Databases


To download MySQL installer, following link

https://www.apachefriends.org/download.html

Required toll are available for all operating systems in the above link.

After installation of the downloaded XAMPP, you have to run the XAMPP control panel system. It will
be like the Figure 2.
To start the service, you have to press the Start button of the Apache and MySQL module. Now, the system
is ready to work with.

3.1 Block
PL/SQL is a blocked programming language. Program units can be named or unnamed blocks. Unnamed
blocks are known as anonymous blocks and are labeled so throughout the book. The PL/SQL coding style
differs from that of the C, C++, and Java programming languages. For example, curly braces do not delimit
blocks in PL/SQL.
Anonymous-block programs are effective in some situations. You typically use anonymous blocks when
building scripts to seed data or perform one-time processing activities.They are also effective when you want to

© Dept. of Computer Science and Engineering, GUB


Figure 1: XAMPP Control Panel

nest activity in another PL/SQL blocks execution section. The basic anonymous-block structure must contain
an execution section.
You can also put optional declaration and exception sections in anonymous blocks. The following illustrates
an anonymous-block prototype:

4 Implementations
4.1 Practicing With XAMPP
To start the practice session, you have to press the Admin button of MySQL module or you have to use the
following link in your web browser: http://localhost/phpmyadmin/

You will get a web page like Figure 3 in your tab. Now, to create a database, you have to select the New
option in phpMyAdmin panel (Upper most option in the left side of the web page). Then, you have to input
a name in the Database name field as your wish and press the Create button. After that, to input data in
your required structure, you have to create table with table name and required number of column. For this,
you have to open SQL option and write necessary syntax.

4.2 Database Creation


To crate a database, we have to write command like " CREATE DATABASE [Database_Name]". Suppose, we
have to create a database named "lab2". We have to write the command as below:

1 [DECLARE]
2 declaration_statements
3 BEGIN
4 execution_statements
5 [EXCEPTION]
6 exception_handling_statements
7 END;
8 /
9 Lets write out first block that will do nothing:
10

© Dept. of Computer Science and Engineering, GUB


Figure 2: Session in Localhost

11 BEGIN
12 NULL;
13 END;
14 /

A databased named "lab2" is created in your local-host.

4.3 Database Use


To use the "lab2" database, we have to write the command in SQL editor space as bellow:

USE lab2

4.4 Table Creation


Now, to create a table named "Student" in database lab2 with attributes like StudentID (int), LastName
(varchar), FirstName (varchar), Address (varchar), City (varchar), we have to write command in SQL
editor space like below:

CREATE TABLE Student(StudentID int, LastName varchar(20), FirstName varchar(20), Address var-
char(50), City varchar(20));

4.5 Table Description


To describe the table structure, we have to write command like "DESCRIBE [Table_Name]". Suppose, we
want to describe Student table. So, we have to write command in SQL editor space as bellow:

DESCRIBE student;

We will get table like figure 3 on the browser tab.

The Student table is ready to insert data.

© Dept. of Computer Science and Engineering, GUB


Figure 3: Description of Student Table

4.6 Data Insertion


To insert data in the table, we have to write proper SQL command on the SQL editor space. Suppose, we want
to insert a student details in Student table like StudentID: 1001, LastName: Das, FirstName: Utsha,
Address: 704, Shamim Shoroni, West Shewrapara, City: Dhaka, we have to write command as bellow:

INSERT INTO ‘student‘ (‘StudentID‘, ‘LastName‘, ‘FirstName‘, ‘Address‘, ‘City‘) VALUES (’1001’,
’Das’, ’Utsha’, ’704, Shamim Shoroni, West Shewrapara’, ’Dhaka’);
We also want to insert an another student details in Student table like StudentID: 1002, LastName:
Hasan, FirstName: Md. Mehedi, Address: 102, Shapla Shoroni, West Shewrapara, City: Dhaka,
we have to write command as bellow:

INSERT INTO ‘student‘ (‘StudentID‘, ‘LastName‘, ‘FirstName‘, ‘Address‘, ‘City‘) VALUES (’1002’,
’Hasan’, ’Md. Mehedi’, ’102, Shapla Shoroni, West Shewrapara’, ’Dhaka’);
In this way, we can insert many student details in the Student table.

4.7 Data Browse


To browse the Student table, we have to write command as bellow:

SELECT * FROM ‘student‘;

A table will be appeared on the tab like figure 4.

Figure 4: Browsing Result of Student Table

4.8 Dropping Table and Database


To drop a table, we have to write command like "DROP TABLE [Table_Name]". Suppose, we want to drop
the Student Table, SQL command will be as bellow:

© Dept. of Computer Science and Engineering, GUB


Table 1: Basic Data Types
Data Type Description
CHAR(size) Holds a fixed length string (can contain letters, numbers, and special characters). The fixed size is specified in parenthesis. Can store up to 255 characters
VARCHAR(size) Holds a variable length string (can contain letters, numbers, and special characters). The maximum size is specified in parenthesis. Can store up to 255 characters. Note: If you put a greater value than 255 it will be converted to a TEXT type
TINYTEXT Holds a string with a maximum length of 255 characters
TEXT Holds a string with a maximum length of 65,535 characters
TINYINT(size) -128 to 127 normal. 0 to 255 UNSIGNED*. The maximum number of digits may be specified in parenthesis
SMALLINT(size) -32768 to 32767 normal. 0 to 65535 UNSIGNED*. The maximum number of digits may be specified in parenthesis
MEDIUMINT(size) -8388608 to 8388607 normal. 0 to 16777215 UNSIGNED*. The maximum number of digits may be specified in parenthesis
INT(size) -2147483648 to 2147483647 normal. 0 to 4294967295 UNSIGNED*. The maximum number of digits may be specified in parenthesis
BIGINT(size) -9223372036854775808 to 9223372036854775807 normal. 0 to 18446744073709551615 UNSIGNED*. The maximum number of digits may be specified in parenthesis
FLOAT(size,d) A small number with a floating decimal point. The maximum number of digits may be specified in the size parameter. The maximum number of digits to the right of the decimal point is specified in the d parameter
DOUBLE(size,d) A large number with a floating decimal point. The maximum number of digits may be specified in the size parameter. The maximum number of digits to the right of the decimal point is specified in the d parameter
DECIMAL(size,d) A DOUBLE stored as a string, allowing for a fixed decimal point. The maximum number of digits may be specified in the size parameter. The maximum number of digits to the right of the decimal point is specified in the d parameter
DATE() A date. Format: YYYY-MM-DD Note: The supported range is from ’1000-01-01’ to ’9999-12-31’
DATETIME() *A date and time combination. Format: YYYY-MM-DD HH:MI:SS Note: The supported range is from ’1000-01-01 00:00:00’ to ’9999-12-31 23:59:59’
TIMESTAMP() *A timestamp. TIMESTAMP values are stored as the number of seconds since the Unix epoch (’1970-01-01 00:00:00’ UTC). Format: YYYY-MM-DD HH:MI:SS Note: The supported range is from ’1970-01-01 00:00:01’ UTC to ’2038-01-09 03:14:07’ UTC
TIME() A time. Format: HH:MI:SS Note: The supported range is from ’-838:59:59’ to ’838:59:59’
YEAR() A year in two-digit or four-digit format. Note: Values allowed in four-digit format: 1901 to 2155. Values allowed in two-digit format: 70 to 69, representing years from 1970 to 2069

DROP TABLE student;

Student table will be removed from lab2 database.


To drop the lab2 database, we have to write command as bellow:

DROP DATABASE lab2;

5 Discussion & Conclusion


In this example, I have used varchar as data type for all the attributes. Numbers indicates the length of that
specific attribute. Besides varchar, there many types of data type which is described in the Table 1.
In this lab, We have installed a MySQL in our computer and created a database with a table. We have also
known the basic data types used in database and inserted data in the table and browsed the table. Finally, we
have dropped the table as well as the database. That’s meant, we have achieved our lab objectives.

6 Lab Task (Please implement yourself and show the output to the
instructor)
1. Create a database named "University"
2. Create a Table named "Teacher" with attributes named TeacherID, Name, Designation, Address, and
Email.

3. Create a Table named "Student" with attributes named StudentID, Name, Address, and Phone.
4. Insert at least five entities in each table.
5. Drop each table of the database.

6.1 Problem analysis


1. You have to create a database named "University" with the help of create option provided in pypMyAdmin
panel.

2. You have to create a table named "Teacher" with attributes named TeacherID, Name, Designation, Ad-
dress, and Email. You must use proper data type and size.
3. You have to create a table named "Student" with attributes named StudentID, Name, Address, and
Phone. You must use proper data type and size.
4. You have to insert at least five tuples both in Student and Teacher table.

5. You have to drop the tables.

© Dept. of Computer Science and Engineering, GUB


7 Lab Exercise (Submit as a report)
• Create a Database with five tables.
• Insert five to ten tuples in each table.
• Browse each table and take a snapshot.

8 Policy
Copying from internet, classmate, seniors, or from any other source is strongly prohibited. 100% marks will be
deducted if any such copying is detected.

© Dept. of Computer Science and Engineering, GUB

You might also like