Docsity

CSIS 350 Lecture 24: MySQL CHECK Constraints, Views, and Database Programming, Study notes of Database Management Systems (DBMS)

Toggle sidebar
bg1
CSIS 350 โ€“ Lecture 24
Announcements
Chapter 7
Last time I told you that mySQL doesn't support CHECK constraints. However, there is a
work-around for one type of CHECK constraint โ€“ Say we have a column like this:
Country char(15) not null,
constraint countryValues CHECK
(Country in ('Canada', 'US', 'England')),
In mySQL, we can accomplish the same thing using an ENUM type:
Country ENUM('Canada', 'US', 'England'),
Views
A view is a 'virtual' or derived table.
- means that a view acts like a base table, but that no actual table exists.
- rows in a view don't exist until they are derived from base tables.
Why use views?
- Provide independence between application and database definition
- Simplify queries
- Security
oCan hide rows and columns from users
oCan set different permissions on views and tables
Creating views:
Use a CREATE VIEW statement:
CREATE VIEW <viewName> AS <Select statement>;
Restriction: Select statement cannot have ORDER BY clause.
I'm going to go over some examples โ€“ these are representative only โ€“ READ THE BOOK
for more examples!
Examples:
A simple view that includes only some of the columns from a table:
pf3
pf4
pf5

Partial preview of the text

Download CSIS 350 Lecture 24: MySQL CHECK Constraints, Views, and Database Programming and more Study notes Database Management Systems (DBMS) in PDF only on Docsity!

CSIS 350 โ€“ Lecture 24

Announcements Chapter 7 Last time I told you that mySQL doesn't support CHECK constraints. However, there is a work-around for one type of CHECK constraint โ€“ Say we have a column like this: Country char(15) not null, constraint countryValues CHECK (Country in ('Canada', 'US', 'England')), In mySQL, we can accomplish the same thing using an ENUM type: Country ENUM('Canada', 'US', 'England'), Views A view is a 'virtual' or derived table.

  • means that a view acts like a base table, but that no actual table exists.
  • rows in a view don't exist until they are derived from base tables. Why use views?
  • Provide independence between application and database definition
  • Simplify queries
  • Security o Can hide rows and columns from users o Can set different permissions on views and tables Creating views: Use a CREATE VIEW statement: CREATE VIEW AS