Solved

Truncate table/create index permissions with dynamic sql

Posted on 2007-03-20
7
740 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
Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

 

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

867 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now