2010-09-13 6 views
5

Ad esempio. Ho uno script di aggiornamento del database per aggiungere una colonna a una tabella di database. Sembra un po 'questo:Come posso visualizzare qualcosa durante l'esecuzione di uno script SQL su SQLServer?

IF NOT Exists(SELECT * FROM SysColumns sc, SysObjects so 
       WHERE sc.Name = 'dealer_number' 
       AND so.Name = 'collector' 
       AND so.Type= 'U' 
       AND so.id = sc.id) 
BEGIN 
-- SQL for creating column 
END 
ELSE 
BEGIN 
-- notify user that column already exists 
END 

Come si comunica all'utente che la colonna esiste già?

risposta

7
RAISERROR ('column already exists',0,1) with nowait 

o

print 'column already exists' 
+0

+1 - Molto utile anche nei processi di memorizzazione lunghi. – JNK

2

Utilizzare STAMPA - funziona dalla maggior parte delle applicazioni client SQL. SELEZIONA funziona anche es

PRINT 'column already exists or something' 

o

SELECT 'column already exists or something' 
2

è possibile utilizzare PRINT istruzione in SQL

Problemi correlati