Barra asterisco (blocco di commento) (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

Evidenzia il testo inserito dall'utente. Il testo tra /* e */ non viene valutato dal server.

Convenzioni di sintassi Transact-SQL

Sintassi

/*  
text_of_comment  
*/  

Nota

Per visualizzare la sintassi Transact-SQL per SQL Server 2014 (12.x) e versioni precedenti, vedere la documentazione delle versioni precedenti.

Argomenti

text_of_comment
Testo del commento. Può essere composto da una o più stringhe di caratteri.

Osservazioni:

I commenti possono essere inseriti in una riga distinta o all'interno di un'istruzione Transact-SQL. I commenti a più righe devono essere indicati da /* e */. Una convenzione stilistica spesso usata per i commenti a più righe consiste nell'iniziare la prima riga con /*, le righe successive con **e terminano con */.

I commenti possono essere di qualsiasi lunghezza.

Non sono supportati i commenti nidificati. Se il modello di caratteri /* si verifica in qualsiasi punto all'interno di un commento esistente, viene considerato come l'inizio di un commento annidato e, pertanto, richiede un segno di chiusura */ commento. Se il carattere di chiusura del commento non è presente, viene generato un errore.

Il codice di esempio seguente genera un errore.

DECLARE @comment AS VARCHAR(20);  
GO  
/*  
SELECT @comment = '/*';  
*/   
SELECT @@VERSION;  
GO   

Per risolvere il problema, apportare la modifica seguente.

DECLARE @comment AS VARCHAR(20);  
GO  
/*  
SELECT @comment = '/*';  
*/ */  
SELECT @@VERSION;  
GO  

Esempi

Nell'esempio seguente vengono utilizzati i commenti per descrivere la funzionalità della sezione di codice.

USE AdventureWorks2022;  
GO  
/*  
This section of the code joins the Person table with the Address table,   
by using the Employee and BusinessEntityAddress tables in the middle to   
get a list of all the employees in the AdventureWorks2022 database   
and their contact information.  
*/  
SELECT p.FirstName, p.LastName, a.AddressLine1, a.AddressLine2, a.City, a.PostalCode  
FROM Person.Person AS p  
JOIN HumanResources.Employee AS e ON p.BusinessEntityID = e.BusinessEntityID   
JOIN Person.BusinessEntityAddress AS ea ON e.BusinessEntityID = ea.BusinessEntityID  
JOIN Person.Address AS a ON ea.AddressID = a.AddressID;  
GO  

Vedi anche

-- (commento) (Transact-SQL)
Control-of-Flow Language (Transact-SQL)