SQL Server Compact Code Snippet of the Week #5 : rename a table

The SQL Server Compact ADO.NET provider allows you to rename a table name by using the special sp_rename T-SQL “command” (SQL Server Compact does not support stored procedures, but this “command” corresponds to the sp_rename system stored procedure on SQL Server).

You cannot only use sp_rename against a table in SQL Server Compact using the ADO.NET interfaces, but using the native OLEDB interfaces, you can also rename columns, as Joao demonstrates here. This is used in his Data Port Console product. Otherwise you can just script a DROP and CREATE statement with the SQL Server Compact Toolbox, and rename both column and table names in the CREATE script.

To rename a table, use the following T-SQL code:

sp_rename 'OldName', 'NewName'

Write a Comment

Your email address will not be published. Required fields are marked *