Feed on
Subscription

Technology of SQL Server database (93)

Besides the function that use system provides,The user is OK still define function oneself according to need.The user defines function oneself (User Defined Functions) it is the database object that SQL Server 2000 adds newly,Improve be SQL Server greatly.
The user cannot be used at executing a series of operations that change database position from definition function,But it can be in like systematic function inquiry or memory process are used in the block that wait,Also can pass EXECUTE command to carry out like memory process.The user stored in definition function oneself Cheng of exemple of a Transact-SQL,Can return fair value.
In the basis in SQL Server 2000 of form of function return of value differ to define the user function cent to be three sort oneself model:Scalar quantity function (Scalar Functions)
The scalar quantity that scalar quantity function returns a certain type is worth type of its return of value to be the other data type outside removing TEXT, NTEXT, IMAGE, CURSOR, TIMESTAMP and TABLE type.Function body statement is defined inside BEGIN-END statement,It is OK to was included among them the Transact-SQL of return of value commands.Couplet expresses value function inside (Inline Table-valued Functions)
Couplet expresses value function to return a return of value with the form of the watch inside,Namely what it returns is value of watch of the couplet inside a watch function the function body that did not rise by draw together of BEGIN-END statement.The watch that its return is commanded by a SELECT in be located in RETURN clause paragraph choose from inside the database.The view that couplet expresses value function function to be equivalent to a parameter changing inside.Value of much statement watch function (Multi-statement Table-valued Functions)
Value of much statement watch function can regard scalar quantity model and inside the combinative put oneself in another's position of couplet watch value function.Its return of value is a watch,But the function system that there is to rise with draw together of BEGIN-END statement like it and scalar quantity function,The data in the watch of return of value is insert by the statement in function body.This shows,It can undertake for many times inquiring,Undertake for many times filtration to data
With amalgamative,Made up for inside the inadequacy of couplet watch value function.

13.13.1 founds an user to define function oneself
SQL Server 2000 defined function to offer different command to establish a pattern oneself for the user of three kinds of types.
(1) found scalar quantity user to define function oneself (Scalar Functions) its grammar is as follows:


Each parameter explains as follows:


Owner_name
Those who appoint an user to define function oneself is possessory.Function_name
The name that designates an user to define function oneself.Database_name.owner_name.function_name should be only.@parameter_name
The name that defines one or more parameter.A function can define 1024 at most parameter is used before every parameter " @ " the symbol indicates.The action limits of parameter is whole function.Parameter can replace constant only,The name that cannot replace watch name, row name or other database object.The user does not support output parameter from definition function.Scalar_parameter_data_type
The data type that specifies scalar quantity parameter,Can be the other data type outside removing TEXT, NTEXT, IMAGE, CURSOR, TIMESTAMP and TABLE type.Scalar_return_data_type
The data type that assigns scalar quantity return of value,Can be the other data type outside removing TEXT, NTEXT, IMAGE, CURSOR, TIMESTAMP and TABLE type.Scalar_expression
The expression of mark value of a quantity that appoints scalar quantity user to define function to return oneself.Function_body
Appoint a series of Transact-SQL statement,The return of value that they decided function.ENCRYPTION
Add close option.The statement that CREATE FUNCTION concerns in letting SQL Server be expressed to the system is added close,Be released in order to avoid the one share that the user regards SQL Server as to duplicate from definition function (Publish) .SCHEMABINDING
The plan binds calm option to define the user function to if assigned this option,bind the database object that cites to it surely oneself,Criterion the database target that function place involves cannot be deleted or will revise from now on,Unless function is deleted or take out this option.What should notice is,Should bind decided database object to must be with function in same database.



(2) found inside couplet watch value user defines function oneself (Inline Table-valued Functions)
Its grammar is as follows:



Each parameter explains as follows:TABLE
Appoint return of value to be expressed for.Select-stmt
Statement of individual SELECT,The data of the watch that returns certainly.
The others parameter and scalar quantity user defines function oneself identical.




[1] [2] issues one page

Related:

    收藏到网摘:

    Submit: