3

I would like to have a script for deployment which is rerunable. So I check if the table is there before renaming it.

IF EXISTS ( SELECT  * FROM    sys.objects  WHERE   object_id = OBJECT_ID(N'[dbo].[Schema]')  AND type IN ( N'U' ) )  
BEGIN
sp_rename [Schema], [SchemaInfo] 
END

The error is

Incorrect syntax near 'sp_rename'.

0

2 Answers 2

5

Try:

EXEC sp_rename N'Schema', N'SchemaInfo';

IMHO you should never call a stored procedure without EXEC.

Sign up to request clarification or add additional context in comments.

Comments

3

Try with EXEC statement in followng way:

IF EXISTS ( SELECT  * FROM    sys.objects  WHERE   object_id = OBJECT_ID(N'[dbo].[Schema]')  AND type IN ( N'U' ) )  
BEGIN
EXEC sp_rename [Schema], [SchemaInfo] 
END

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.