create function

Description

Creates a user-defined function.

NoteWhen you create a function replication definition, a user-defined function is automatically created. For more information, see create applied function replication definition and create request function replication definition.

If your application uses asynchronous procedure delivery associated with table replication definitions, you may need to create user-defined functions. For more information, see the Replication Server Administration Guide Volume 2.

Syntax

create function replication_definition.function
([@param_name datatype [, @param_name datatype]...])

Parameters

replication_definition

The name of the replication definition the function is for. You can create only one user-defined function for all the replication definitions for the same table. If there are multiple replication definitions for the same table, you can specify the name of any one of them. However, each replication definition has its own function string for the user-defined function.

function

The name of the function. The name must be unique for the replication definition and must conform to the rules for identifiers. The names of the system functions listed in Chapter 4, “Replication Server System Functions,”and all function names that begin with “rs_”, are reserved.

@param_name

The name of an argument to the user-defined function. Each parameter name must be preceded by an @ sign and must conform to the rules for identifiers. The value of each parameter is supplied when the function is executed.

datatype

The datatype of the parameter. Some datatypes require a length, in parentheses, after the datatype name. See “Datatypes” for a description of the datatypes and their syntax. The datatype cannot be text, unitext, rawobject, or image.

Examples

Example 1

Creates a user-defined function named newpublishers, with four parameters, for the publishers_rep replication definition:

create function publishers_rep.newpublishers
 (@pub_id char(4), @pub_name varchar(40),
 @city varchar(20), @state char(2))

Usage

Permissions

create function requires “create object” permission.

See also

create applied function replication definition, create function string, create request function replication definition, drop function