Truncate

  • I have a stored procedure that has several functions in it.

    Two of them are:

    Truncate a table

    Insert to that same table.

    I truncate (rather than) because I thought that was the best way to get the index (seed) back to the number 1.

    I need to assign a DataBase Role the ability to truncate to they may execute this Store Procedure.

    Execute As Self looks like it may work BUT, I can't seem to get it working in 2000 (MSSQL 7).

    If I can't use Execute As Self, maybe I just am not using correctly, which other permission is the best to grant.

    I would really appreciate your help,

  • Is this SQL 2000? I don't believe EXECUTE AS works in 2000.

    AFAIK, in 2000 you had to be the owner of the table for truncate.

    http://msdn.microsoft.com/en-us/library/aa260621%28SQL.80%29.aspx

  • iirc, to truncate a table you have to be either

    1) Owner of the table

    2) member of ddl_admin fixed database role.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • I've added ddl_admin to the people that need to execute this Stored Procedure.

    It has worked in testing.

    I'll know for sure next week when it's deployed, but it looks good. When we upgrage, then perhaps I can change the Procedure to Execute As. That might be better.

  • Ken@Work (8/18/2010)


    I've added ddl_admin to the people that need to execute this Stored Procedure.

    Just bear in mind that ddl_admin gives them the permission to create, alter and drop any table, view, procedure, function, etc in the database.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply