How to specify a query as read only

Last post 07-15-2009 11:57 AM by Zippy. 25 replies.
Page 1 of 2 (26 items) 1 2 Next >
Active Topics My Discussions Unanswered Sort Posts: Previous Next
  • 09-04-2008 9:14 AM

    How to specify a query as read only

    Hi all,

     I want to know about ReadOnly SQL Queries.

    And How to create the Readonly Queries?What are the advantages?If anyone know, plz let me know.

    Thanks,
    Dhana

  • 09-04-2008 12:32 PM In reply to

    Re: How to specify a query as read only

    I'm a bit confused as to what exactly you mean by a "readonly query." Queries by their very nature are readonly.

    Do you mean a view? You can make a view readonly by creating an "Instead Of" trigger for Insert, Update, Delete which consists of nothing more than a return statement.
    TommCatt
    In theory, there is no difference between theory and practice. In practice, there is.
  • 09-04-2008 1:13 PM In reply to

    Re: How to specify a query as read only

    Do you mean to say that query is going to just read the data?
    Atul Sharma
    "Problems are opportunities to learn."
    Filed under:
  • 09-04-2008 2:12 PM In reply to

    Re: How to specify a query as read only

    Well, YEAH! A query takes the form "Select ... from ..."

    No matter how hard you try, you can't make any changes to the data with just "Select..." You have to use the non-query commands (Insert, Update, Delete)to change the data.

    This makes me think that you mean something else by "query." Could you be referring to the connection itself?
    TommCatt
    In theory, there is no difference between theory and practice. In practice, there is.
  • 04-01-2009 8:13 AM In reply to

    • Keith
    • Not Ranked
    • Joined on 04-01-2009
    • Posts 1

    Re: How to specify a query as read only

     Perhaps Dhana is thinking of a query with no locks on the table(s) being used?

     e.g.

    SELECT * FROM Customer_tbl WITH (NOLOCK)

  • 04-02-2009 3:23 AM In reply to

    • satya
    • Top 10 Contributor
    • Joined on 11-05-2002
    • United Kingdom
    • Posts 23,751
    • Microsoft MVP
      Moderator

    Re: How to specify a query as read only

    We can see the OP (Dhana) hasn;t followed it up after the Q has been posted, so I think it could be a interview or classroom based question.

    Appreciate your ideas on reply though.

    -Satya S K J

    SQL Server MVP



    Knowledge is Power, you will gain by sharing it. SSQA.net - Invisible contributions to the users & visible success in SQL Community.
  • 06-09-2009 5:04 PM In reply to

    Re: How to specify a query as read only

    I am wondering the very same question. For further clarification there used to be the ability to set a VIEW as 'ReadOnly' in SQL Server 2000 I believe by going into the VIEW properties and then editing its 'Permission' set, though I'm not sure that works any more...or does it? I guess my underlying question is...is there a way to simply flag a VIEW a 'ReadOnly' via some Property, etc.? Instead of having to create empty TRIGGERS, Constraints, etc. Thanks!
  • 06-10-2009 1:28 AM In reply to

    Re: How to specify a query as read only

    Welcome to the forum!

    By definition is a query "read-only", because it is nothing but a request to the database to retrieve some information from there.

    The only way I could imagine (and provided that the view is updatable anyway) is to revoke all but SELECT permisisions from the view.

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Contributing Editor, Writer & Forum Moderator http://www.sql-server-performance.com
    Webmaster: http://www.insidesql.org
    View Frank Kalis's profile on LinkedIn
  • 06-10-2009 3:50 AM In reply to

    Re: How to specify a query as read only

    Not revoke update/insert/delete, but deny, I would think.

    Remember that by granting permission on a view, the permission is valid for the underlying table as well, unless the permission is denied on the table itself for the same grantee.

  • 06-10-2009 4:09 AM In reply to

    Re: How to specify a query as read only

     Good catch! Smile

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Contributing Editor, Writer & Forum Moderator http://www.sql-server-performance.com
    Webmaster: http://www.insidesql.org
    View Frank Kalis's profile on LinkedIn
  • 06-11-2009 2:56 AM In reply to

    • satya
    • Top 10 Contributor
    • Joined on 11-05-2002
    • United Kingdom
    • Posts 23,751
    • Microsoft MVP
      Moderator

    Re: How to specify a query as read only

    As referred by Frank if you are looking to restrict the permissions on any DB object then you have to control the set by referring to Database fixed roles or specific privileges on that table.

    There is no such topic in SQL that implies a QUERY is READ-ONLY, its the permission you need to set on the user to ensure the access is not compromised.

    rcurrie:
    I am wondering the very same question. For further clarification there used to be the ability to set a VIEW as 'ReadOnly' in SQL Server 2000 I believe by going into the VIEW properties and then editing its 'Permission' set, though I'm not sure that works any more...or does it? I guess my underlying question is...is there a way to simply flag a VIEW a 'ReadOnly' via some Property, etc.? Instead of having to create empty TRIGGERS, Constraints, etc. Thanks!

    -Satya S K J

    SQL Server MVP



    Knowledge is Power, you will gain by sharing it. SSQA.net - Invisible contributions to the users & visible success in SQL Community.
  • 06-11-2009 11:50 AM In reply to

    Re: How to specify a query as read only

    Thanks for the replies. I was asking about a view objects in general. Originally (in earlier versions of SQL Server) I thought there was simply a flag you could set on the view object itself that would allow affective 'read-only' operations...like simple select queries, but would therefore disallow any attempt to update the data contained or represented by the view object. It seems this has changed slightly so now you manage permissions on a view object by rights management. Which makes sense I guess...I just thought there was a way to say this view object can only be used to "look into" the database, but not update anything. Thanks!
  • 06-26-2009 10:18 AM In reply to

    • yossi
    • Not Ranked
    • Joined on 06-26-2009
    • Posts 4

    Re: How to specify a query as read only

    Here is an interesting "twist":

    Is there a way to make only certain columns of the view read-only?

  • 06-26-2009 3:09 PM In reply to

    Re: How to specify a query as read only

    INSTEAD OF triggers?

     

    Atul Sharma
    "Problems are opportunities to learn."
    Filed under:
  • 06-26-2009 3:15 PM In reply to

    • yossi
    • Not Ranked
    • Joined on 06-26-2009
    • Posts 4

    Re: How to specify a query as read only

    That's right.  Instead of triggers.  Is there SQL keyword specifying that a particular column in a view is read only?

Page 1 of 2 (26 items) 1 2 Next >
Active Topics   My Discussions    Unanswered Posts


© 2010 Jude O'Kelly All Rights Reserved.