Download mysql> show tables

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Entity–attribute–value model wikipedia , lookup

Database wikipedia , lookup

Extensible Storage Engine wikipedia , lookup

Microsoft Jet Database Engine wikipedia , lookup

Microsoft SQL Server wikipedia , lookup

Open Database Connectivity wikipedia , lookup

Clusterpoint wikipedia , lookup

Relational model wikipedia , lookup

SQL wikipedia , lookup

Database model wikipedia , lookup

PL/SQL wikipedia , lookup

Transcript
Lab 7
Why Views are useful!
Backgound
The following information is located at this link.
http://www.w3schools.com/sql/sql_view.asp
What is a View?
In SQL, a VIEW is a virtual table 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. You can add SQL functions, WHERE, and JOIN statements to a view and present the
data as if the data were coming from a single table.
Note: The database design and structure will NOT be affected by the functions, where, or join statements in a
view.
Syntax
CREATE VIEW view_name AS
SELECT column_name(s)
FROM table_name
WHERE condition
Note: The database does not store the view data! The database engine recreates the data, using the view's
SELECT statement, every time a user queries a view
Using Views
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 you to present exactly the data you want to the user.
What to Do.
Open a logfile called Lab07 and run queries to illustrate that your views work.
Use the command line to create the following views on your students courses and grades database. (you can use
the GUI to create it and then copy and paste it to the command line.)
The user ‘bob’ that you created in the last activity should be given permission to see these views and these views
only.
1. Create a view called “gradesonly” which shows only the following:
student first name
student last name
course codes
course description
grade for all students.
2. Create a view called “gradeswithHWD101” which shows only the following:
student first name
student last name
course codes
course description
grade
for all students and all the courses that they have taken but only if they have taken HWD101 and order them by
student last name.
3.
Create a view called “highestHWD101”
Which shows only the following:
Course code
Course description
Highest grade
4.
Create a view called “studenthighgradeHWD101”
Which shows only the following:
Student firstname
Student lastname
Course code
Grade
Run the appropriate Select statements to show these view tables.
Close your log file.
Add to your log file a screen shot of the permissions you gave to ‘bob’ in SQLyog.
Can you figure out how to show the permissions from the command line in SQL?
Attach your log file to an e-mail and submit as Lab 7