If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Command Required

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-18-05, 02:51
esanthosh esanthosh is offline
Registered User
 
Join Date: Oct 2005
Posts: 8
Command Required

Hi,

I have around 10,000 tables in my db2 database. I have to grant a user insert privilege to all the tables in the database. Please let me know the command to perform this grant operation in a single shot.

Regards,
Santhosh
Reply With Quote
  #2 (permalink)  
Old 10-18-05, 03:07
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
You cannot do that with one command, but you can build a script that will do that:

db2 connect to XXXXX

db2 "select 'grant insert on table '||rtrim(tabschema)||'.'||rtrim(tabname)||' to authorization-name;' from syscat.tables where tabschema <> 'SYSIBM' and type = 'T'"

Pipe the output to a file. Edit the file a bit and submit it to grant the inserts.
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
  #3 (permalink)  
Old 10-18-05, 05:13
esanthosh esanthosh is offline
Registered User
 
Join Date: Oct 2005
Posts: 8
Thanks Marcus. I am able to generate the script and grant insert privileges to the particular user to all the tables in the database.
Reply With Quote
  #4 (permalink)  
Old 10-19-05, 02:37
esanthosh esanthosh is offline
Registered User
 
Join Date: Oct 2005
Posts: 8
Marucs,

you used rtrim(tabschema) for character string values. If I have to pass integer variable say "tbspaceid" in the below command I am facing the errors.

C:\>db2 "select 'list tablespace container for '||rtrim(tbspaceid)||' with detail' from syscat.table
spaces"
SQL0440N No authorized routine named "RTRIM" of type "FUNCTION" having
compatible arguments was found. SQLSTATE=42884

Regards,
Santhosh
Reply With Quote
  #5 (permalink)  
Old 10-19-05, 02:50
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
You need to convert it to character:

db2 "select 'list tablespace containers for '||rtrim(cast (tbspaceid as char(3)))||' show detail' from syscat.tablespaces"
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390

Last edited by Marcus_A; 10-19-05 at 02:52.
Reply With Quote
  #6 (permalink)  
Old 10-19-05, 04:38
esanthosh esanthosh is offline
Registered User
 
Join Date: Oct 2005
Posts: 8
Thanks marcus. I am able to get the output.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On