3.8 View Flashcards

(48 cards)

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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
Why is the `WITH CHECK OPTION` useful?
It ensures data integrity by *preventing inserts or updates* that would make data invisible to the view.
26
Can you delete data directly from a view?
Generally, deletes are restricted from views due to potential ambiguity *in corresponding changes to base tables*.
27
How are views utilized to maintain *data consistency*?
By allowing *only controlled access to data* via the view, thus ensuring data access patterns don’t violate **business rules**.
28
What is the `WITH CHEAK OPTION` clause?
``` CREATE VIEW ViewName [ ( Column1, Column2, ... ) ] AS SelectStatement [WITH CHECK OPTION] ; ``` ## Footnote Disregard the brackets for the With CHEAK opt [📖](https://app.milanote.com/1TqbXz1f69yoeE?p=N4oXWlErVzz)
29
Why would adding to `SalesEmployee` fail? 1. ID: 8520 1. Name: Jiho Chen 1. Department: 80
The new employee is inserted into `Employee` but is not in department 51 and therefore does not appear in the view table.
30
Write a statement to prevent inserts and updates which wouldn't satisfy the view query `WHERE` clause.
``` CREATE VIEW SalesEmployee (ID, Name, Department) AS SELECT * FROM Employee WHERE DepartmentCode = 51 WITH CHEAK OPTION; ```
31
What is a standard view?
A standard view is essentially a saved SELECT query that acts as a virtual table. The query is executed every time the view is accessed. ## Footnote Standard views are ideal for real-time data retrieval.
32
What is a materialized view?
A materialized view stores the result set of the query as a physical table in the database. ## Footnote Materialized views are useful for improving performance in complex queries and aggregations.
33
When should you use standard views?
Use standard views when you need real-time data and do not want to store redundant data. ## Footnote They are good for simple queries or when the data changes frequently.
34
When should you use materialized views?
Use materialized views when performance is critical, the underlying data doesn't change too frequently, and you can tolerate some latency in the data being displayed. ## Footnote They are suitable for complex queries, aggregations, and reporting.
35
True or False: A standard view stores data as a physical table.
False ## Footnote Standard views do not store data; they execute the query each time they are accessed.
36
Fill in the blank: A materialized view is similar to a standard view, but it _______.
stores the result set of the query as a physical table in the database. ## Footnote This allows for faster data retrieval compared to standard views.
37
What is a materialized view?
A materialized view stores the result set of a query as a physical table.
38
How does a materialized view differ from a regular view?
A materialized view holds pre-computed results, while a regular view executes its underlying query every time it is accessed.
39
What is a key advantage of using materialized views?
Significantly speeds up query performance.
40
What issue can arise with materialized views due to pre-computation?
The data can become stale as the underlying data changes.
41
What must be done to maintain data consistency in materialized views?
The materialized view must be periodically refreshed.
42
True or False: Users of a materialized view must always provide search terms.
False.
43
What is not a general restriction for materialized views regarding user input?
Users interacting with the view don't necessarily have to provide search terms.
44
Are indexes required for the tables referenced in a materialized view?
No, indexes are not a strict requirement.
45
What can improve the performance of the initial creation and refresh of a materialized view?
Indexes can improve performance.
46
Is compression a requirement for using materialized views?
No, compression is not inherently tied to the use of materialized views.
47
Fill in the blank: A materialized view must be _______ to reflect the latest data in the base tables.
refreshed.
48
What technique can be used to optimize storage in relation to materialized views?
Compression.