The SQL
query that I have used is :
ALTER TABLE oldtable RENAME TO newtable;
But, it gives me an error.
Server: Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'TO'.
The SQL
query that I have used is :
ALTER TABLE oldtable RENAME TO newtable;
But, it gives me an error.
Server: Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'TO'.
To rename a column:
To rename a table:
To rename a table in SQL Server, use the
sp_rename
command:When using sp_rename which works like in above answers, check also which objects are affected after renaming, that reference that table, because you need to change those too
I took a code example for table dependencies at Pinal Dave's blog here
So, all these dependent objects needs to be updated also
Or use some add-in if you can, some of them have feature to rename object, and all depend,ent objects too
Nothing worked from proposed here .. So just pored the data into new table
maybe will be useful for someone..
In my case it didn't recognize the new schema also the dbo was the owner..
Worked for me. I found it from the script generated automatically when updating the PK for one of the tables. This way it recognized the new schema as well..
If you try
exec sp_rename
and receieve a LockMatchID error then it might help to add a use [database] statement first:I tried
What I had to do to fix it was to rewrite it to:
Table Name
Column
Index
also available for statics and datatypes