Reputation: 646
I want to rename a table in SQL Server. I know the proper syntax would be:
sp_rename 'old table name','new table name';
Would it make any difference if I write it this way?:
EXEC sp_rename 'old table name','new table name';
I tried running it on SQL Server and without the EXEC
, it would highlight my syntax sp_rename
with red, but it doesn't throw any error.
Can anyone suggest the proper way or any other alternatives to rename a table?
Note: I know altering table name will affect or probably break the script and stored procedure, is there any way to prevent this? Or it only breaks if there is another table dependent on it?
Upvotes: 2
Views: 2951
Reputation: 25152
The easiest way would be to right click on the table name and click "rename". Both of your methods of using a proc are correct, though.
I would caution using this procedure though, especially in renaming stored procedures. It has been documented in many places that sp_rename fails to update the sys.procedures table which is often used to identify these objects within your database.
Upvotes: 1
Reputation: 8043
You can execute a stored procedure with or without the EXEC Keyword. So Both your approaches are correct and has the same effect.
All the below 3 approaches are valid but the most commonly used is the 1st one
EXEC sp_rename 'old table name','new table name';
EXECUTE sp_rename 'old table name','new table name';
sp_rename 'old table name','new table name';
Upvotes: 1