Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Views vs Tables

Views vs Tables

Scheduled Pinned Locked Moved Database
databasesql-servervisual-studioquestion
25 Posts 7 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J jschell

    Eric Whitmore wrote:

    if I do "inserts" into "tables" I am doing it "wrong

    You should ask why. There could be an architectural reason such as an intent to move to another schema or legacy reasons. Could just be an odd way to provide a database layer though. For that though I use stored procs.

    P Offline
    P Offline
    PIEBALDconsult
    wrote on last edited by
    #8

    jschell wrote:

    I use stored procs

    Right, I don't (willingly), but I know many do and, of the two techniques, procedures make more sense.

    1 Reply Last reply
    0
    • M Mycroft Holmes

      I ran across this attitude in the 90s (and not since) I believe it was based on security, there was a difference between table and view security back then. I would be very interested in your DBAs reasoning behind the statement. PieBald You can insert into views if there is 1 table in the view (how dumb is that) or the relationships are not too complex. I have never explored this as I also think it is a horror waiting to happen.

      Never underestimate the power of human stupidity RAH

      P Offline
      P Offline
      PIEBALDconsult
      wrote on last edited by
      #9

      Mycroft Holmes wrote:

      in the 90s

      At that time I was using Oracle (6) and I remember asking the DBAs why the views (there weren't many) had an _v suffix and the response was "to remind the developers that they are views and therefore readonly".

      M 1 Reply Last reply
      0
      • P PIEBALDconsult

        Mycroft Holmes wrote:

        in the 90s

        At that time I was using Oracle (6) and I remember asking the DBAs why the views (there weren't many) had an _v suffix and the response was "to remind the developers that they are views and therefore readonly".

        M Offline
        M Offline
        Mycroft Holmes
        wrote on last edited by
        #10

        I think I was working with MSSQL 6.5! Try creating a view of only 1 table, no joins, and inserting/editing a record. Now add an inner join and repeat. Even though I have SSMS open I'll not bother as it is a complete WOTAM.

        Never underestimate the power of human stupidity RAH

        1 Reply Last reply
        0
        • P PIEBALDconsult

          You may have misunderstodd, or he's wrong. I've never heard of inserting into views, a view is essentially readonly, you have no idea how the data feeding it is structured -- one of the benefits of views. Then again databases have advanced quite a bit in the last twenty years and I may be behind the times. It may be that some versions of some databases support it in some cases, but I would never do it.

          G Offline
          G Offline
          GuyThiebaut
          wrote on last edited by
          #11

          I recently tested updates on a mock view, in SQL Server 2008, which contained a join between two tables. I did this because where I work the majority of what our users see is through views and they occasionally need to update what they see. I read up on it beforehand and all the documentation pointed to this being possible as long as it was unambiguous as to which row in which table was being updated. The update did work - I then tried to break it and succeeded by using an aggregate function in the view so that there was ambiguity in what would be updated. It can be useful to insert or update a view, since if one is passing a view into a control then it is easier to perform an update, on the source of that control, than to have to attach lots of meta data documenting which tables to update.

          “That which can be asserted without evidence, can be dismissed without evidence.”

          ― Christopher Hitchens

          P J 2 Replies Last reply
          0
          • G GuyThiebaut

            I recently tested updates on a mock view, in SQL Server 2008, which contained a join between two tables. I did this because where I work the majority of what our users see is through views and they occasionally need to update what they see. I read up on it beforehand and all the documentation pointed to this being possible as long as it was unambiguous as to which row in which table was being updated. The update did work - I then tried to break it and succeeded by using an aggregate function in the view so that there was ambiguity in what would be updated. It can be useful to insert or update a view, since if one is passing a view into a control then it is easier to perform an update, on the source of that control, than to have to attach lots of meta data documenting which tables to update.

            “That which can be asserted without evidence, can be dismissed without evidence.”

            ― Christopher Hitchens

            P Offline
            P Offline
            PIEBALDconsult
            wrote on last edited by
            #12

            GuyThiebaut wrote:

            passing a view into a control

            But that's not a good idea. It doesn't lead to a properly layered application.

            GuyThiebaut wrote:

            aggregate function

            Or a UNION or a CASE , probably if there's CAST or CONVERT ... I suppose it requires that there be a primary key as well.

            G 1 Reply Last reply
            0
            • P PIEBALDconsult

              GuyThiebaut wrote:

              passing a view into a control

              But that's not a good idea. It doesn't lead to a properly layered application.

              GuyThiebaut wrote:

              aggregate function

              Or a UNION or a CASE , probably if there's CAST or CONVERT ... I suppose it requires that there be a primary key as well.

              G Offline
              G Offline
              GuyThiebaut
              wrote on last edited by
              #13

              "But that's not a good idea. It doesn't lead to a properly layered application." - I don't understand why using a view in a control would do this, could you let me know why?

              “That which can be asserted without evidence, can be dismissed without evidence.”

              ― Christopher Hitchens

              J 1 Reply Last reply
              0
              • M Mycroft Holmes

                I ran across this attitude in the 90s (and not since) I believe it was based on security, there was a difference between table and view security back then. I would be very interested in your DBAs reasoning behind the statement. PieBald You can insert into views if there is 1 table in the view (how dumb is that) or the relationships are not too complex. I have never explored this as I also think it is a horror waiting to happen.

                Never underestimate the power of human stupidity RAH

                J Offline
                J Offline
                Jorgen Andersson
                wrote on last edited by
                #14

                Mycroft Holmes wrote:

                You can insert into views if there is 1 table in the view (how dumb is that)

                It's quite useful if you want to filter the contents of a table for a certain group of users.

                "The ones who care enough to do it right care too much to compromise." Matthew Faithfull

                J M 2 Replies Last reply
                0
                • G GuyThiebaut

                  I recently tested updates on a mock view, in SQL Server 2008, which contained a join between two tables. I did this because where I work the majority of what our users see is through views and they occasionally need to update what they see. I read up on it beforehand and all the documentation pointed to this being possible as long as it was unambiguous as to which row in which table was being updated. The update did work - I then tried to break it and succeeded by using an aggregate function in the view so that there was ambiguity in what would be updated. It can be useful to insert or update a view, since if one is passing a view into a control then it is easier to perform an update, on the source of that control, than to have to attach lots of meta data documenting which tables to update.

                  “That which can be asserted without evidence, can be dismissed without evidence.”

                  ― Christopher Hitchens

                  J Offline
                  J Offline
                  jschell
                  wrote on last edited by
                  #15

                  GuyThiebaut wrote:

                  since if one is passing a view into a control then it is easier to perform an updat

                  Control? As in a GUI control? For small systems with stand along apps that might be appropriate. For anything larger one should have a database layer. And of course it won't work at all for a web app.

                  1 Reply Last reply
                  0
                  • G GuyThiebaut

                    "But that's not a good idea. It doesn't lead to a properly layered application." - I don't understand why using a view in a control would do this, could you let me know why?

                    “That which can be asserted without evidence, can be dismissed without evidence.”

                    ― Christopher Hitchens

                    J Offline
                    J Offline
                    jschell
                    wrote on last edited by
                    #16

                    GuyThiebaut wrote:

                    I don't understand why using a view in a control would do this, could you let me know why?

                    Because if you use the view in the GUI then there is no database layer. Nor presumably a business layer for that matter.

                    G 1 Reply Last reply
                    0
                    • J Jorgen Andersson

                      Mycroft Holmes wrote:

                      You can insert into views if there is 1 table in the view (how dumb is that)

                      It's quite useful if you want to filter the contents of a table for a certain group of users.

                      "The ones who care enough to do it right care too much to compromise." Matthew Faithfull

                      J Offline
                      J Offline
                      jschell
                      wrote on last edited by
                      #17

                      Jörgen Andersson wrote:

                      It's quite useful if you want to filter the contents of a table for a certain group of users.

                      Why would you do that in the database versus the application layer? And of course in general when you say 'user' if you mean an actual database user then there can be negative impacts such as licensing.

                      J 1 Reply Last reply
                      0
                      • J Jorgen Andersson

                        Mycroft Holmes wrote:

                        You can insert into views if there is 1 table in the view (how dumb is that)

                        It's quite useful if you want to filter the contents of a table for a certain group of users.

                        "The ones who care enough to do it right care too much to compromise." Matthew Faithfull

                        M Offline
                        M Offline
                        Mycroft Holmes
                        wrote on last edited by
                        #18

                        Jörgen Andersson wrote:

                        f you want to filter the contents of a table for a certain group of users

                        Sure but that is one of the uses of a view - a very old fashioned use, but still valid. Who puts authorisation logic at that level these days. Apps no longer have to rely on the database for authorisation, very 80s :laugh:

                        Never underestimate the power of human stupidity RAH

                        J 1 Reply Last reply
                        0
                        • J jschell

                          GuyThiebaut wrote:

                          I don't understand why using a view in a control would do this, could you let me know why?

                          Because if you use the view in the GUI then there is no database layer. Nor presumably a business layer for that matter.

                          G Offline
                          G Offline
                          GuyThiebaut
                          wrote on last edited by
                          #19

                          There is a database layer - the control is populated via a query from this layer. Any updates to this view are then passed through this layer via update commands. So we can lock down particular columns and perform verification on the values before update so that we both have a business and database layer. So I am still not getting what is wrong with using the results of a view in a GUI.

                          “That which can be asserted without evidence, can be dismissed without evidence.”

                          ― Christopher Hitchens

                          J 1 Reply Last reply
                          0
                          • J jschell

                            Jörgen Andersson wrote:

                            It's quite useful if you want to filter the contents of a table for a certain group of users.

                            Why would you do that in the database versus the application layer? And of course in general when you say 'user' if you mean an actual database user then there can be negative impacts such as licensing.

                            J Offline
                            J Offline
                            Jorgen Andersson
                            wrote on last edited by
                            #20

                            Because some companies are quite divided. The right place to do it is in the application, but I've been working for companies where the database department were responsible for that one department couldn't see the same columns as another department. It's a lot easier to keep track on this with a view than with column permissions. When it comes to licensing it doesn't matter. It's the number of actual users that counts, not the number of users you setup in the database. It's a common misconception.

                            "The ones who care enough to do it right care too much to compromise." Matthew Faithfull

                            J 1 Reply Last reply
                            0
                            • M Mycroft Holmes

                              Jörgen Andersson wrote:

                              f you want to filter the contents of a table for a certain group of users

                              Sure but that is one of the uses of a view - a very old fashioned use, but still valid. Who puts authorisation logic at that level these days. Apps no longer have to rely on the database for authorisation, very 80s :laugh:

                              Never underestimate the power of human stupidity RAH

                              J Offline
                              J Offline
                              Jorgen Andersson
                              wrote on last edited by
                              #21

                              :sigh: I know, see my answer to jschell.

                              "The ones who care enough to do it right care too much to compromise." Matthew Faithfull

                              M 1 Reply Last reply
                              0
                              • J Jorgen Andersson

                                :sigh: I know, see my answer to jschell.

                                "The ones who care enough to do it right care too much to compromise." Matthew Faithfull

                                M Offline
                                M Offline
                                Mycroft Holmes
                                wrote on last edited by
                                #22

                                Yeah I read that and thought poor bastard, I just hope you are not working with one of those old EIS systems as well!

                                Never underestimate the power of human stupidity RAH

                                J 1 Reply Last reply
                                0
                                • M Mycroft Holmes

                                  Yeah I read that and thought poor bastard, I just hope you are not working with one of those old EIS systems as well!

                                  Never underestimate the power of human stupidity RAH

                                  J Offline
                                  J Offline
                                  Jorgen Andersson
                                  wrote on last edited by
                                  #23

                                  I'm at a different place now, with a different set of pains.

                                  Mycroft Holmes wrote:

                                  I just hope you are not working with one of those old EIS systems as well!

                                  Depends on what EIS stands for. If it is Executive Information System, then yes kind of. It's my own design though. It's the users that's the main pain now.

                                  "The ones who care enough to do it right care too much to compromise." Matthew Faithfull

                                  1 Reply Last reply
                                  0
                                  • G GuyThiebaut

                                    There is a database layer - the control is populated via a query from this layer. Any updates to this view are then passed through this layer via update commands. So we can lock down particular columns and perform verification on the values before update so that we both have a business and database layer. So I am still not getting what is wrong with using the results of a view in a GUI.

                                    “That which can be asserted without evidence, can be dismissed without evidence.”

                                    ― Christopher Hitchens

                                    J Offline
                                    J Offline
                                    jschell
                                    wrote on last edited by
                                    #24

                                    GuyThiebaut wrote:

                                    Any updates to this view are then passed through this layer via update commands.

                                    Either you are expressing it incorrectly or there is no layer. You said you used the "view" in the "control". If instead you are using a DTO in the "control" then that is not the same as what you said. If however you are using a language specific layer to access the a view in the control then there is no database layer.

                                    GuyThiebaut wrote:

                                    So I am still not getting what is wrong with using the results of a view in a GUI.

                                    First, the question, per the OP, is why someone would insist that only views be used. It isn't whether views might or might not be used. Second, as I already said your terminology/phrasing is not precise. If you have a database layer then you are not using the view in the GUI. What you are using is the results of the database layer or even business layer in the GUI. The fact that they originated from a view in another layer is irrelevant and expressing it that way should be avoided because data model entity might not originate in a one to one mapping with the database. And the user (GUI) should not concern itself with how it did originate from he database.

                                    1 Reply Last reply
                                    0
                                    • J Jorgen Andersson

                                      Because some companies are quite divided. The right place to do it is in the application, but I've been working for companies where the database department were responsible for that one department couldn't see the same columns as another department. It's a lot easier to keep track on this with a view than with column permissions. When it comes to licensing it doesn't matter. It's the number of actual users that counts, not the number of users you setup in the database. It's a common misconception.

                                      "The ones who care enough to do it right care too much to compromise." Matthew Faithfull

                                      J Offline
                                      J Offline
                                      jschell
                                      wrote on last edited by
                                      #25

                                      Jörgen Andersson wrote:

                                      Because some companies are quite divided.

                                      Certainly. And some companies need to create their own database. But in the general case neither of those are true.

                                      Jörgen Andersson wrote:

                                      It's the number of actual users that counts, not the number of users you setup in the database. It's a common misconception.

                                      I know how it works. The fact that user licensing exists at all specifically indicates that support in the database per user is something that is in fact significant. Unless you are claiming that only a single user connects at a time, then my comment about user licensing stands. And if you are claiming that then it is far from what any normal business would use.

                                      1 Reply Last reply
                                      0
                                      Reply
                                      • Reply as topic
                                      Log in to reply
                                      • Oldest to Newest
                                      • Newest to Oldest
                                      • Most Votes


                                      • Login

                                      • Don't have an account? Register

                                      • Login or register to search.
                                      • First post
                                        Last post
                                      0
                                      • Categories
                                      • Recent
                                      • Tags
                                      • Popular
                                      • World
                                      • Users
                                      • Groups