Chapter 7 similar to adding data directly to

Chapter 7 similar to adding data directly to a normal table. Therefore, you can still use the INSERT statement in the same way. After you ve created the view, you reference the view in an INSERT statement to add rows just as if you ve referenced a table in the INSERT statement. Adding data through a view is as easy as adding data to a regular table. However, you must adhere to a number of conditions. The most important of these conditions are the following: INSERT and UPDATE statements must modify only one of the underlying tables at a time. If you want to UPDATE data that resides in more than one table, you have to perform the UPDATE in two or more statements. Inserts against the underlying table must provide values for all NOT NULL columns, unless DEFAULT values are declared for those columns. Inserted data must conform to the view definition when WITH CHECK is specified on the view. If you are not sure whether your INSERT will be valid, you may want to use sp_helptext to check the SELECT statement that creates the view. A view is not a table, even though it an often be treated like one. If a view displays columns from only one table, then you do not have to worry about inserts and updates affecting more than one table. If, however, your view is used to consolidate data from many tables, you have to be careful when you UPDATE columns in more than one table. When you INSERT data through the view, you may find that the view actually makes the process difficult. For example, if you create the following view in the Pubs database: CREATE VIEW TitleAuthors AS SELECT dbo.Authors.au_id, dbo.Authors.au_lname, .dbo.Authors.au_fname, dbo.Authors.phone, .dbo.Authors.contract, dbo.Titles.title, .dbo.Titles.type FROM dbo.Authors INNER JOIN .dbo.TitleAuthor ON dbo.Authors.au_id = .dbo.TitleAuthor.au_id INNER JOIN .dbo.Titles ON dbo.TitleAuthor.title_id = dbo.Titles.title_id You can then add an author record with the following statement: WORKING WITH VIEWS 415

For high quality java hosting services please check tomcat web hosting website.

Comments are closed.