Search code examples
c#renamemdf

Rename a table in c#


Hello how can I rename a table? I'm so newcomer on SQL.

Here is my code:

using (SqlConnection connection = new SqlConnection(connString))
{
    // string symbolName = dt.Rows[1][0].ToString();

    SqlCommand command = new SqlCommand(connString);
    command.CommandText = "ALTER TABLE test RENAME TO [" + symbolName + "]";
    command.CommandType = CommandType.Text;
}

Solution

  • You can use this: sp_rename

    exec sp_rename 'schema.old_test', 'new_your_new_table_name'