How can I display something during the execution of a SQL script on SQLServer?

时间秒杀一切 提交于 2019-11-30 05:14:57

问题


For example. I have a database upgrade script for adding a column to a database table. It looks a little like this:

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

How do I notify the user that the column already exists?


回答1:


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

or

print 'column already exists'



回答2:


you can use PRINT statement in SQL




回答3:


RAISERROR seems appropriate here. See here.




回答4:


Use PRINT - it works from most SQL client applications. SELECT also works e.g

PRINT 'column already exists or something'

or

SELECT 'column already exists or something'


来源:https://stackoverflow.com/questions/3700106/how-can-i-display-something-during-the-execution-of-a-sql-script-on-sqlserver

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!