Home > Archive > Microsoft SQL Server forum > August 2005 > wrong select or insert into ?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author wrong select or insert into ?
adam

2005-08-22, 8:23 pm

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--

2005-08-22, 8:23 pm

>> 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.

adam

2005-08-22, 8:23 pm

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

ZeldorBlat

2005-08-23, 3:23 am

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.

Dan Guzman

2005-08-24, 7:24 am

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@ne
mesis.news.tpi.pl...
> 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
>



Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com