|
|
|
Say Hey Kid
      
Group: General Forum Members
Last Login: 2 days ago @ 8:40 AM
Points: 703,
Visits: 1,032
|
|
| Thanks for the question. Got one option right, the other wrong so I have learnt something today. Thanks for this and as always for the discussion.
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Tuesday, May 28, 2013 1:34 AM
Points: 1,263,
Visits: 1,080
|
|
Neela Khatri (3/12/2012) ... In the options available to be checked, results was spelled wrong twice ...
And I thought this was to help find the correct answers  Check it out--the two options where it reads resutls are the correct ones.
Cheers, Michael
|
|
|
|
|
SSC-Addicted
      
Group: General Forum Members
Last Login: Wednesday, June 12, 2013 8:52 AM
Points: 469,
Visits: 199
|
|
| Simple yet important concept on views where multiple tables are involved regardless of indexes, primary or foreign keys. Thanks for the question.
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Yesterday @ 12:10 PM
Points: 7,185,
Visits: 7,285
|
|
I don't say it's a bad question because it's obvious what answer is intended, and the intended answer for the first view is right whenever the view is an updateable one, which most views whose columns are columns of a single underlying table are, and the intended answer for the second view is right whenever that view doesn't have an "instead of delete" trigger. It will probably make people think and/or consult BoL and learn something, and perhaps at least learn to be careful about deleting through views, so it's far more good than bad.
But it's not really good because the real answer about delete from each view is "it depends".
The question doesn't specify that the first view is an updateable view. Just create a trivial view with with select distinct (so that it is not an updatabale view) and straight away any attempt to delete a row using this view will fail with an error. Since it's made "with columns in table one" some of the ways of making an non-updateable table are ruled out but certainly using "distinct" isn't and neither is anything involving both TOP and the WITH CHECK OPTION. It isn't even clear that a view where a column is constructed from columns (plural) of the underlying table rather than from a single column of the underlying table is ruled out by the wording of the question (try having a column made by adding two columns of the underlying table, and once again it won't work), and it's certainly triue for example that an aggregates like MAX(col_x) is make from column col_x so the wording doesn't rule out the use of aggregates (and aggregates make the view non-updateable). It depends on teh view definition of the first view.
fr teh second view, although the question specifies that neither table has any trigger it doesn't specify that the views don't have triggers - so the second view could perfectly well have an "instead of delete" trigger that did something sensible, so no error message. It depends on whether a suitable trigger exists for the second view.
Tom Is minic a gheibheann béal oscailte dorn dúnta. Is minig a cheapas beul fosgailte dòrn dùinte.
http://es.linkedin.com/in/tomthomsonsoftware
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Yesterday @ 12:10 PM
Points: 7,185,
Visits: 7,285
|
|
Another thing that people should be cautious about when deleting a single row in a view: if the view is updateable (so that you can delete without an instead of trigger), has no trigger, and has duplicate rows and the (single) underlying table doesn't (so it's a view that doesn't include the whole of the primary key of the underlying table) and you ensure deleting a single row in the view by using "delete top (1) ...." it will delete one of the rows in the underlying table. Since the underlying table doesn't have any duplicates, it makes sense to ask "which row" for the underlying table (it doesn't make sense to ask that for the view, because in the view you can't distinguish between the duplicate rows). The only way you can find out is to suck it and see.
Tom Is minic a gheibheann béal oscailte dorn dúnta. Is minig a cheapas beul fosgailte dòrn dùinte.
http://es.linkedin.com/in/tomthomsonsoftware
|
|
|
|
|
Mr or Mrs. 500
      
Group: General Forum Members
Last Login: Tuesday, April 02, 2013 8:28 PM
Points: 555,
Visits: 2,137
|
|
Hugo Kornelis (3/12/2012) ... And if the view includes the WITH CHECK option, those people would also be unable to change active members to non-active members. I am not sure to understand perfectly the WITH CHECK option. From microsoft, I found that "WITH CHECK option" is: "Forces all data modification statements that are executed against the view to follow the criteria set within select_statement." So, If I understand well, all column from the view are protected against updates, but you can delete any row from the view (if it does not have reference constraint) or insert a new row ( if the view covers all "not null" columns). Is that it? That could be neet...
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 2:28 AM
Points: 5,299,
Visits: 7,242
|
|
tilew-948340 (3/12/2012) I am not sure to understand perfectly the WITH CHECK option. Put simply, WITH CHECK means that rows that are inserted or updated through the view must still satisfy the view's predicate. In other words, if you do an insert or update through the view and then a select immediately after it, you should see the updated or inserted row.
Example:
CREATE VIEW SalesPpl AS SELECT EmpNo, Name, Salary, Department FROM Personnel WHERE Department IN ('Sales', 'SalesBackOffice'); The view above allows people to add personnel into the Marketing department, or to update a row to transfer someone from Sales to Accounting. The WITH CHECK option prevents that, while still allowing users to update a row to transfer people between Sales and SalesBackOffice.
Hugo Kornelis, SQL Server MVP Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
|
|
|
|
|
SSCoach
         
Group: General Forum Members
Last Login: Yesterday @ 3:33 PM
Points: 18,858,
Visits: 12,443
|
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Yesterday @ 5:40 PM
Points: 5,123,
Visits: 20,370
|
|
|
|
|
|
Mr or Mrs. 500
      
Group: General Forum Members
Last Login: Tuesday, April 02, 2013 8:28 PM
Points: 555,
Visits: 2,137
|
|
Hugo Kornelis (3/13/2012)
... The view above allows people to add personnel into the Marketing department, or to update a row to transfer someone from Sales to Accounting. The WITH CHECK option prevents that, while still allowing users to update a row to transfer people between Sales and SalesBackOffice. oh... it was not what I tought...good thing I ask  So much to learn... so much to understand...so much to remembered... good thing you are there!
Thanks Hugo for the precision! Thanks bitbucket for the question!
|
|
|
|