Cloud & SQLSailor

Cloud, Databases & Beyond!

Rename a table,Easy using sp_rename,but how to use in C#


Today I came across an interesting question on how to rename a table in SQL Server.Thats a pretty easy one and we can use sp_rename to accomplish this.

sp_rename ‘OLD_TABLE_NAME’  , ‘NEW_TABLE_NAME’

However when a user needs it do via C#,then how can he/she do this.

Solution

 

To rename a table in a C# code, pass the sp_rename code as string to a SqlCommand object and call the SqlCommand.ExecuteNonQuery() method.

 

Leave a comment