"...cannot be renamed because the object participates in enforced dependencies"

  • 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é

  • check sys.sql_expression_dependencies.

    Also, Aaron Bertrands blog is a good reference.



    Lutz
    A pessimist is an optimist with experience.

    How to get fast answers to your question[/url]
    How to post performance related questions[/url]
    Links for Tally Table [/url] , Cross Tabs [/url] and Dynamic Cross Tabs [/url], Delimited Split Function[/url]

  • 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