Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 699
Ron Tuffin Avatar asked Sep 13 '10 11:09

Ron Tuffin


People also ask

How do you display text in SQL query?

:Explanation: Note: You can use literal string (enclosed in single or double quotation mark) just like we use a column name in the SELECT statement. If you use the literal string with a column then it will be displayed in every row of the query results.

How do you display something in SQL?

In Sql Server PRINT statement can be used to return message to the client. It takes string expression as input and returns string as a message to the application.

How do I display a specific record in SQL?

To select rows using selection symbols for character or graphic data, use the LIKE keyword in a WHERE clause, and the underscore and percent sign as selection symbols. You can create multiple row conditions, and use the AND, OR, or IN keywords to connect the conditions.


2 Answers

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

or

print 'column already exists'
like image 192
Martin Smith Avatar answered Sep 19 '22 01:09

Martin Smith


you can use PRINT statement in SQL

like image 20
Sachin Shanbhag Avatar answered Sep 20 '22 01:09

Sachin Shanbhag