Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase ««123»»

VIEWS 2 Expand / Collapse
Author
Message
Posted Monday, March 12, 2012 7:30 AM
SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Today @ 7:05 AM
Points: 926, Visits: 1,316
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.
Post #1265185
Posted Monday, March 12, 2012 8:11 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Tuesday, July 9, 2013 11:12 PM
Points: 1,263, Visits: 1,081
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
Post #1265217
Posted Monday, March 12, 2012 10:25 AM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Saturday, November 29, 2014 2:17 AM
Points: 483, Visits: 245
Simple yet important concept on views where multiple tables are involved regardless of indexes, primary or foreign keys. Thanks for the question.
Post #1265353
Posted Monday, March 12, 2012 11:24 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: 2 days ago @ 7:11 PM
Points: 7,920, Visits: 9,646
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
Post #1265412
Posted Monday, March 12, 2012 11:33 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: 2 days ago @ 7:11 PM
Points: 7,920, Visits: 9,646
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
Post #1265418
Posted Monday, March 12, 2012 6:47 PM
Mr or Mrs. 500

Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500

Group: General Forum Members
Last Login: Thursday, May 15, 2014 8:37 PM
Points: 589, Visits: 2,437
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...

Post #1265657
Posted Tuesday, March 13, 2012 1:50 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 2:32 PM
Points: 6,128, Visits: 8,393
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
Post #1265729
Posted Tuesday, March 13, 2012 3:22 PM


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: Today @ 7:55 AM
Points: 18,060, Visits: 16,090
Got any more like this Ron?



Jason AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server, MVP


SQL RNNR

Posting Performance Based Questions - Gail Shaw
Post #1266361
Posted Tuesday, March 13, 2012 3:35 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Thursday, November 6, 2014 1:00 PM
Points: 5,333, Visits: 25,277
SQLRNNR (3/13/2012)
Got any more like this Ron?


ONe more called VIEW 3 scheduled for the 20th of March and 2 more pending have been submitted .. waiting to be scheduled.


If everything seems to be going well, you have obviously overlooked something.

Ron

Please help us, help you -before posting a question please read

Before posting a performance problem please read
Post #1266366
Posted Tuesday, March 13, 2012 5:31 PM
Mr or Mrs. 500

Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500

Group: General Forum Members
Last Login: Thursday, May 15, 2014 8:37 PM
Points: 589, Visits: 2,437
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!
Post #1266423
« Prev Topic | Next Topic »

Add to briefcase ««123»»

Permissions Expand / Collapse