CREATE PROCEDURE statement [T-SQL]

Description

Creates a new procedure in the database in a manner compatible with Adaptive Server Enterprise.

Syntax

The following subset of the Transact-SQL CREATE PROCEDURE statement is supported in Sybase IQ.

CREATE PROCEDUREowner.]procedure_name
… [ [ ( ] @parameter_name data-type [ = default ] [ OUTPUT ] [ , … ] [ ) ] ]
…[ WITH RECOMPILE ]
… ASstatement-list

Usage

The following differences between Transact-SQL and Sybase IQ statements are listed to help those writing in both dialects.

CREATE PROCEDURE showdept @deptname varchar(30)
AS
  SELECT Employees.Surname, Employees.givenName
  FROM Departmens, Employees
  WHERE Departments.DepartmentName = @deptname
  AND Departments.DepartmentID =
        Employees.DepartmentID

The following is the corresponding Sybase IQ procedure:

CREATE PROCEDURE showdept(in deptname 
      varchar(30) )
RESULT ( lastname char(20), firstname char(20))
ON EXCEPTION RESUME
BEGIN
  SELECT Employees.SurName, Employees.GivenName
  FROM Departments, Employees
  WHERE Departments.DepartmentName = deptname
  AND Departments.DepartmentID =
        Employees.DepartmentID
END

NoteThere are two ways to create stored procedures: T-SQL and SQ/92. BEGIN TRANSACTION, for example, is T-SQL specific when using CREATE PROCEDURE syntax. Do not mix syntax when creating stored procedures.


Side effects

Automatic commit.

Standards

Permissions

Must have RESOURCE authority.

See also

CREATE PROCEDURE statement

“Copy Definition utility (defncopy)” in Chapter 3, “Database Administration Utilities” of the Utility Guide