May 29, 2011 at 2:36 am
Hi
I am working on renaming some tables inside a database. For this I have made the following code:
declare @TableName as varchar(150)
declare @mystring as varchar(200)
declare @NewCompanyName AS VARCHAR(50)
declare @NewTableName AS varchar (250)
declare @counter as int
declare @start as int
set @start = 1;
select @counter =Count(name) from sys.tables
where name like 'CompanyName$%'
while @start <= @counter begin
set @TableName = ''
select top 1 @TableName = name from sys.tables
where name like 'CompanyName$%'
order by object_id asc
IF (@TableName <> '')
Begin
SET @NewTableName = REPLACE(@TableName, 'CompanyName','NewCompanyName')
EXEC sp_rename @TableName, @NewTableName;
end
set @start = @start + 1
end
On some tables it says: Object 'yada yada yada' cannot be renamed because the object participates in enforced dependencies.
How do I find theses “enforced dependencies”?
/René
May 29, 2011 at 2:50 am
check sys.sql_expression_dependencies.
Also, Aaron Bertrands blog is a good reference.
May 29, 2011 at 10:01 am
Thanks, I will look into that 🙂
/René
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply