3.8 View Flashcards

1
Q

Refer to the following CREATE VIEW statement and view table.

A

The name of the view table immediately follows the CREATE VIEW keywords.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Refer to the following CREATE VIEW statement and view table.

A

FacultyName AS Professor in the view query indicates that Professor replaces FacultyName in the view table.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Refer to the following CREATE VIEW statement and view table.

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is a view table in database management?

A

A view table is a virtual table created by a SELECT statement that does not store data permanently but presents data from one or more tables like a regular table.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How do views help optimize database design for users?

A
  • Views can combine and restructure data from multiple tables without altering the underlying database design.
  • It’s easier for users to access and understand complex datasets.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the function of a materialized view?

A
  1. It can improve performance by providing fast access to pre-computed data.
  2. A materialized view stores the result of a view query.

must be refreshed when the base table data changes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the primary advantage of using views to manage sensitive data?

A

Views can exclude sensitive columns, such as salary data, thereby providing access to only the necessary information for specific users or applications.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Why might view tables not allow insert, update, or delete operations?

A

Operations on view tables may not map cleanly to underlying base tables, leading to undefined or problematic data updates, particularly with primary keys and aggregates.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the purpose of the WITH CHECK OPTION clause in view creation?

A

It ensures that any INSERT or UPDATE operations on the view; meet the conditions specified in the view query’s WHERE clause, preventing changes that would render the data invisible in the view.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

In a view created with a join, what are the tables in the FROM clause referred as?

A

They are known as base tables, which are the source tables from which the view draws its data.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What are the advantages of saving complex queries as views?

A

Views can encapsulate complex queries, saving time for users who need to run those queries repeatedly without having to write them out each time.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How is database performance related to using views?

A
  • Using views designed with optimal queries can enhance performance because they allow for pre-optimized query execution.
  • The performance of a query on a view may vary from a direct query on base tables.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What does the CREATE VIEW statement do?

A

It creates a new view by specifying the view’s name, columns, and the SELECT statement that defines it.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Why might users prefer a view that joins tables, like Employee and Address?

A
  1. A view can present combined data in a single table format
  2. Views simply data access for users who need information from both tables.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What happens when a view is queried in SQL?

A

The database processes the view’s SELECT statement along with the user query, treating it as a single combined query against the base tables.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Can views improve query security and why?

A

Yes, by allowing access to specific data while keeping other data, possibly sensitive, hidden from the user.

17
Q

How do views assist in simplifying complex database queries?

A

They encapsulate complex logic within a SELECT statement, allowing users to query the view directly without understanding the details.

18
Q

What restriction applies to views when performing an INSERT operation?

A

An insert may be problematic for a view if:

  1. It the insert doesn’t include necessary primary keys
  2. Attempts to insert into aggregated columns.
19
Q

Can a view be defined based on other views?

A

Yes, a view can be built using other views, though they are not considered base tables.

20
Q

Describe how a view and a base table differ in data storage.

A
  • Views do not store data; they only describe a way to retrieve data from base tables
  • Base tables physically store data.
21
Q

What is a join view?

SELECT DepartmentName, EmployeeName 
FROM Department 
INNER JOIN Employee ON DepartmentID = Employee.DepartmentID
A

A join view involves combining data from two tables

22
Q

What role does a view play in data abstraction?

A

Views abstract away complex queries and database structures, presenting a simplified data interface to users.

To abstract (away), specifically in computer science, refers to intentionally obscuring the details of how something works in order to simplify.

23
Q

How often must materialized views be refreshed?

A

They must be refreshed whenever the base table data changes, to ensure accuracy.

24
Q

Why might databases disallow certain data modifications through views?

A

Because the modification might not map correctly back to the base tables, creating ambiguity or undefined behavior.

25
Q

Why is the WITH CHECK OPTION useful?

A

It ensures data integrity by preventing inserts or updates that would make data invisible to the view.

26
Q

Can you delete data directly from a view?

A

Generally, deletes are restricted from views due to potential ambiguity in corresponding changes to base tables.

27
Q

How are views utilized to maintain data consistency?

A

By allowing only controlled access to data via the view, thus ensuring data access patterns don’t violate business rules.

28
Q

What is the WITH CHEAK OPTION clause?

A
CREATE VIEW ViewName [ ( Column1, Column2, ... ) ]
AS SelectStatement
[WITH CHECK OPTION] ;

Disregard the brackets for the With CHEAK opt

29
Q

Why would adding to SalesEmployee fail?
1. ID: 8520
1. Name: Jiho Chen
1. Department: 80

A

The new employee is inserted into Employee but is not in department 51 and therefore does not appear in the view table.

30
Q

Write a statement to prevent inserts and updates which wouldn’t satisfy the view query WHERE clause.

A
CREATE VIEW SalesEmployee (ID, Name, Department)
AS SELECT *
    FROM Employee
    WHERE DepartmentCode = 51
WITH CHEAK OPTION;