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?
: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.
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.
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.
RAISERROR ('column already exists',0,1) with nowait
or
print 'column already exists'
you can use PRINT statement in SQL
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With