wrong select or insert into ?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • adam

    wrong select or insert into ?

    hello

    I have strange problem.
    I write to MySQL data to table with one column of varchar(8000). I write
    750000 bytes, so it get 93 records of 8000 bytes and the last - 6000bytes.
    but what is strange - when I check length of this records:

    select len(column_name ) from table_name

    this last record ( which is 6000bytes length ) isn't on 94 position, but ...
    on 14 position !?
    The same, when I try to reads recods:

    select column name from table name

    this 6000 record apear on 14 position instead on 94 position

    It's important to me to get this record on proper ( last) position to not
    change ( complicating ) my C++ application algoritm.

    Could someone help me, please

    thanks in advance

    Adam

  • --CELKO--

    #2
    Re: wrong select or insert into ?

    >> It's important to me to get this record [sic] on proper (last) position [sic] to not change (complicating ) my C++ application algoritm. <<

    You never had a class or read a book on RDBMS, have you? The most
    fundamental concept in SQL is that there is no ordering to table!!

    Let's get back to the basics of an RDBMS. Rows are not records; fields
    are not columns; tables are not files; there is no sequential access or
    ordering in an RDBMS, so "first", "next" and "last" are totally
    meaningless. If you want to have an ordering, you need a column for it.

    Comment

    • adam

      #3
      Re: wrong select or insert into ?

      Yes- you are right. I did it - I added a field ( lp int ) with integer from
      1 to last row - and added to my question "order by lp"- there I get what I
      want.
      But there is some interesting - you say that there is no any ordering in
      RDBMS. So why I always get this row at 14 posiotion? There must be some
      "internal" ordering if SQL give me this row ALWAYS on 14 position - not on
      random position ( first time on 14 , next on 20 and so on ).

      best wishes

      Adam

      Comment

      • ZeldorBlat

        #4
        Re: wrong select or insert into ?

        Without an "order by" clause in your query, you're likely to get the
        rows out ordered by the clustered index, since that's the order that
        they're stored on the disk. That's probably why you're getting them in
        the same order everytime.

        BTW, before you chime in, Celko, I don't give two shits that "order by"
        is part of a cursor, not a query -- so save your breath.

        Comment

        • Dan Guzman

          #5
          Re: wrong select or insert into ?

          Without ORDER BY, SQL Server is free to return results in any sequence.
          This is usually the most efficient chosen by the cost-based optimizer.
          Ordering of results may vary depending on indexes, statistics, number of
          processors, concurrent queries, etc. The version, service pack, and hotfix
          level can also influence ordering due to potential optimizer changes.
          Consequently, one should never assume data will be returned in any
          particular order unless ORDER BY is specified.

          --
          Hope this helps.

          Dan Guzman
          SQL Server MVP

          "adam" <ereuseen@wp.pl > wrote in message
          news:dedop9$d60 $1@nemesis.news .tpi.pl...[color=blue]
          > Yes- you are right. I did it - I added a field ( lp int ) with integer
          > from
          > 1 to last row - and added to my question "order by lp"- there I get what I
          > want.
          > But there is some interesting - you say that there is no any ordering in
          > RDBMS. So why I always get this row at 14 posiotion? There must be some
          > "internal" ordering if SQL give me this row ALWAYS on 14 position - not on
          > random position ( first time on 14 , next on 20 and so on ).
          >
          > best wishes
          >
          > Adam
          >[/color]


          Comment

          Working...