Which of the following restrictions must be applied while creating a view?
All views are not updatable. So, UPDATE command is not applicable to all views. An updatable view is one which allows performing a UPDATE command on itself without affecting any other table. Show
Contents: When can a view be updated?1. The view is defined based on one and only one table. 2. The view must include the PRIMARY KEY of the table based upon which the view has been created. 3. The view should not have any field made out of aggregate functions. 4. The view must not have any DISTINCT clause in its definition. 5. The view must not have any GROUP BY or HAVING clause in its definition. 6. The view must not have any SUBQUERIES in its definitions. 7. If the view you want to update is based upon another view, the later should be updatable. 8. Any of the selected output fields (of the view) must not use constants, strings or value expressions. Syntax: UPDATE < view_name > SET Parameters: NameDescriptionview_nameName of the virtual table or view where data will be modified.column1,column2Name of the columns of the table.value1,value2Values for the columns which are going to be updated.conditionCondition or criteria. Example: Sample view: agentview To update the view 'agentview' with following conditions - 1. 'commission' must be set at .13, 2. 'working_area' must be 'London', the following SQL statement can be used: SQL Code:
Output: To execute query on this view SQL Code:
SQL updatable viewsIn the following topic, we are discussing, how a view can be updated in a UPDATE VIEW statement. Example: Sample table: agents This statement bellow creates a updatable view 'countryagent': SQL Code:
To update the column 'commission' with the value .13 of the view 'countryagent', the following SQL statement can be used: SQL Code:
Output: To execute query on this view SQL Code:
SQL updatable views using in operatorIn the following topic we are going to discuss, how SQL IN operator can be used in a UPDATE VIEW statement to update the data of columns in a view. Example: Sample table: orders This statement bellow creates a updatable view 'orderindate': SQL Code:
To update the view 'orderindate' with following conditions - 1. 'advance_amount' set at 2000, 2. 'advance_amount' must be 1500, the following SQL statement can be used: SQL Code:
Output: To execute query on this view SQL Code:
SQL updatable views with aggregate functionHere in the following topics, we are discussing, that a view can not be updated (using a UPDATE VIEW statement) if any of the fields of the view is created by using either an AGGREGATE FUNCTION or a GROUP BY clause. Example: Sample table: orders This statement bellow creates a view 'daywiseorder': SQL Code:
To update the view 'daywiseorder' with following conditions - 1. 'ord_count' set at 2, 2. 'ord_count' must be 1, the following SQL statement can be used : SQL Code: 0Note: This view is a not an updatable view. The aggregate function 'COUNT' have been used in the definition of the view so this view is not updatable i.e. the 'view' is read only. To execute query on this view SQL Code: 1SQL update views with arithmetic expressionIn the following topics, we are discussing, that a view can not be updated (using a UPDATE VIEW statement) if any of the fields of the view is created by using an arithmetic expression. Example: Sample table: customer This statement bellow creates a view 'myclient': SQL Code: 2To update the view 'myclient' with following condition - 1. 'outspercent' set at 80, the following SQL statement can be used: SQL Code: 3Note: This view is a not an updatable view. Arithmetic expression has been used in the definition of the view. So this view is not updatable i.e. the 'view' is read only. To execute query on this view SQL Code: 4SQL update views using subqueriesIn this page, we are discussing, that a view can not be updated (using a UPDATE VIEW statement) if any of the fields of the view is created by using a subquery. Example: Sample table: orders Sample table: agents This statement bellow creates a view 'myagent': SQL Code: 5To update the view 'myagent' with following condition - 1. 'commission' set at .15, the following SQL statement can be used: SQL Code: 6See our Model Database Practice SQL Exercises
Want to improve the above article? Contribute your Notes/Comments/Examples through Disqus. Previous: Create view with join SQL: Tips of the DayEquals(=) vs. LIKE LIKE and = are different operators. Most answers here focus on the wildcard support, which is not the only difference between these operators! = is a comparison operator that operates on numbers and strings. When comparing strings, the comparison operator compares whole strings. LIKE is a string operator that compares character by character. To complicate matters, both operators use a collation which can have important effects on the result of the comparison. What are some of the limitations of view?Although there are many advantages to views, the main disadvantage to using views rather than real tables is performance degradation. Because views only create the appearance of a table, not a real table, the query processor must translate queries against the view into queries against the underlying source tables.
What are the restrictions that are put on update operations using a view?Updates through a view cannot specify an IDENTITY column value. Inserts to IDENTITY columns are restricted to: The table owner. The database owner or the system administrator, if the table owner has granted them permission.
Which of the following command is used to create view?The syntax for the CREATE VIEW statement in SQL is: CREATE VIEW view_name AS SELECT columns FROM tables [WHERE conditions]; view_name.
Which type of clause must be included in the CREATE VIEW statement?The CREATE VIEW statement requires the CREATE VIEW privilege for the view, and some privilege for each column selected by the SELECT statement. For columns used elsewhere in the SELECT statement, you must have the SELECT privilege. If the OR REPLACE clause is present, you must also have the DROP privilege for the view.
|