How to change the table name in visual studio 2013 in design mode?
Asked Answered
L

9

24

I created a SQL database table in Visual Studio 2013. I want to rename it but the name property is disabled. How can I change the table name?

enter image description here

Lafrance answered 12/12, 2013 at 8:53 Comment(1)
just in case you have SQLServer Management Studio, you can choose the table in tree and rename by right-click on the table -> rename. I checked the same in VS it doesn't allow me to change, use Scripts insteadPazit
L
50

In Server Explorer right click on Views and click New Query.
use this code to rename table:

EXEC sp_rename 'Table', 'NewName'  

then click on Execute button.
after 5-30 seconds in server explorer click on refresh button.

enter image description here

Lafrance answered 12/12, 2013 at 10:47 Comment(0)
N
3

You can change table name in SQL Server Object Explorer in Visual Studio. Choose the table in tree and rename by right-click on the table -> rename

Nighthawk answered 9/6, 2015 at 15:13 Comment(0)
P
1

The correct answer as follows: 1.First select your table that you want to change. 2. Then change the name in the script pane. 3.Finally in the upper-left corner of the Table Designer, choose the Update button. Please as shown below:

enter image description here

Parental answered 24/9, 2014 at 10:20 Comment(1)
This creates a new table with the new desired name - it does not rename the existing table. (i.e. you lose all your data)Personnel
S
1

Ive been trying to too, and the simple option to rename the [dbo][Table] did not seem to work.

But it actually does! Please note that refreshing doesn't work right away.

Steps:

  1. rename [dbo][Table] to [dbo][yourTable]
  2. press update button
  3. Refresh a few times, it may take a minute.

Hope this helps :) It seems a like really wierd bug.

Sleuth answered 25/9, 2014 at 7:41 Comment(0)
K
0

You can change table name in T-SQL part as showin in image as follows..

CREATE TABLE{dbo].[t1]{
{
   ...
   ...
}

to

CREATE TABLE{dbo].[t2]{
{
   ...
   ...
}

ans then press "Update" button present above...

Koopman answered 12/12, 2013 at 9:46 Comment(2)
This way create a new tableLafrance
it's for create new table !Streetman
E
0

As explained here, found through "visual studio server explorer rename table", you can't.

There is a workaround: add the tables to a database diagram, rename it there and save it.

Eleven answered 12/12, 2013 at 9:50 Comment(3)
CodeCaster , this link is to Visual studio 2010. not work in vs2013Lafrance
What do you mean with "not work in vs2013", did you try creating a database diagram and renaming the table from there?Eleven
@Samiey you're right, that's only for when connecting to SQL Server.Eleven
A
0

(using VS2013) I came looking on here because I had written the main table for my project this afternoon, and as usual set it's name in T-SQL. But had not realized that the name had not stuck until I went to use it in the Linq-to-SQL I tried over and over to rename it, and I had refreshed many times.

The default name 'Table', has an obvious clash problem in normal code.

Then tonight came on here to see if you guys had found a way and opened the project to try some out.

Turns out that although the original table called 'Table' was still there, I now had many copies of it, one for each attempt at renaming it.

So I think from that we can assume the table renaming problem is a bug rather than a feature, and that MS use a copy first, then should do the deete of the file that is being renamed. But also that the refresh does not work on these copies until the project is closed and then reopened. Yes I know, a bit cheesey, but at least there is a way around.

Personally, with this and the database overwrites at run time, I am starting to lean towards letting the database designer create the scripts for my program to use rather than creating the tables and other database parts. That puts everything back into your hands, which must be a good thing.

I haven't quite got to grips with doing the Linq-to-SQL manually yet, and it is such a bonus to a programmer that I have to tackle that first.

Airt answered 14/1, 2014 at 19:51 Comment(0)
M
0

This will help if you accidently put a dang period in your table name

EXEC sp_rename '[dbo].[Vb.Net]','VB'
Mating answered 26/7, 2022 at 3:26 Comment(0)
Y
-2

Just rename the [dbo][Table] to [dbo][TableName] press the update button.

Younger answered 14/7, 2015 at 5:35 Comment(1)
That creates a new table; leaving the existing table and its data.Personnel

© 2022 - 2024 — McMap. All rights reserved.