Results 1 to 8 of 8
  1. #1
    Join Date
    Aug 2002
    Posts
    5

    Question Unanswered: Joining one database table with other database table in stroed procedures.

    Hi All,
    I need to perform a join on table1 of database1 with table2 or database2, in a stored procedure and return to my web application.. For this I'm providing execute permission on stored procedure, in database1 and "SELECT" permission on database2 table 2, to my database webuser.
    Is there any way ( Another stored procedure in database2), i can get join on two tables without SELECT permission right on table2 ( or table1).
    Purely using stored procedures. If so how?

  2. #2
    Join Date
    Feb 2002
    Location
    Houston, TX
    Posts
    809
    Normally you only need to grant execute permission on a stored procedure not select permission on the underlying tables.

    Past that I would setup a sp to on database1 to return the data and make sure the webuser has an a security path from database1 to database2. How do yo uhave security setup for this user on databse1 and database2?
    Paul Young
    (Knowledge is power! Get some!)

  3. #3
    Join Date
    Aug 2002
    Posts
    5
    Hi Paul,
    Thanks, What is meant by security path? I didnot get ur point.
    User have only public permission on both databases. Is it not enough? I do have execute permission on sp1 (Stored Procedure) in database1.
    but in sp1 I have a select statement which is a join on database2 table-'table2'. When I tried to execute sp1 from web application only with execute permission on sp1-
    I got an error as Webuser does not have 'SELECT' permission on table2 of database2. So I provided it and sp1 worked fine. But I don't want to use a SELECT permission- What is alternate, for the join.
    sp1 has simple
    SELECT *
    FROM database1.dbo.table1 t1
    INNER JOIN database2.dbo.table2 t2
    ON (t1.col1 = t2.col1)

    Originally posted by Paul Young
    Normally you only need to grant execute permission on a stored procedure not select permission on the underlying tables.

    Past that I would setup a sp to on database1 to return the data and make sure the webuser has an a security path from database1 to database2. How do yo uhave security setup for this user on databse1 and database2?

  4. #4
    Join Date
    Feb 2002
    Location
    Houston, TX
    Posts
    809
    by security path I was refering to how a user gets authenticated on server2 when making a connection from server1.

    You might try using OPENQUERY to call a stored procedure on server2 and use the results to join to a table on server1. I haven't had the need for this in the past so I am working on theory here. Check BOL for usage on OPENQUERY, they have some good examples.
    Paul Young
    (Knowledge is power! Get some!)

  5. #5
    Join Date
    Aug 2002
    Posts
    15
    When calling a stored proc from database 1, you need execute privs on the proc. You do not need to give the user privs on the table itself as long as it is in database 1, too. If database 2 is owned by the same user that is the owner of database 1, you do not need explicit permissions on the object in table 2 accessed by the proc. However, if the database owners are different for the two databases, the user calling the proc must have explicit permissions in the second database.

    If need be, you can change the database owner by:

    EXEC sp_changedbowner 'username'

    Execute this in the database you want to change.

  6. #6
    Join Date
    Aug 2002
    Posts
    5
    Well Both databases are on same server. Is OPENQUERY solve in this case too?

  7. #7
    Join Date
    Aug 2002
    Posts
    15
    Originally posted by soumyag
    Well Both databases are on same server.
    It doesn't matter what server they are on, the owner of the databases is what matters. You can have multiple databases on the same server with different owners. In query analyzer, run:

    sp_helpdb

    It will list the owner for each of the databases. If the owner is different, run sp_changedbowner to set them the same.

  8. #8
    Join Date
    Aug 2002
    Posts
    5
    Hi,
    Both are on same server, but owned by different users. And I don't have any right to change the dbowners But how it will help in writing a join on tables. What is other alternative way to solve this problem.
    Thanks.

    Originally posted by bglass


    It doesn't matter what server they are on, the owner of the databases is what matters. You can have multiple databases on the same server with different owners. In query analyzer, run:

    sp_helpdb

    It will list the owner for each of the databases. If the owner is different, run sp_changedbowner to set them the same.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •