mySQL Views?

Discussion in 'MySQL' started by cancer10, Feb 11, 2009.

  1. #1
    Hi

    This tutorial explains what VIEWS are and how are they created.

    My Question is that why do we need VIEWS for? Why cannot we use the normal SELECT command and fetch records directly from the main table instead of creating a VIEW first and then display records?


    Thanx
     
    cancer10, Feb 11, 2009 IP
  2. w0tan

    w0tan Peon

    Messages:
    77
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #2
    There are two reasons: security, and writing complex queries.

    In large databases, the database administrator will create views that contain all the information a given person needs to work with. Instead of querying the database directly, the person can query the view. With property security in place, a person can only access the view(s) that they have permission to read and write to.

    Once you work with SQL enough you'll run into certain problems that need to be solved with views. These queries are usually a pain, and until you run into one, it will be hard to grasp the utility of a view.

    Also, you can use views to reuse your code. For example, if you need to write 10 queries, and each query joins 4 tables together, you would make a view containing the SQL to join those 4 tables and then call the view from each of the 10 queries in order to save time.
     
    w0tan, Feb 11, 2009 IP
  3. cancer10

    cancer10 Guest

    Messages:
    364
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    That cleared my query.


    Thanx
     
    cancer10, Feb 11, 2009 IP
  4. dowhile

    dowhile Active Member

    Messages:
    37
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    93
    #4
    I'm also suggesting you to read this Wiki "http://en.wikipedia.org/wiki/View_(database)" article about views.

    "A view is a pre-compiled virtual table...", - also a reason to use views.
     
    dowhile, Feb 13, 2009 IP