Results 1 to 4 of 4

Thread: [RESOLVED] SQL Server 2005 Truncate Table

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    Resolved [RESOLVED] SQL Server 2005 Truncate Table

    On my server at home, I get this error when I try to truncate a table:
    Cannot truncate table 'dbo.*****' because it is being referenced by a FOREIGN KEY constraint.

    Yes, it is referenced with a foreign key, but there is no data in the other table ! so there is nothing to complain about !

    I have simmilar table structure at on the servers at work, and when I do that it does not complain...

    There must be a setting somewhere to make it check if there are actually records in the other table, but where ?

  2. #2

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    Re: SQL Server 2005 Truncate Table

    Anyone ?

    Please help... I still have this problem

  3. #3
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: SQL Server 2005 Truncate Table

    That is just ANSI SQL. If the table has a referenced child table and the FK is in place you can not issue a trucate table command. You can remove the FKs truncate and replace if you want. You might be able to diable the FKs then re-enable when completed
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    Re: SQL Server 2005 Truncate Table

    This is my solution:
    Code:
    DELETE FROM my_table
    DBCC CHECKIDENT ( my_table, RESEED, 0 )

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width