473,396 Members | 2,030 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

how to grant all tables

Hi,

db2 GRANT all on a_table_name to user me

is for a table, I'm wondering possible to grant all on all_tables to
user me, without listing all tables' names?

--
Thanks
John
Toronto

May 31 '06 #1
6 26322

jo******@canada.com wrote:
Hi,

db2 GRANT all on a_table_name to user me

is for a table, I'm wondering possible to grant all on all_tables to
user me, without listing all tables' names?

--
Thanks
John
Toronto


Try something like this:

function grantme {
echo "select 'grant SELECT ON ' || RTRIM(TABSCHEMA) || '.' ||
RTRIM(tabname) || chr(10)
|| ' TO ME '
|| ' ; ' || chr(10)
from syscat.tables
where tabschema = '$1' ${2+" and tabname = \'$2\'"}
;" | db2 -xt +p > .tmp

db2 -vtf .tmp
}

Jun 1 '06 #2
>
function grantme {
echo "select 'grant SELECT ON ' || RTRIM(TABSCHEMA) || '.' ||
RTRIM(tabname) || chr(10)
|| ' TO ME '
|| ' ; ' || chr(10)
from syscat.tables
where tabschema = '$1' ${2+" and tabname = \'$2\'"}
;" | db2 -xt +p > .tmp

db2 -vtf .tmp
}


Thanks lots, but

1. in linux, when run it in db2 console:

db2 => db2 => function grantme {echo "select 'gra....

it returned error:
SQL0007N The character "{" following "function grantme " is not valid.

SQLSTATE=42601

2. in linux, when run it in shell:
$ function grantme {echo "select 'grant SELECT ...

it returned error:
-bash: syntax error near unexpected token `{echo'

so, can u tell how to execute it in linux (any version for windows? I
have cgywin in windows)

--
Thanks again
John

Jun 1 '06 #3
Note that this will have to be re-done as soon as a new table is added
to the database.
Depending upon the environment, database, security etc., another option
is to grant your id DBADM access - this will give you implicit ALL
access to ALL tables.
Here's how you would do it -
1. Connect to the database as SYSADM or DBADM user
2. execute the SQL - "grant DBADM on database to user <your-id>"

-- Jayesh

jo******@canada.com wrote:

function grantme {
echo "select 'grant SELECT ON ' || RTRIM(TABSCHEMA) || '.' ||
RTRIM(tabname) || chr(10)
|| ' TO ME '
|| ' ; ' || chr(10)
from syscat.tables
where tabschema = '$1' ${2+" and tabname = \'$2\'"}
;" | db2 -xt +p > .tmp

db2 -vtf .tmp
}


Thanks lots, but

1. in linux, when run it in db2 console:

db2 => db2 => function grantme {echo "select 'gra....

it returned error:
SQL0007N The character "{" following "function grantme " is not valid.

SQLSTATE=42601

2. in linux, when run it in shell:
$ function grantme {echo "select 'grant SELECT ...

it returned error:
-bash: syntax error near unexpected token `{echo'

so, can u tell how to execute it in linux (any version for windows? I
have cgywin in windows)

--
Thanks again
John


Jun 1 '06 #4
> Here's how you would do it -
1. Connect to the database as SYSADM or DBADM user
2. execute the SQL - "grant DBADM on database to user <your-id>"

-- Jayesh


Thanks Jayesh.

It's good but let's say user1 create table, then when user2 login and
tried to use tables created by user1, user2 has to use like

select * from user1.table;

How to make tables created by user1, for other users use it without
specifying schema, just

like select * from table, as user1 uses?

--
Thanks
John

Jun 1 '06 #5
db2 currently lacks an oracle-style concept of public schema, but that
does not matter so much because you have at least these alternate ways
of addressing the objects.

(a) after user2 successfully connects to the database, have that user
perform "set schema user1" to ensure that any unqualified names
mentioned by user2 map to the user1 schema (assuming that user2 has
privileges to access those objects).
That setting of the default schema for the connection can be done
interactively or programatically, possibly by db2cli.ini configuration
also.

(b) create a set of aliases so that some or all of the objects in the
user1 schema
are visible (via those aliases) from the user2 schema. Example: create
alias user2.some_table for user1.some_table. Assumes that user2 has
privileges to access the objects in the user1 schema.



jo******@canada.com wrote:
Here's how you would do it -
1. Connect to the database as SYSADM or DBADM user
2. execute the SQL - "grant DBADM on database to user <your-id>"

-- Jayesh


Thanks Jayesh.

It's good but let's say user1 create table, then when user2 login and
tried to use tables created by user1, user2 has to use like

select * from user1.table;

How to make tables created by user1, for other users use it without
specifying schema, just

like select * from table, as user1 uses?

--
Thanks
John


Jun 2 '06 #6
John,

You can also do the same in an SQL Procedure using EXECUTE IMMEDIATE.
that will be portable. (there are plenty of examples doing DDL in
procedures)

Cheers
Serge

--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Jun 2 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Charles Cantrell | last post by:
I have recently set up mySQL on a Mandrake release of Linux (Version 7 of Mandrake, I believe), using the binary 4.0.13 standard release. The set up and start up all were normal, as far as I...
0
by: Peter Gorelczenko | last post by:
I'm running as normal user (not root or database owner). This user has c= reate=20 temporary table priv. show tables partial: GRANT CREATE TEMPORARY TABLES ON `foobar0`.* TO 'foo'@'localhost'...
0
by: taf | last post by:
Hi, I've installed 4.0.13 on a WinXP system. The service starts and stops just fine, but I cannot connect to the server, nor can I ping the 3306 port. I think the problem may be failure to...
1
by: Adam Smith | last post by:
I have a new DB provided by my ISP don't know details of installation, setup etc. I can log in as anybody except root. mysql -h localhost -u mysql Welcome to the MySQL monitor. Commands end...
3
by: Chris Ochs | last post by:
Is there a shortcut to grant all privileges on a schema and it's objects to a user without having to issue GRANT statements for each individual object in the schema? Given all the possible types...
0
by: Serman D. | last post by:
Hi, I can't understand why mysql allows me to grant lock tables to all tables in a particular database, while it fails to accept the same command applied to a single table only. I've tested on...
0
by: svgeorge | last post by:
I want to update several tables using one stored procedure. How can i do this I mean the syntax.etc. declaration etc. I know the basic syntax as below CREATE PROCEDURE <Procedure_Name, sysname,...
3
by: Gladiator | last post by:
Any Suggestions on the below scenario will be helpful to us. # There are 10 tables in a schema “S1” and I have to give select privilege (Only read access) to a user on all the tables in the...
7
by: MNNovice | last post by:
Please forgive me for this is a long request. I am designing a DB to capture expenses related to Federal Grants and to generate appropriate reports. Each grant starts with a Notice of Grant Award...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.