Solved

Truncate table/create index permissions with dynamic sql

Posted on 2007-03-20
7
743 Views
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?

jkabx
0
Comment
Question by:jkavx
  • 4
  • 3
7 Comments
 
LVL 29

Expert Comment

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

Author Comment

by:jkavx
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.
0
 
LVL 29

Accepted Solution

by:
QPR earned 500 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...

Permissions
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.

0
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 

Author Comment

by:jkavx
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.
0
 
LVL 29

Expert Comment

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

Expert Comment

by:QPR
ID: 18761749
and again (as above) for truncating.....
Permissions
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.
0
 

Author Comment

by:jkavx
ID: 18761874

Great.  Thx.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

821 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