SitePoint Sponsor

User Tag List

Page 3 of 3 FirstFirst 123
Results 51 to 57 of 57
  1. #51
    Spirit Coder allspiritseve's Avatar
    Join Date
    Dec 2002
    Location
    Ann Arbor, MI (USA)
    Posts
    648
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by BerislavLopac View Post
    It is not impossible to have models represented by joins, even in moderately complex systems. But if such models are needed on a regular basis they're much better represented in the DB itself using a view, which can be easily accessed as a standard table.
    Does this 'database view' have to actually be located in the database, or could I maybe create a view class that works like a table data gateway, except instead of accessing a table, it accesses a specific group of tables? Or is there some reason why that wouldn't work?

    Quote Originally Posted by Mastodont
    vbmenu_register("postmenu_3607535", true);Query functions return results (as resource). If you convert them into arrays, you need to traverse this raw array for the second time to get formatted output.


    IMHO is better pass directly results, although you have to write formatting objects for each type of db separately.
    I have data that takes two queries to compile. Can I save both of these resources and access each without affecting the other?

  2. #52
    SitePoint Guru BerislavLopac's Avatar
    Join Date
    Sep 2004
    Location
    Zagreb, Croatia
    Posts
    830
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by allspiritseve View Post
    Does this 'database view' have to actually be located in the database, or could I maybe create a view class that works like a table data gateway, except instead of accessing a table, it accesses a specific group of tables? Or is there some reason why that wouldn't work?
    The whole idea of the view is to keep the data in the database. View (in this sense) is a relational DB concept, defined in the RDB theory -- see http://en.wikipedia.org/wiki/View_%28database%29

  3. #53
    Spirit Coder allspiritseve's Avatar
    Join Date
    Dec 2002
    Location
    Ann Arbor, MI (USA)
    Posts
    648
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by BerislavLopac View Post
    The whole idea of the view is to keep the data in the database. View (in this sense) is a relational DB concept, defined in the RDB theory -- see http://en.wikipedia.org/wiki/View_%28database%29
    Ok, if I create a view in my database, will that allow me full CRUD operations on the view, or is it a read-only kind of thing?

  4. #54
    SitePoint Guru BerislavLopac's Avatar
    Join Date
    Sep 2004
    Location
    Zagreb, Croatia
    Posts
    830
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Read the Wikipedia link. It depends on the database you use.

  5. #55
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    On views and mysql 5.1, new information for me.

    Quote Originally Posted by Mysql-Man
    30.6.6: Can you insert into views that are based on joins?

    It is possible, provided that your INSERT statement has a column list that makes it clear there's only one table involved.

    You cannot insert into multiple tables with a single insert on a view.
    http://dev.mysql.com/doc/refman/5.1/en/faqs-views.html
    Have I understood this correctly, if your view is made up from a join, lets say its made up from people.name and balance.current, if you update balance.current in the view, that will in turn update the static table?

  6. #56
    SitePoint Addict
    Join Date
    Feb 2006
    Posts
    281
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Forget about views and trigger functions unless you are accessing the same database with multiple applications.

  7. #57
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Cups View Post
    Have I understood this correctly, if your view is made up from a join, lets say its made up from people.name and balance.current, if you update balance.current in the view, that will in turn update the static table?
    Yes, but with some limitations. Basically, if the view is just a couple of joined tables, it will work fine; Just like you can update to a joined query.

    I should warn though, that MySql's support for views is rather limited. They work, but in some cases, they are very inefficient.

    Quote Originally Posted by blueyon View Post
    Forget about views and trigger functions unless you are accessing the same database with multiple applications.
    I don't think it's right to say that views are only useful for applications, with multiple frontends. Views are an abstraction, and as such quite a useful tool. If you have a large database, with properly normalised data, you'd often end up joining dozens of tables for your queries. Views help making this more manageable. Views can also be used for decoupling dependencies within the database. For example, a rule could be that tables are divided into logical groups (modules). Each module can internally use tables, but if a module uses tables from another module, it must go through that modules views. This is akin to protected/public properties in objects.


Bookmarks

Posting Permissions

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