User`s guide
exec
7-119
Define a stored procedure named create_table that creates a table named
test_table by executing this code. This procedure has no input or output arguments.
This code assumes you are using a Microsoft SQL Server database.
CREATE PROCEDURE create_table
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
create table test_table
(
CATEGORY_ID INTEGER IDENTITY PRIMARY KEY,
CATEGORY_DESC CHAR(50) NOT NULL
);
END
GO
Connect to the Microsoft SQL Server database. This code assumes you are connecting to
a data source named MS SQL Server with user name username and password pwd.
conn = database.ODBCConnection('MS SQL Server','username','pwd');
Call the stored procedure create_table. Assign the returned cursor object to the
variable curs.
curs = exec(conn,'create_table')
curs =
ODBCCursor with properties:
Data: 0
RowLimit: 0
SQLQuery: 'create_table'
Message: []
Type: 'ODBCCursor Object'
Statement: [1x1 database.internal.ODBCStatementHandle]
The empty Message property means the stored procedure completed successfully.
After finishing with the cursor object, close it.