打印本文 打印本文 关闭窗口 关闭窗口
PowerBuilder Plugins and Internet Explorer
作者:武汉SEO闵涛  文章来源:敏韬网  点击数868  更新时间:2009/4/22 23:09:14  文章录入:mintao  责任编辑:mintao

liminating the need to preface the object name with the owner name

  Many developers create all their objects with dba as the owner.This is reasonable since the dba user is already on the database and has rights to everything in the system.The problem comes when adding users to the system and granting them rights to the database objects.Most developers start out like this:

CREATE TABLE mytable (mycolumn CHAR(10) PRIMARY KEY)
GRANT CONNECT TO mygroup
GRANT GROUP TO mygroup
GRANT CONNECT TO myuser IDENTIFIED BY mypassword
GRANT MEMBERSHIP IN GROUP mygroup TO myuser
GRANT SELECT,INSERT,UPDATE,DELETE ON mytable TO mygroup

  This works just fine if you construct your queries like this:

SELECT * FROM "dba"."mytable" 

  However, if the query is constructed like this and executed by "myuser" then it will fail with a "Table 'mytable' not found" error:

SELECT * FROM "mytable"

  The following query will work, however some problems have been seen with earlier versions of the database engine where it didn't like to see the dba user without double quotes around it.  

SELECT * FROM dba."mytable"

  "dba" is also a keyword and that can cause problems.

  To completely eliminate the need to preface the object name with the name of the owner you should upgrade the "dba" user to a group and then grant rights off of that group.  Here is a sample of how to do it.

GRANT GROUP TO "dba"
CREATE TABLE mytable (mycolumn CHAR(10) PRIMARY KEY)
GRANT CONNECT TO mygroup
GRANT GROUP TO mygroup
GRANT MEMBERSHIP IN GROUP "dba" TO mygroup
GRANT CONNECT TO myuser IDENTIFIED BY mypassword
GRANT MEMBERSHIP IN GROUP mygroup TO myuser
GRANT SELECT,INSERT,UPDATE,DELETE ON mytable TO mygroup

  Once this is completed the following query will work just fine when logged in as "myuser":

SELECT * from "mytable"

  An Alternative

  Some developers prefer to not have the "dba" user as the owner of all the objects.  Much of this preference stems from the use of dba as a keyword.  To resolve this, create a new user, upgrade the user to a group and then create all objects with that user as the owner.

  One Reason To Avoid Prefacing

  During development it is often necessary for developers to create their own tables to test with.  If your application prefaces all the database objects with the owner name then the developer cannot utilize the temporary table.  For example:

CONNECT USER dba IDENTIFIED BY sql
CREATE TABLE "dba". "mytable" (mycolumn CHAR(10) PRIMARY KEY)
CONNECT USER developer1 IDENTIFIED BY password
CREATE TABLE "mytable" (mycolumn CHAR(10) PRIMARY KEY)
Now, when the user "developer1" queries "mytable" they will be 
working against their own table instead of the table that is owned by "dba":
SELECT * from "mytable"

  In PowerBuilder if you are logged in to the database as the owner of the objects then the SQL painters will construct SQL without the owner name.  If you are logged in as a user other than the owner (but with rights to the object) then your SQL will be constructed with the owner name prefacing the objects.

打印本文 打印本文 关闭窗口 关闭窗口