Solved

Truncate table/create index permissions with dynamic sql

Posted on 2007-03-20
7
741 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MS SQL with ODBC 5 36
get column names from table in vb.net 8 28
SQL View nearest date 5 36
SQL2016 to ORACLE11G linked-server 6 8
Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how the fundamental information of how to create a table.

770 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