Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Truncate table/create index permissions with dynamic sql

Posted on 2007-03-20
7
Medium Priority
?
758 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
[X]
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
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 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...

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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

610 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