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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Order in database

Order in database

Scheduled Pinned Locked Moved Database
questioncsharpasp-netdatabase
10 Posts 6 Posters 1 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.
  • S Offline
    S Offline
    srikantha_nagaraj
    wrote on last edited by
    #1

    Hi, Actually i want rows in the table in an order. How can i force the tables to keep that order? is there any command for that. Actually i am inserting the data row from asp.net front end.

    L S A 3 Replies Last reply
    0
    • S srikantha_nagaraj

      Hi, Actually i want rows in the table in an order. How can i force the tables to keep that order? is there any command for that. Actually i am inserting the data row from asp.net front end.

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

      srikantha_nagaraj wrote:

      Actually i want rows in the table in an order.

      Sort the table.

      srikantha_nagaraj wrote:

      How can i force the tables to keep that order?

      By definition, you can't. A table is a collection of rows that's saved in a random order. You can read them back and order by any field that's present within that selection. You could also add a custom field to indicate the order of the rows, but you'd still need to 'order by' that particular field. You can, alternatively, create a stored procedure that selects all your rows and sort them. Next, hide the table and give the user only access to your sproc. That would not stop anyone from re-sorting the dataset though.

      I are Troll :)

      S J 2 Replies Last reply
      0
      • L Lost User

        srikantha_nagaraj wrote:

        Actually i want rows in the table in an order.

        Sort the table.

        srikantha_nagaraj wrote:

        How can i force the tables to keep that order?

        By definition, you can't. A table is a collection of rows that's saved in a random order. You can read them back and order by any field that's present within that selection. You could also add a custom field to indicate the order of the rows, but you'd still need to 'order by' that particular field. You can, alternatively, create a stored procedure that selects all your rows and sort them. Next, hide the table and give the user only access to your sproc. That would not stop anyone from re-sorting the dataset though.

        I are Troll :)

        S Offline
        S Offline
        srikantha_nagaraj
        wrote on last edited by
        #3

        Thanks for the answer. :)

        1 Reply Last reply
        0
        • S srikantha_nagaraj

          Hi, Actually i want rows in the table in an order. How can i force the tables to keep that order? is there any command for that. Actually i am inserting the data row from asp.net front end.

          S Offline
          S Offline
          stendulkar54
          wrote on last edited by
          #4

          Use Order By clause of SQL. It orders the output.

          1 Reply Last reply
          0
          • L Lost User

            srikantha_nagaraj wrote:

            Actually i want rows in the table in an order.

            Sort the table.

            srikantha_nagaraj wrote:

            How can i force the tables to keep that order?

            By definition, you can't. A table is a collection of rows that's saved in a random order. You can read them back and order by any field that's present within that selection. You could also add a custom field to indicate the order of the rows, but you'd still need to 'order by' that particular field. You can, alternatively, create a stored procedure that selects all your rows and sort them. Next, hide the table and give the user only access to your sproc. That would not stop anyone from re-sorting the dataset though.

            I are Troll :)

            J Offline
            J Offline
            J4amieC
            wrote on last edited by
            #5

            Eddy Vluggen wrote:

            srikantha_nagaraj wrote: How can i force the tables to keep that order? By definition, you can't.

            That's not strictly true, Tables will be stored in the order of their clustered index. This then forms the "default" order.

            J I 2 Replies Last reply
            0
            • J J4amieC

              Eddy Vluggen wrote:

              srikantha_nagaraj wrote: How can i force the tables to keep that order? By definition, you can't.

              That's not strictly true, Tables will be stored in the order of their clustered index. This then forms the "default" order.

              J Offline
              J Offline
              J4amieC
              wrote on last edited by
              #6

              Because it escapes me.

              L 1 Reply Last reply
              0
              • J J4amieC

                Eddy Vluggen wrote:

                srikantha_nagaraj wrote: How can i force the tables to keep that order? By definition, you can't.

                That's not strictly true, Tables will be stored in the order of their clustered index. This then forms the "default" order.

                I Offline
                I Offline
                i j russell
                wrote on last edited by
                #7

                That's not strictly true either! The only way to guarantee output order is using an order by clause.

                L 1 Reply Last reply
                0
                • J J4amieC

                  Because it escapes me.

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

                  I added a five, that should even it out.

                  J4amieC wrote:

                  That's not strictly true, Tables will be stored in the order of their clustered index. This then forms the "default" order

                  The rows in a RDBMS are not interdependent, same goes for the columns. They might not be returned in the order that they're saved. Because there is no relation between the rows themselves (except that they belong to the same table) there is no order in the collection. This may vary depending on each implementation of course. Now, that's just theory that I swallowed a long time ago. I found that the most simple table in Access has a storage-order, and I have seen people abuse it. Most of the time, it's easier to add a custom column and sort on that. I've been reading up after your comment, and a clustered index[^] seems indeed to be the solution :)

                  Yes? :)

                  1 Reply Last reply
                  0
                  • I i j russell

                    That's not strictly true either! The only way to guarantee output order is using an order by clause.

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

                    That makes it also not strictly false :laugh:

                    public enum strictBool { true, false, EFileNotFound }

                    1 Reply Last reply
                    0
                    • S srikantha_nagaraj

                      Hi, Actually i want rows in the table in an order. How can i force the tables to keep that order? is there any command for that. Actually i am inserting the data row from asp.net front end.

                      A Offline
                      A Offline
                      Ashfield
                      wrote on last edited by
                      #10

                      You have already asked this question and had correct replies. A database does NOT guarantee the order records are returned in UNLESS you have an order by clause. If there is a clustered index or primary key then this is the default order, but even then it is NOT guaranteed (certanly by SQL Server) as when you have multiple worker processe, unless an order by is specified he results are returned as each worker process completes, which MAY not be the expected order. If you hav any further doubts try reading up on it, there are thousands of articles on google

                      Bob Ashfield Consultants Ltd Proud to be a 2009 Code Project MVP

                      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