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. Other Discussions
  3. The Weird and The Wonderful
  4. A database view that affects the underlying data?!

A database view that affects the underlying data?!

Scheduled Pinned Locked Moved The Weird and The Wonderful
databasequestion
24 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.
  • B Brisingr Aerowing

    Whiskey. Tango. Foxtrot. Whoever wrote that view needs to be drawn and quartered. Then each piece quartered again. Then those chunks dumped into a lava pit. It's called a VIEW for a reason, people!

    What do you get when you cross a joke with a rhetorical question? The metaphorical solid rear-end expulsions have impacted the metaphorical motorized bladed rotating air movement mechanism. Do questions with multiple question marks annoy you???

    L Offline
    L Offline
    Lost User
    wrote on last edited by
    #4

    Brisingr Aerowing wrote:

    Whoever wrote that view needs to be drawn and quartered. Then each piece quartered again. Then those chunks dumped into a lava pit.It's called a VIEW for a reason, people!

    I am thinking it isn't actually the developer of the view but the dev of the queries for the view. A view can't actually change the data as it is or its not a "view" per say, but any idiot could have put some insertion or anything with in a query that is accessed when a view is accessed. Granted, probably the same developer but not necessarily.

    Computers have been intelligent for a long time now. It just so happens that the program writers are about as effective as a room full of monkeys trying to crank out a copy of Hamlet. The interesting thing about software is it can not reproduce, until it can.

    L 2 Replies Last reply
    0
    • L Lost User

      Brisingr Aerowing wrote:

      Whoever wrote that view needs to be drawn and quartered. Then each piece quartered again. Then those chunks dumped into a lava pit.It's called a VIEW for a reason, people!

      I am thinking it isn't actually the developer of the view but the dev of the queries for the view. A view can't actually change the data as it is or its not a "view" per say, but any idiot could have put some insertion or anything with in a query that is accessed when a view is accessed. Granted, probably the same developer but not necessarily.

      Computers have been intelligent for a long time now. It just so happens that the program writers are about as effective as a room full of monkeys trying to crank out a copy of Hamlet. The interesting thing about software is it can not reproduce, until it can.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #5

      N_tro_P wrote:

      A view can't actually change the data as it is or its not a "view" per say

      ..if the underlying data changes, and they request the results of the same view two weeks later? You expect the same results, or new ones?

      Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^][](X-Clacks-Overhead: GNU Terry Pratchett)

      P L 2 Replies Last reply
      0
      • J Jeremy Falcon

        Wait, that's actually allowed? In all my years I've never attempted to update the DB in a view. I mean who would? :wtf:

        Jeremy Falcon

        K Offline
        K Offline
        kmoorevs
        wrote on last edited by
        #6

        Yep, I found this out a couple of weeks ago when faced with a challenging client who insists on keeping two systems (databases)...one receives data automatically as a daily scheduled task from their receiving and pos systems while the other holds the same data but in monthly summary, and after passing through the accounting dept/system. Looking for an easy way to keep 95% of the shared tables in synch, I decided to try recreating the shared tables as views in one of the databases. I was fully expecting an error when creating a new record in a view...but it did what it wasn't supposed to do. :confused: It still confuses me, but at least it solves the problem at hand. :laugh:

        "Go forth into the source" - Neal Morse

        J L P 3 Replies Last reply
        0
        • K kmoorevs

          Yep, I found this out a couple of weeks ago when faced with a challenging client who insists on keeping two systems (databases)...one receives data automatically as a daily scheduled task from their receiving and pos systems while the other holds the same data but in monthly summary, and after passing through the accounting dept/system. Looking for an easy way to keep 95% of the shared tables in synch, I decided to try recreating the shared tables as views in one of the databases. I was fully expecting an error when creating a new record in a view...but it did what it wasn't supposed to do. :confused: It still confuses me, but at least it solves the problem at hand. :laugh:

          "Go forth into the source" - Neal Morse

          J Offline
          J Offline
          Jeremy Falcon
          wrote on last edited by
          #7

          Oh... Emmm... Gee

          Jeremy Falcon

          1 Reply Last reply
          0
          • K kmoorevs

            Yep, I found this out a couple of weeks ago when faced with a challenging client who insists on keeping two systems (databases)...one receives data automatically as a daily scheduled task from their receiving and pos systems while the other holds the same data but in monthly summary, and after passing through the accounting dept/system. Looking for an easy way to keep 95% of the shared tables in synch, I decided to try recreating the shared tables as views in one of the databases. I was fully expecting an error when creating a new record in a view...but it did what it wasn't supposed to do. :confused: It still confuses me, but at least it solves the problem at hand. :laugh:

            "Go forth into the source" - Neal Morse

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #8

            Access?

            Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^][](X-Clacks-Overhead: GNU Terry Pratchett)

            K 1 Reply Last reply
            0
            • L Lost User

              Access?

              Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^][](X-Clacks-Overhead: GNU Terry Pratchett)

              K Offline
              K Offline
              kmoorevs
              wrote on last edited by
              #9

              Eddy Vluggen wrote:

              Access?

              No, SQL Server...haven't tried it in Access.

              "Go forth into the source" - Neal Morse

              1 Reply Last reply
              0
              • K kmoorevs

                Yep, I found this out a couple of weeks ago when faced with a challenging client who insists on keeping two systems (databases)...one receives data automatically as a daily scheduled task from their receiving and pos systems while the other holds the same data but in monthly summary, and after passing through the accounting dept/system. Looking for an easy way to keep 95% of the shared tables in synch, I decided to try recreating the shared tables as views in one of the databases. I was fully expecting an error when creating a new record in a view...but it did what it wasn't supposed to do. :confused: It still confuses me, but at least it solves the problem at hand. :laugh:

                "Go forth into the source" - Neal Morse

                P Online
                P Online
                PIEBALDconsult
                wrote on last edited by
                #10

                I think that's different (but still not a good idea) in this case I'm "just reading" from the view, but apparently something (a function or who knows what) is making changes.

                Richard DeemingR 1 Reply Last reply
                0
                • L Lost User

                  N_tro_P wrote:

                  A view can't actually change the data as it is or its not a "view" per say

                  ..if the underlying data changes, and they request the results of the same view two weeks later? You expect the same results, or new ones?

                  Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^][](X-Clacks-Overhead: GNU Terry Pratchett)

                  P Online
                  P Online
                  PIEBALDconsult
                  wrote on last edited by
                  #11

                  That depends on what's backing it. In many cases, the tables are "live" and you expect the latest data every time you read the view. In other cases, the tables are in a "reporting" database that might contain "the state of the data as of close-of-business yesterday" and you would not expect different data throughout the day. In that case, something would update the reporting database in the evening. But, it seems like somehow they got this view to perform that update! So they want others (me) to call it once in the evening, but not during the day. :sigh: I'd rather get the updated data, but others are reported as being "confused" by having the data change. :badger:

                  1 Reply Last reply
                  0
                  • P PIEBALDconsult

                    I think that's different (but still not a good idea) in this case I'm "just reading" from the view, but apparently something (a function or who knows what) is making changes.

                    Richard DeemingR Offline
                    Richard DeemingR Offline
                    Richard Deeming
                    wrote on last edited by
                    #12

                    I'm struggling to see how that would be possible. :confused:

                    • A view cannot insert, update, or delete any records. It can only select records.
                    • A view can select from a table-valued function, but a TVF cannot insert, update, or delete records. Neither can it call a stored procedure, or use temporary tables.
                    • You can't create a trigger that would fire when records are selected from a table or view. And you can't create triggers on TVFs at all.

                    "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                    "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

                    J P 2 Replies Last reply
                    0
                    • Richard DeemingR Richard Deeming

                      I'm struggling to see how that would be possible. :confused:

                      • A view cannot insert, update, or delete any records. It can only select records.
                      • A view can select from a table-valued function, but a TVF cannot insert, update, or delete records. Neither can it call a stored procedure, or use temporary tables.
                      • You can't create a trigger that would fire when records are selected from a table or view. And you can't create triggers on TVFs at all.

                      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

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

                      Richard Deeming wrote:

                      A view cannot insert, update, or delete any records. It can only select records.

                      Actually it can under some circumstances

                      MSDN wrote:

                      You can modify the data of an underlying base table through a view, as long as the following conditions are true: Any modifications, including UPDATE, INSERT, and DELETE statements, must reference columns from only one base table. The columns being modified in the view must directly reference the underlying data in the table columns. The columns cannot be derived in any other way, such as through the following: An aggregate function: AVG, COUNT, SUM, MIN, MAX, GROUPING, STDEV, STDEVP, VAR, and VARP. A computation. The column cannot be computed from an expression that uses other columns. Columns that are formed by using the set operators UNION, UNION ALL, CROSSJOIN, EXCEPT, and INTERSECT amount to a computation and are also not updatable. The columns being modified are not affected by GROUP BY, HAVING, or DISTINCT clauses. TOP is not used anywhere in the select_statement of the view together with the WITH CHECK OPTION clause.

                      CREATE VIEW (Transact-SQL) - MSDN[^] <edit>BTW, most databases support it since it's standardized in SQL-92</edit>

                      Wrong is evil and must be defeated. - Jeff Ello

                      Richard DeemingR 1 Reply Last reply
                      0
                      • J Jorgen Andersson

                        Richard Deeming wrote:

                        A view cannot insert, update, or delete any records. It can only select records.

                        Actually it can under some circumstances

                        MSDN wrote:

                        You can modify the data of an underlying base table through a view, as long as the following conditions are true: Any modifications, including UPDATE, INSERT, and DELETE statements, must reference columns from only one base table. The columns being modified in the view must directly reference the underlying data in the table columns. The columns cannot be derived in any other way, such as through the following: An aggregate function: AVG, COUNT, SUM, MIN, MAX, GROUPING, STDEV, STDEVP, VAR, and VARP. A computation. The column cannot be computed from an expression that uses other columns. Columns that are formed by using the set operators UNION, UNION ALL, CROSSJOIN, EXCEPT, and INTERSECT amount to a computation and are also not updatable. The columns being modified are not affected by GROUP BY, HAVING, or DISTINCT clauses. TOP is not used anywhere in the select_statement of the view together with the WITH CHECK OPTION clause.

                        CREATE VIEW (Transact-SQL) - MSDN[^] <edit>BTW, most databases support it since it's standardized in SQL-92</edit>

                        Wrong is evil and must be defeated. - Jeff Ello

                        Richard DeemingR Offline
                        Richard DeemingR Offline
                        Richard Deeming
                        wrote on last edited by
                        #14

                        But that's only if you issue an INSERT, UPDATE or DELETE statement against the view. My interpretation of PIEBALDconsult's message is that he's only reading the view - a SELECT statement. And I can't think of any way that a SELECT statement against a view could modify the underlying data.


                        "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                        "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

                        P J 2 Replies Last reply
                        0
                        • Richard DeemingR Richard Deeming

                          I'm struggling to see how that would be possible. :confused:

                          • A view cannot insert, update, or delete any records. It can only select records.
                          • A view can select from a table-valued function, but a TVF cannot insert, update, or delete records. Neither can it call a stored procedure, or use temporary tables.
                          • You can't create a trigger that would fire when records are selected from a table or view. And you can't create triggers on TVFs at all.

                          "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                          P Online
                          P Online
                          PIEBALDconsult
                          wrote on last edited by
                          #15

                          Yeah, I don't know either. If they're not smart enough to know not to do it, then they're probably not smart enough to know how to do it. I can imagine a CLR function that could pull data from somewhere, but that's just not a good idea. For example SELECT id , name , GetManagerID(id) FROM usertable And in the background, the GetManagerID function accesses LDAP and refills the usertable or something.

                          1 Reply Last reply
                          0
                          • Richard DeemingR Richard Deeming

                            But that's only if you issue an INSERT, UPDATE or DELETE statement against the view. My interpretation of PIEBALDconsult's message is that he's only reading the view - a SELECT statement. And I can't think of any way that a SELECT statement against a view could modify the underlying data.


                            "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

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

                            I got the impression he's "reading" the view via an SP or similar.

                            Piebald wrote:

                            in this case I'm "just reading" from the view, but apparently something (a function or who knows what) is making changes.

                            Anyway, that means I misread what you wrote.

                            Wrong is evil and must be defeated. - Jeff Ello

                            P 1 Reply Last reply
                            0
                            • Richard DeemingR Richard Deeming

                              But that's only if you issue an INSERT, UPDATE or DELETE statement against the view. My interpretation of PIEBALDconsult's message is that he's only reading the view - a SELECT statement. And I can't think of any way that a SELECT statement against a view could modify the underlying data.


                              "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                              P Online
                              P Online
                              PIEBALDconsult
                              wrote on last edited by
                              #17

                              Exactly. That's been covered.

                              1 Reply Last reply
                              0
                              • J Jorgen Andersson

                                I got the impression he's "reading" the view via an SP or similar.

                                Piebald wrote:

                                in this case I'm "just reading" from the view, but apparently something (a function or who knows what) is making changes.

                                Anyway, that means I misread what you wrote.

                                Wrong is evil and must be defeated. - Jeff Ello

                                P Online
                                P Online
                                PIEBALDconsult
                                wrote on last edited by
                                #18

                                An ETL in SSIS actually, but that's just details, if I say SELECT ... FROM someview that should cause the data to change.

                                J 1 Reply Last reply
                                0
                                • P PIEBALDconsult

                                  An ETL in SSIS actually, but that's just details, if I say SELECT ... FROM someview that should cause the data to change.

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

                                  Then the only possibility I can think of is if some idiot (IMHO) has created a trigger on the view.

                                  Wrong is evil and must be defeated. - Jeff Ello

                                  Richard DeemingR 1 Reply Last reply
                                  0
                                  • L Lost User

                                    N_tro_P wrote:

                                    A view can't actually change the data as it is or its not a "view" per say

                                    ..if the underlying data changes, and they request the results of the same view two weeks later? You expect the same results, or new ones?

                                    Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^][](X-Clacks-Overhead: GNU Terry Pratchett)

                                    L Offline
                                    L Offline
                                    Lost User
                                    wrote on last edited by
                                    #20

                                    Eddy Vluggen wrote:

                                    You expect the same results, or new ones?

                                    As another said it depends. Not all vies are static and will report on new data rather than a slice. Depends on how the view was built, but that is not what the OP is really about. It sounds more like a view was causing the data to actually change meaning a query was doing adding to the data set which is against all view policies.

                                    Computers have been intelligent for a long time now. It just so happens that the program writers are about as effective as a room full of monkeys trying to crank out a copy of Hamlet. The interesting thing about software is it can not reproduce, until it can.

                                    L 1 Reply Last reply
                                    0
                                    • L Lost User

                                      Brisingr Aerowing wrote:

                                      Whoever wrote that view needs to be drawn and quartered. Then each piece quartered again. Then those chunks dumped into a lava pit.It's called a VIEW for a reason, people!

                                      I am thinking it isn't actually the developer of the view but the dev of the queries for the view. A view can't actually change the data as it is or its not a "view" per say, but any idiot could have put some insertion or anything with in a query that is accessed when a view is accessed. Granted, probably the same developer but not necessarily.

                                      Computers have been intelligent for a long time now. It just so happens that the program writers are about as effective as a room full of monkeys trying to crank out a copy of Hamlet. The interesting thing about software is it can not reproduce, until it can.

                                      L Offline
                                      L Offline
                                      Lost User
                                      wrote on last edited by
                                      #21

                                      Or even better: Some triggers.

                                      The language is JavaScript. that of Mordor, which I will not utter here
                                      This is Javascript. If you put big wheels and a racing stripe on a golf cart, it's still a fucking golf cart.
                                      "I don't know, extraterrestrial?" "You mean like from space?" "No, from Canada." If software development were a circus, we would all be the clowns.

                                      1 Reply Last reply
                                      0
                                      • L Lost User

                                        Eddy Vluggen wrote:

                                        You expect the same results, or new ones?

                                        As another said it depends. Not all vies are static and will report on new data rather than a slice. Depends on how the view was built, but that is not what the OP is really about. It sounds more like a view was causing the data to actually change meaning a query was doing adding to the data set which is against all view policies.

                                        Computers have been intelligent for a long time now. It just so happens that the program writers are about as effective as a room full of monkeys trying to crank out a copy of Hamlet. The interesting thing about software is it can not reproduce, until it can.

                                        L Offline
                                        L Offline
                                        Lost User
                                        wrote on last edited by
                                        #22

                                        N_tro_P wrote:

                                        It sounds more like a view was causing the data to actually change meaning a query was doing adding to the data set which is against all view policies.

                                        A view does not have side-effects. Adding a row is not the same as a view with side-effects :)

                                        Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^][](X-Clacks-Overhead: GNU Terry Pratchett)

                                        1 Reply Last reply
                                        0
                                        • J Jorgen Andersson

                                          Then the only possibility I can think of is if some idiot (IMHO) has created a trigger on the view.

                                          Wrong is evil and must be defeated. - Jeff Ello

                                          Richard DeemingR Offline
                                          Richard DeemingR Offline
                                          Richard Deeming
                                          wrote on last edited by
                                          #23

                                          SQL Server doesn't let you create a trigger that fires on a SELECT.


                                          "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                                          "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

                                          J 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