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