Docsity

View in Database - Database Design - Lecture Slides, Slides of Database Management Systems (DBMS)

Partial preview of the text

Download View in Database - Database Design - Lecture Slides and more Slides Database Management Systems (DBMS) in PDF only on Docsity!

SQL

• This presentation will cover:

  • A Brief History of DBMS

– View in database

– MySQL installation

SQL – DBMS History

• DBMS History

  • The IBM’s System/R was not the first DBMS. The first to market was Relational Software's product named Oracle
  • The second was Relational Technology's Ingres.
  • IBM then released improved products in 1982 named SQL/DS and DB2. Oracle and DB2 in nth generation forms while the Ingres technology was bought by Computer Associates.

SQL – Enhanced features

  • Every DBMS vendor wants their products to be different. So most products offers extra features, these additions are generally not compatible with competitor's SQL products.
  • It is always safest to stick with pure SQL
  • The enhancements are not all bad because these extensions are very useful. - For example, most DBMS sold today have an automatic way to assign a serial number feature since serial numbering is so common. However, the method of implementation is not uniform.

What is a View?

  • In SQL, a VIEW is a virtual relation based on the result-set of a SELECT statement.
  • A view contains rows and columns, just like a real table. The fields in a view are fields from one or more real tables in the database. In some cases, we can modify a view and present the data as if the data were coming from a single table.
  • Syntax :

CREATE VIEW view_name AS SELECT column_name(s) FROM table_name WHERE condition

SQL – Create View

  • Example: Create a view with title and year and made by Paramount studio.

Movie (title, year, length, inColor, studioName,

producerC#)

CREATE VIEW ParamountMovie AS

SELECT title,year

FROM Movie

WHERE studioName = ‘Paramount’;

SQL – Querying View

  • A view could be used from inside a query, a stored procedure, or from inside another view. By adding functions, joins, etc., to a view, it allows us to present exactly the data we want to the user.

SELECT title FROM ParamountMovie WHERE year = ‘1979’;

  • Have same result as

SELECT title FROM Movie WHERE studioName = ‘Paramount’ AND year = ‘1979’;

View

Table

SQL - Querying View example

Movie (title, year, length, inColor, studioName, producerC#) MovieExec (name, address, cert#, netWorth)

CREATE VIEW MovieProd AS SELECT title, name FROM Movie, MovieExec WHERE producerC# = cert#; SELECT name FROM MovieProd WHERE title = ‘Gone With the Wind’;

  • Same result as query from tables SELECT name FROM Movie, MovieExec WHERE producerC# = cert# AND title = ‘The War Of the World’;

SQL - Renaming Attributes in View

• Sometime, we might want to distinguish

attributes by giving the different name.

CREATE VIEW MovieProd (movieTitle, prodName) AS SELECT title, name FROM Movie, MovieExec WHERE producerC# = cert#;

SQL – Modifying View (INSERT)

INSERT INTO ParamountMovie VALUES (‘Star Trek’, 1979); To make the view ParamountMovie updateable, we need to add attribute studioName to it’s SELECT clause because it makes more sense if the studioName is Paramount instead of NULL.

CREATE VIEW ParamountMovie AS SELECT studioName, title, year FROM Movie WHERE studioName = ‘Paramount’; Then INSERT INTO ParamountMovie VALUES (‘Paramount’, ‘Star Trek’, 1979);

Title year length inColor studioName producerC# ‘Star Trek’ 1979 0 NULL ‘Paramount’ NULL

SQL - Modifying View (DELETE)

  • Suppose we wish to delete all movies with “Trek” in

their title from the updateable view

ParamountMovie.

DELETE FROM ParamountMovie WHERE title LIKE ‘%Trek%’;

It is turned into the base table delete

DELETE FROM Movie WHERE title LIKE ‘%Trek%’ AND studioName = ‘Paramount’;

SQL – View (DROP)

  • DROP view: All views can be dropped, whether or not the view is updateable.

DROP VIEW ParamountMovie;

  • DROP VIEW does not affect any tuples of the underlying relation (table) Movie.
  • However, DROP TABLE will delete the table and also make the view ParamountMovie unusable.

DROP TABLE Movie

SQL - D ownload MySQL

  • Go to http://dev.mysql.com/downloads/ and

download:

 MySQL (Windows User / version 4.1.10a, 5.0.2-

alpha has bug that keep shutting down the service)

 MySQL Administrator

 MySQL Query Browser

SQL - MySQL Administrator

  • MySQL Administrator come with MySQL System

Tray Monitor allow you to configure your server

  • Run MySQL Administrator –
    • For the first time, you may not have “Stored

connection,” you can and

give the Connection name.

  • Server Host: type “localhost” If you don’t use

networking

SQL - MySQL Query Browser

  • Run MySQL Query Browser
    • Give a name for the Default Schema
      • Schema means Database instance
    • You can type command line into the top box or

right Click on schemata to create new table