Solved

Rename table with dependancies in SQL Server 2005

Posted on 2010-08-23
8
2,386 Views
Last Modified: 2012-08-13
I have made primary key and indexing changes to a relatively large table in my database and now I need to rename the old table so I can rename the new table to replace it.

The problem comes in with the fact that the old table has about 20 stored procedures that reference the table. SQL Server is complaining about the dependancies when I try to rename it.

How do I get around this?
0
Comment
Question by:dgerler
  • 4
  • 3
8 Comments
 
LVL 3

Expert Comment

by:mnachu
ID: 33502863
Interesting I thought SQL server would just give a warning if only SPs are referencing the tables and let you rename it.

It will complain only if the tables you are trying to rename is referrenced by other tables using Foreign keys.

Anyways one work around I can think of is just drop the procedures, rename the tables, create the new tables, and create the dropped procedures.

Regards,
Nachi
0
 
LVL 42

Expert Comment

by:dqmq
ID: 33502936
Agree, dependent procs should not prevent the rename.  What exactly is the error message?
0
 

Author Comment

by:dgerler
ID: 33503045
The error...

TITLE: Microsoft SQL Server Management Studio
------------------------------

Unable to rename TicketDetailold. (ObjectExplorer)

------------------------------
ADDITIONAL INFORMATION:

Rename failed for Table 'dbo.TicketDetail'.  (Microsoft.SqlServer.Smo)

For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=9.00.4035.00&EvtSrc=Microsoft.SqlServer.Management.Smo.ExceptionTemplates.FailedOperationExceptionText&EvtID=Rename+Table&LinkId=20476

------------------------------

An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo)

------------------------------

Object '[dbo].[TicketDetail]' cannot be renamed because the object participates in enforced dependencies. (Microsoft SQL Server, Error: 15336)

For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=09.00.4035&EvtSrc=MSSQLServer&EvtID=15336&LinkId=20476

0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 

Author Comment

by:dgerler
ID: 33503060
I removed the foriegn key already.

What about views? would that cause the problem?
0
 
LVL 42

Accepted Solution

by:
dqmq earned 500 total points
ID: 33503140
Views?  I don't think so.

Try this:

select o.name as ObjName, r.name as ReferencedObj
from sys.sql_dependencies d
join sys.objects o on o.object_id=d.object_id
join sys.objects r on r.object_id=d.referenced_major_id
where d.class=1
AND r.name = 'TicketDetail'
0
 
LVL 42

Expert Comment

by:dqmq
ID: 33503155
Correction.  A view can be the cause if it is stored with the Schema Binding option.
0
 

Author Comment

by:dgerler
ID: 33503175
Looks like it's a view

Detail      TicketDetail
Detail      TicketDetail
Detail      TicketDetail
Detail      TicketDetail
Detail      TicketDetail
Detail      TicketDetail
Detail      TicketDetail
Detail      TicketDetail
Detail      TicketDetail
Detail      TicketDetail
Detail      TicketDetail
Detail      TicketDetail
Detail      TicketDetail
Detail      TicketDetail
Detail      TicketDetail
Detail      TicketDetail
0
 

Author Comment

by:dgerler
ID: 33503228
Yep.. I was able to rename after droping  the view. Of course I scripted it to query window first to make it easy to put back. :) Thank you.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
sql calculate reminders 11 76
Sql Permission 6 61
Set the max value for a column 7 39
Anyway to make these 2 SQL statements into one? 13 39
by Mark Wills PIVOT is a great facility and solves many an EAV (Entity - Attribute - Value) type transformation where we need the information held as data within a column to become columns in their own right. Now, in some cases that is relatively…
INTRODUCTION: While tying your database objects into builds and your enterprise source control system takes a third-party product (like Visual Studio Database Edition or Red-Gate's SQL Source Control), you can achieve some protection using a sing…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question