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 > Grant SELECT to all tables in schema

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-16-04, 15:30
mrled mrled is offline
Registered User
 
Join Date: Jul 2004
Posts: 1
Grant SELECT to all tables in schema

New to DB2 and am wanting to grant SELECT to all tables in a schema to a group. Am hoping not to have to do this by individual tables (several thousand), but instead loop through all matching tables in SYSCAT.TABLES where TABSCHEMA = 'myschema'.

Anyone done this before?

Thanks.
Reply With Quote
  #2 (permalink)  
Old 07-16-04, 17:28
db2guru1 db2guru1 is offline
Registered User
 
Join Date: Aug 2003
Posts: 106
This is what the syntax looks like:

GRANT SELECT TO TABLE {TABLE NAME}

Looking at the syntax there is no provision for entering multiple table names.

What I would do is to do a select of all the tables and capture it in a text file. And do find replace.

STEP 1:
Capture the contents of the following select statement into text file say capture.sql using the select statement

SELECT CONCAT TABSCHEMA CONCAT '.' TABNAME WHERE TABSCHEMA = 'myschema'

So the file will have enteries like...

myschema.table1
myschema.table2

STEP 2

Use your favourite text editor and REPLACE like...

REPLACE myschema with 'GRANT SELECT TO TABLE myschema'

So
myschema.table1
myschema.table2

will become...

GRANT SELECT TO TABLE myschema.table1
GRANT SELECT TO TABLE myschema.table2

STEP 3
And now run the capture.sql in CLI interface.

Maybe there is better way others can suggest:-)
__________________

You are the creator of your own destiny!
Reply With Quote
  #3 (permalink)  
Old 07-16-04, 22:14
bmujeeb bmujeeb is offline
Registered User
 
Join Date: Mar 2004
Posts: 448
Could do some thing like that

db2 -x +o -z grant.ddl "select 'grant select on '||'.'|| tabschema '||' to group test;' from syscat.tables where tabschema ='DB2INST1'"

// Change the DB2INST1 to your schema name and group test to your group


check the file

more grant.ddl

run

db2 -tvf grant.ddl


regards,

mujeeb
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