How to grant select privileges on all tables for DB2

Take these steps to generate SELECT privileges for a given USER on all tables in a SCHEMA

Either create a shell script and execute, or run from the command prompt

 

MYDB=""
MYSCHEMA=""
MYUSER=""
db2 "CONNECT TO $MYDB"
DBTABLES=`db2 -x "SELECT tabname FROM syscat.tables WHERE tabschema=UPPER('$MYSCHEMA')"`
for TABLENAME in $DBTABLES;
do db2 "GRANT SELECT ON $MYSCHEMA.$TABLENAME TO USER $MYUSER"
done
db2 "DISCONNECT $MYDB"

 

Author: Jack Vamvas

Leave a Reply

Discover more from ciquery

Subscribe now to keep reading and get access to the full archive.

Continue reading