View with check option : View « View « SQL Server / T-SQL Tutorial

Home
SQL Server / T-SQL Tutorial
1.Query
2.Insert Delete Update
3.Table
4.Table Join
5.Data Types
6.Set Operations
7.Constraints
8.Subquery
9.Aggregate Functions
10.Date Functions
11.Math Functions
12.String Functions
13.Data Convert Functions
14.Analytical Functions
15.Sequence Indentity
16.View
17.Index
18.Cursor
19.Database
20.Transact SQL
21.Procedure Function
22.Trigger
23.Transaction
24.XML
25.System Functions
26.System Settings
27.System Tables Views
28.User Role
29.CLR
SQL Server / T-SQL Tutorial » View » View 
16.1.5.View with check option
5CREATE TABLE Shippers (
6>      ShipperID int NOT NULL ,
7>      CompanyName nvarchar (40NOT NULL ,
8>      Phone nvarchar (24NULL
9)
10> GO
1>
2>
3INSERT Shippers VALUES(1,'Express','(503555-9831')
4INSERT Shippers VALUES(2,'Package','(503555-3199')
5INSERT Shippers VALUES(3,'Shipping','(503555-9931')
6> go

(rows affected)

(rows affected)

(rows affected)
1>
2>    CREATE VIEW OregonShippers_vw
3>    AS
4>    SELECT   ShipperID,
5>             CompanyName,
6>             Phone
7>    FROM     Shippers
8>    WHERE Phone LIKE '(503)%'
9>    WITH CHECK OPTION
10> GO
1>
2>
3>
4>    UPDATE OregonShippers_vw
5>    SET Phone = '(333555 9831'
6>    WHERE ShipperID = 1
7> GO
Msg 550, Level 16, State 1, Server J\SQLEXPRESS, Line 4
The attempted insert or update failed because the target view either specifies WITH CHECK OPTION or spans a view that specifies WITH CHECK OPTION and one or more rows resulting from the operation did
not qualify under the CHECK OPTION constraint.
The statement has been terminated.
1> drop view OregonShippers_vw;
2> GO
1>
2> drop table Shippers;
3> GO
16.1.View
16.1.1.VIEWS ARE STORED named SELECT statements.
16.1.2.View creation syntax
16.1.3.A view is a SELECT statement that's stored with the database.
16.1.4.Create and query a view
16.1.5.View with check option
16.1.6.Join syscomments and sysobjects to query a view
16.1.7.Create a view to wrap a long sql statement
16.1.8.Setting Permissions on a View
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.