Friday, February 24, 2012

Can a view have parameters?

For years I would have said, no it can't. But in the course of studying for
my cert exam, I checked out the following syntax:
CREATE VIEW [ schema_name . ] view_name [ (column [ ,...n ] ) ]
[ WITH <view_attribute> [ ,...n ] ]
AS select_statement [ ; ]
[ WITH CHECK OPTION ]
What is (column [ ,...n ] ) if not parameters, and how are they to be used?
I've never seen an example, and there wasn't one in the BOL article. I tried
creating a vew with a parameter, but got syntax errors.Doh! It one to many columns for the view.
"Bev Kaufman" <BevKaufman@.discussions.microsoft.com> wrote in message
news:E4F3733F-720F-47C6-8C19-C99DAA45FA8A@.microsoft.com...
> For years I would have said, no it can't. But in the course of studying
> for
> my cert exam, I checked out the following syntax:
> CREATE VIEW [ schema_name . ] view_name [ (column [ ,...n ] ) ]
> [ WITH <view_attribute> [ ,...n ] ]
> AS select_statement [ ; ]
> [ WITH CHECK OPTION ]
> What is (column [ ,...n ] ) if not parameters, and how are they to be
> used?
> I've never seen an example, and there wasn't one in the BOL article. I
> tried
> creating a vew with a parameter, but got syntax errors.
>|||Never mind, I just figured it out. The column list is just another way to
set up names for the columns in the view.
CREATE VIEW Test (Vendor, Company)
AS SELECT VendID, VendName FROM Vendor
is the same as
CREATE VIEW Test
AS SELECT VendID AS Vendor, VendName AS Company FROM Vendor
which is information that I will probably never need in the real world.
"Bev Kaufman" wrote:
> For years I would have said, no it can't. But in the course of studying for
> my cert exam, I checked out the following syntax:
> CREATE VIEW [ schema_name . ] view_name [ (column [ ,...n ] ) ]
> [ WITH <view_attribute> [ ,...n ] ]
> AS select_statement [ ; ]
> [ WITH CHECK OPTION ]
> What is (column [ ,...n ] ) if not parameters, and how are they to be used?
> I've never seen an example, and there wasn't one in the BOL article. I tried
> creating a vew with a parameter, but got syntax errors.
>|||A parameterized view is called a "user defined inline table function".
Insert / update / delete over UDFs requires coding relevant triggers.
"Bev Kaufman" <BevKaufman@.discussions.microsoft.com> wrote in message
news:E4F3733F-720F-47C6-8C19-C99DAA45FA8A@.microsoft.com...
> For years I would have said, no it can't. But in the course of studying
> for
> my cert exam, I checked out the following syntax:
> CREATE VIEW [ schema_name . ] view_name [ (column [ ,...n ] ) ]
> [ WITH <view_attribute> [ ,...n ] ]
> AS select_statement [ ; ]
> [ WITH CHECK OPTION ]
> What is (column [ ,...n ] ) if not parameters, and how are they to be
> used?
> I've never seen an example, and there wasn't one in the BOL article. I
> tried
> creating a vew with a parameter, but got syntax errors.
>

No comments:

Post a Comment