Truncate table/create index permissions with dynamic sql

Posted on 2007-03-20
Medium Priority
Last Modified: 2012-06-21
I need to be able to use dynamic sql to truncate tables and create indexes.  Two different stored procs are involved.  One simply does a truncate table, using dynamic sql and a table name parameter.  The other just creates an index on a column, using dynamic sql and an a table name parameter.  This is related to a batch process; there are a group of identical tables involved.

The problem is that once the stored proc uses dynamic sql, there is not sufficient permission to do the truncate or create index.  How do I assign permissions so that the batch process account can do the truncate and create index?

Question by:jkavx
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
LVL 29

Expert Comment

ID: 18761629
make the batch process account a dbo of the Db involved?

Author Comment

ID: 18761669
Could do that, but I thought it would be better if possible to grant specific permissions for these functions - truncate table and create index.
LVL 29

Accepted Solution

QPR earned 2000 total points
ID: 18761696
How about creating a role in that DB and put the user into that role.
Give the role permissions to delete from the table and create inddexes.
From BOL...

CREATE INDEX permissions default to the sysadmin fixed server role and the db_ddladmin and db_owner fixed database roles and the table owner, and are not transferable.

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users


Author Comment

ID: 18761715
There is a role being used.  I did a Grant All on the table to that role, but that doesn't allow Create Index.

How do I make this role the owner of the table?

Delete will work, but I want to do a truncate to minimize what's written to the log.  There are a lot of records involved.
LVL 29

Expert Comment

ID: 18761740
You change the owner by using.... sp_changeobjectowner
books online will show you the parameters you nees to pass to it.
LVL 29

Expert Comment

ID: 18761749
and again (as above) for truncating.....
TRUNCATE TABLE permissions default to the table owner, members of the sysadmin fixed server role, and the db_owner and db_ddladmin fixed database roles, and are not transferable.

Author Comment

ID: 18761874

Great.  Thx.

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Suggested Courses

777 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