SET FMTONLY (Transact-SQL)

Si applica a:SQL Server database SQL di Azure Istanza gestita di SQL di Azure Azure Synapse Analytics AnalyticsPlatform System (PDW)SQL analytics endpoint in Microsoft FabricWarehouse in Microsoft Fabric

Restituisce solo i metadati al client. Può essere utilizzata per testare il formato della risposta senza eseguire effettivamente la query.

Convenzioni di sintassi Transact-SQL

Sintassi

SET FMTONLY { ON | OFF }   

Osservazioni:

Quando FMTONLY è ON, viene restituito un set di righe con i nomi delle colonne, ma senza righe di dati.

SET FMTONLY ON non ha effetto quando viene analizzato il batch Transact-SQL. L'effetto si verifica durante la fase di esecuzione.

Il valore predefinito è OFF.

Autorizzazioni

È richiesta l'appartenenza al ruolo public.

Esempi

Nell'esempio di codice Transact-SQL che segue FMTONLY viene impostato su ON. Questa impostazione fa in modo che SQL Server restituisca solo le informazioni sui metadati per le colonne selezionate. Nello specifico vengono restituiti i nomi delle colonne. Non vengono restituite righe di dati.

Nell'esempio, l'esecuzione di prova della stored procedure prc_gm29 restituisce quanto segue:

  • Set di righe multipli.
  • Colonne da più tabelle, in una delle relative istruzioni SELECT.
SET NOCOUNT ON;
GO

DROP PROCEDURE IF EXISTS prc_gm29;

DROP TABLE IF EXISTS #tabTemp41;
DROP TABLE IF EXISTS #tabTemp42;
GO

CREATE TABLE #tabTemp41
(
   KeyInt41        INT           NOT NULL,
   Name41          NVARCHAR(16)  NOT NULL,
   TargetDateTime  DATETIME      NOT NULL  DEFAULT GetDate()
);

CREATE TABLE #tabTemp42
(
   KeyInt42 INT          NOT NULL,   -- JOIN-able to KeyInt41.
   Name42   NVARCHAR(16) NOT NULL
);
GO

INSERT INTO #tabTemp41 (KeyInt41, Name41) VALUES (10, 't41-c');
INSERT INTO #tabTemp42 (KeyInt42, Name42) VALUES (10, 't42-p');
GO

CREATE PROCEDURE prc_gm29
AS
BEGIN
SELECT * FROM #tabTemp41;
SELECT * FROM #tabTemp42;

SELECT t41.KeyInt41, t41.TargetDateTime, t41.Name41, t42.Name42
   FROM
                 #tabTemp41 AS t41
      INNER JOIN #tabTemp42 AS t42 on t42.KeyInt42 = t41.KeyInt41
END;
GO

SET DATEFORMAT mdy;

SET FMTONLY ON;
EXECUTE prc_gm29;   -- Returns multiple tables.
SET FMTONLY OFF;
GO

DROP PROCEDURE IF EXISTS prc_gm29;

DROP TABLE IF EXISTS #tabTemp41;
DROP TABLE IF EXISTS #tabTemp42;
GO

/****  Actual Output:
[C:\JunkM\]
>> osql.exe -S myazuresqldb.database.windows.net -U somebody -P secret -d MyDatabase -i C:\JunkM\Issue-2246-a.SQL 

 KeyInt41    Name41           TargetDateTime
 ----------- ---------------- -----------------------

 KeyInt42    Name42
 ----------- ----------------

 KeyInt41    TargetDateTime          Name41           Name42
 ----------- ----------------------- ---------------- ----------------


[C:\JunkM\]
>>
****/

Vedi anche

Istruzioni edizione Standard T (Transact-SQL)