Samiey Mehdi
Samiey Mehdi

Reputation: 9414

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

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

Upvotes: 24

Views: 42721

Answers (9)

drpepper1324
drpepper1324

Reputation: 133

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

EXEC sp_rename '[dbo].[Vb.Net]','VB'

Upvotes: 0

TOOR PIZZZ
TOOR PIZZZ

Reputation: 72

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

Upvotes: -2

Sel
Sel

Reputation: 2004

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

Upvotes: 3

F. Hamers
F. Hamers

Reputation: 11

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.

Upvotes: 1

Shahram fr
Shahram fr

Reputation: 122

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

Upvotes: 1

Bob
Bob

Reputation: 93

(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.

Upvotes: 0

Samiey Mehdi
Samiey Mehdi

Reputation: 9414

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

Upvotes: 50

CodeCaster
CodeCaster

Reputation: 151588

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.

Upvotes: 0

Ravi Patel
Ravi Patel

Reputation: 463

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...

Upvotes: 0

Related Questions