1. Assume that the fields "ID" and "Manager" exist as Integers for each entry in the "Persons" table. Write a SQL Function that accepts an "ID" and returns the value from the "Manager" of the specified person. 2. Assume the table "Persons" has a field named "Location" that matches up with the "ID" field of the "Locations" table. Write the SQL to create a view that returns all fields for "Persons" with the correct value of the "Description" field from the "Locations" table.
Assuming it's not homework (hahaha)... The "function" to which you refer is probably a "scalar function". Scalar functions are generally a poor choice in these situations because they are... well... procedural code, not set based code. It's my understanding that they get executed once for each row (slow). There's an interesting article here (
http://www.sqlservercentral.com/articles/T-SQL/91724/) that treats an in-line table valued function (which is set-based rather than procedural) as if it were a scalar function. It returns a "table" of one row, one column, so you get (some of) the performance benefits of set-based code, with the advantage of encapsulated logic. Having said all of that, you'd test performance in each case because the right solution might depend on some peculiarity of a particular situation.