Skip to content
OCTAVIIUS DOCSCore & Studio 0.2.83
SQL reference / 0.2.83

Views, stored procedures and SQL batches

Relational abstraction, procedure parameters and SQL script control flow.

Views and interface stability

A view names a reusable relational expression and exposes a read interface. CREATE OR ALTER VIEW evolves its definition under a stable identifier. Explicit column lists make the consumer contract independent of source-schema expansion. A view stores a definition; a preaggregate is a physical calculation structure: they serve distinct roles.

Read-only views

CREATE VIEW, ALTER VIEW, CREATE OR ALTER VIEW and DROP VIEW are available. A view stores its definition, not an independent materialized dataset. Views are read-only. SELECT permissions can target the view; test source permissions under the actual identity rather than assuming SQL Server ownership chaining.

SQL
CREATE OR ALTER VIEW dbo.TotauxPays AS
SELECT Pays, SUM(Montant) AS total FROM dbo.Ventes GROUP BY Pays;

SELECT * FROM dbo.TotauxPays ORDER BY Pays;

Define and call a procedure

CREATE/ALTER/CREATE OR ALTER/DROP PROC or PROCEDURE, EXEC/EXECUTE, typed/default parameters, positional then named arguments, OUTPUT and RETURN are available. A positional argument cannot follow a named one. Nested calls are limited to 32 levels. EXECUTE AS and table-valued procedure parameters are unsupported.

Create the definition as a separate statement. OUTPUT enables input/output; the caller must also pass the variable with OUTPUT. Internal writes retain normal permission checks: EXECUTE is not privilege escalation.

SQL
CREATE OR ALTER PROCEDURE dbo.Ajouter
 @entree INT, @total INT OUTPUT
AS BEGIN
 SET @total = @total + @entree;
 SELECT @total AS total;
 RETURN 7;
END;

SQL calls and HTTP protocol

This SQL call captures output and status separately. HTTP applications select protocol 4; protocol 3 rejects procedures. OUTPUT values and return_status become final only on global complete. ODBC exposes successive results through SQLMoreResults/nextset within the driver’s qualified scope.

SQL
DECLARE @somme INT = 2, @statut INT;
EXEC @statut = dbo.Ajouter @entree = 3, @total = @somme OUTPUT;
SELECT @somme AS somme, @statut AS statut;

Dynamic SQL and identifier quoting

EXEC(string) and sp_executesql with typed/OUTPUT parameters are available. Caller batch variables are not automatically visible in an isolated dynamic scope. Bind values and use QUOTENAME for a validated identifier; QUOTENAME does not authorize arbitrary objects. RAISERROR is unsupported; use THROW within its implemented scope.

Procedure deletion and renaming

DROP PROCEDURE [IF EXISTS] and DROP VIEW [IF EXISTS] support conditional forms. EXEC sp_rename with objtype OBJECT is limited here to procedure renaming; it does not promise general SQL Server table/column renaming. The new name is an unqualified identifier. Check dependent calls after renaming; this is not a general rewrite of stored SQL.