Solved

Rename table with dependancies in SQL Server 2005

Posted on 2010-08-23
8
2,281 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
 

Author Comment

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

What about views? would that cause the problem?
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

If you having speed problem in loading SQL Server Management Studio, try to uncheck these options in your internet browser (IE -> Internet Options / Advanced / Security):    . Check for publisher's certificate revocation    . Check for server ce…
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

707 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now