sp_optgoal

Creates a user-defined optimization goal, and defines the set of active criteria included in the goal.

This system procedure contains the functionality to make optimization goals that are run and saved into global optimization levels in the server using sp_configure. You can use this at the session level using the set command, or globally via sp_configure.

Syntax

sp_optgoal 'goal_name’, action

Parameters

Examples

Usage

sp_optgoal with no parameters displays a list of all user-defined optimizer goals.

Permissions

The permission checks for sp_optgoal differ based on your granular permissions settings.

SettingDescription
Enabled

With granular permissions enabled, users with sa_role and sa_serverprivs_role must have manage opt goal privilege to create or delete a goal. By default, sa_role and sa_serverprivs_role are granted the manage opt goal privilege. Once created, all users can use the goal.

Any user can run sp_optgoal 'show'.

Disabled

With granular permissions disabled, you must be a user with sa_role to create or delete a goal. However, once created, all users can use the goal.

Any user can run sp_optgoal 'show'.

Auditing

Values in event and extrainfo columns from the sysaudits table are:

InformationValues
Event

38

Audit option

exec_procedure

Command or access audited

Execution of a procedure

Information in extrainfo
  • Roles – Current active roles

  • Keywords or options – NULL

  • Previous value – NULL

  • Current value – NULL

  • Other information – All input parameters

  • Proxy information – Original login name, if set proxy in effect