1 year ago
#385254
Insan Cahya
Rename table in SQL Server
I want to rename a table. But I get an error when running the code. What is the correct code?
DECLARE @TABLE_NAME VARCHAR(100)
SET @TABLE_NAME = 'Employee_Destination'
IF EXISTS (SELECT NAME FROM SYS.tables WHERE NAME = @TABLE_NAME)
BEGIN
EXEC sp_rename @TABLE_NAME, @TABLE_NAME += '_2'
END
This error message (SSMS):
Incorrect syntax near @TABLE_NAME
This error message (SSIS Project) :
[Execute SQL Task] Error: Executing the query "DECLARE @TABLE_NAME VARCHAR(100) DECLARE @TABLE_TE..." failed with the following error: "An error occurred while extracting the result into a variable of type (DBTYPE_I4)". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.
Note: I run this code in a SSIS project
Thank you.
sql
sql-server
ssis
0 Answers
Your Answer