EDIT: the function creation was missing, sorry about that
I have a T-SQL request that goes:
DECLARE @IsSomething bit
SET @IsSomething = 0
IF /some tests/ SET @IsSomething = 1
EXEC('
CREATE FUNCTION IsSomething ()
RETURNS bit
AS
BEGIN
RETURN ' + @IsSomething + '
END')
Of course if I run it twice I get
There is already an object named 'IsSomething ' in the database.
How would I do something like this:
IF EXIST @IsSomething DESTROY @IsSomething // (Pseudo bad code)
A DROP statement in SQL removes a component from a relational database management system (RDBMS). Syntax: DROP object object_name Examples: DROP TABLE table_name; table_name: Name of the table to be deleted. DROP DATABASE database_name; database_name: Name of the database to be deleted.
To remove an existing database from a SQL Server instance, you use the DROP DATABASE statement. In this syntax, you specify the name of the database that you want to drop after the DROP DATABASE keywords.
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id (N'[dbo].[IsSomething]') AND OBJECTPROPERTY(id, N'IsFunction') = 1)
DROP function IsSomething
GO
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