Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Views

Author  Topic 

petek
Posting Yak Master

192 Posts

Posted - 2008-10-24 : 10:55:11
Hi all,

If i create a view of a table is it possible to use the view to change data in the source table??

Kind Regards

Pete.

petek
Posting Yak Master

192 Posts

Posted - 2008-10-24 : 10:58:00
further to this can i call the view from query analyser and run an update statement against it??

Kind Regards

Pete.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-24 : 10:59:32
Yup. you can have updatable views. But not all views are updatable. There are some condition that view must follow for it to become updatable like no use of GROUPING or DISTINCT, JOIN,... The full conditions can be found below

http://doc.ddart.net/mssql/sql70/create_9.htm
Go to Top of Page

Lumbago
Norsk Yak Master

3271 Posts

Posted - 2008-10-24 : 11:02:08
There are quite a few conditions, but in general the answer is yes. Look up the "Updatable views" section in the article CREATE VIEW in Books Online

- Lumbago
Go to Top of Page

petek
Posting Yak Master

192 Posts

Posted - 2008-10-24 : 11:02:22
thanks Visahk16.....I created my view and called the view to update another table it works. thanks

Kind Regards

Pete.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-24 : 11:03:10
quote:
Originally posted by petek

thanks Visahk16.....I created my view and called the view to update another table it works. thanks

Kind Regards

Pete.


Cheers
Go to Top of Page

NeilG
Aged Yak Warrior

530 Posts

Posted - 2008-10-24 : 11:12:32
One tip it to alway check the underlying table for Not Null columns as these will throw back an error if not included in the view select list when updateing through the view

Go to Top of Page

cr8nk
Yak Posting Veteran

77 Posts

Posted - 2008-10-25 : 00:24:39
Using instead of triggers on the view also give you more flexibility into updating data from a view. Even though I am not a big fan of using them.
Go to Top of Page
   

- Advertisement -