We have moved to www.dataGenX.net, Keep Learning with us.

Tuesday, July 10, 2012

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.
We can either create a script or execute the commands one by one on Terminal.


MYDB="<insert_db_name>"
MYSCHEMA="<insert_schema>"
MYUSER="<insert_user>"
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"




njoy the simplicity.......
Atul Singh

No comments :

Post a Comment