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.

 

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s