0% found this document useful (0 votes)
44 views15 pages

Lab 2

This document outlines steps for creating a database and tables in MySQL Workbench, loading data into the tables, and using SQL commands to retrieve and manipulate data from the tables. It includes instructions for creating a database called "cisb314", importing a table called "Pet" from an external source, and selecting the database for use. It also provides examples of SQL queries to select all data, filter rows by certain criteria, select specific columns, sort rows, perform pattern matching, and count rows.

Uploaded by

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

Lab 2

This document outlines steps for creating a database and tables in MySQL Workbench, loading data into the tables, and using SQL commands to retrieve and manipulate data from the tables. It includes instructions for creating a database called "cisb314", importing a table called "Pet" from an external source, and selecting the database for use. It also provides examples of SQL queries to select all data, filter rows by certain criteria, select specific columns, sort rows, perform pattern matching, and count rows.

Uploaded by

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

Database

Implementation
LAB 2
Outline
Create Create database

Create Create tables

Load Load into tables

Manipulate Manipulate data


Create database schema cisb314
Create database
Create Table
Import table Pet
Download table Pet from Moodle.

In MySQL workbench, click on Table Data Import Wizard.


Click Next until import data is completed.
Import table
Use statement
To select a database to be used (as current database), use the following command: use
xxxx;

Note: a database is created only once, but you need to select it every time you want to use
the database.
Retrieving Information from a
Table (SQL exercise)
Selecting All Data
Selecting Particular Rows
Selecting Particular Columns
Sorting Rows
Pattern Matching
Counting Rows
Retrieving Information from a
Table
Selecting All Data

Mysql> select * from pet;


Retrieving Information from a
Table
Selecting Particular Rows
◦ Display the records for owner Gwen.
◦ Display the animals that were born during or after 2014
◦ Display records for female dogs.
◦ Display records for snake and bird.
◦ Display records for male cat and female dog.
Retrieving Information from a
Table
Selecting Particular Columns
◦ Display columns name and birth.
◦ Display the pets’ owners.
◦ Display pets’ owner only once.
◦ Display name, species and birth for dogs and cats only.

Sorting rows
◦ Display columns name and birth sorted by birthdate in ascending order.
Retrieving Information from a
Table
Pattern Matching
◦ Display records for name begins with letter ‘B’.
◦ Display records for name ends with letter ‘y’.
◦ Display records for name contains letter ‘a’.
◦ Display records for name contains exactly 5 characters.
Retrieving Information from a
Table
Counting Rows
◦ Count the number of animals.
◦ Count how many pets each owner has.
◦ Count the number of animals per species.
END

You might also like