473,320 Members | 1,887 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Order of insertion.

Hi .. another quey... i just noticed that the entries being done to
the sql server tables ( insert query in C# )are not in the correct
order.. the last entry is not always the last record in the table..
How to overcome it? i want all the records in the order of insertion...

Apr 4 '07 #1
3 1665
On Apr 4, 7:33 am, "Shum" <shumy...@gmail.comwrote:
Hi .. another quey... i just noticed that the entries being done to
the sql server tables ( insert query in C# )are not in the correct
order.. the last entry is not always the last record in the table..
How to overcome it? i want all the records in the order of insertion...
If you want a particular order, you should have a column in your table
which you sort by, and make sure that you insert entries with
appropriate values for that column.

Jon

Apr 4 '07 #2
To elaborate on what Jon said, Sql Server tables are sets. Yes, they
are visualized with an "order", but that visualization is implying something
that is not the case. When you insert rows into SQL Server, there is no
order to how they appear in the table. Yes, there is a physical
implementation of how the rows are stored, and there is an order to that,
but that order is not guaranteed.

This is why Jon's recommendation works, and you will have to do this
every time you query the data. You have to apply the sort that makes sense
to your application.

As a general recommendation, when working with data in SQL Server, don't
think of it in terms of tables (which have an implicit order from top to
bottom, and which also imply thinking in terms of cursors, which have an
order of traversal). Rather, you have to think about it in terms of set
operations.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Jon Skeet [C# MVP]" <sk***@pobox.comwrote in message
news:11**********************@y80g2000hsf.googlegr oups.com...
On Apr 4, 7:33 am, "Shum" <shumy...@gmail.comwrote:
>Hi .. another quey... i just noticed that the entries being done to
the sql server tables ( insert query in C# )are not in the correct
order.. the last entry is not always the last record in the table..
How to overcome it? i want all the records in the order of insertion...

If you want a particular order, you should have a column in your table
which you sort by, and make sure that you insert entries with
appropriate values for that column.

Jon

Apr 4 '07 #3

Hmmm.. makes sense... Thankyou for the explanation. I've learned a lot
through these groups..
On Apr 4, 10:34 pm, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.comwrote:
To elaborate on what Jon said, Sql Server tables are sets. Yes, they
are visualized with an "order", but that visualization is implying something
that is not the case. When you insert rows into SQL Server, there is no
order to how they appear in the table. Yes, there is a physical
implementation of how the rows are stored, and there is an order to that,
but that order is not guaranteed.

This is why Jon's recommendation works, and you will have to do this
every time you query the data. You have to apply the sort that makes sense
to your application.

As a general recommendation, when working with data in SQL Server, don't
think of it in terms of tables (which have an implicit order from top to
bottom, and which also imply thinking in terms of cursors, which have an
order of traversal). Rather, you have to think about it in terms of set
operations.

--
- Nicholas Paldino [.NET/C# MVP]
- m...@spam.guard.caspershouse.com

"Jon Skeet [C# MVP]" <s...@pobox.comwrote in messagenews:11**********************@y80g2000hsf.g ooglegroups.com...
On Apr 4, 7:33 am, "Shum" <shumy...@gmail.comwrote:
Hi .. another quey... i just noticed that the entries being done to
the sql server tables ( insert query in C# )are not in the correct
order.. the last entry is not always the last record in the table..
How to overcome it? i want all the records in the order of insertion...
If you want a particular order, you should have a column in your table
which you sort by, and make sure that you insert entries with
appropriate values for that column.
Jon- Hide quoted text -

- Show quoted text -

Apr 5 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

39
by: Nicolas Fleury | last post by:
In the following example: class MyMetaclass(type): pass class MyBaseType(object): __metaclass__ = MyMetaclass class MyType(MyBaseType): x = 4 y = 5 z = 6 Is there any way to modify...
12
by: Tanguy Fautré | last post by:
Hello, does std::multimap make any guarantee about the insertion order? for example: int main() { std::multimap<int, int> Map;
0
by: Murad Nayal | last post by:
Hello, I vaguely remember reading in the manual that the order of the retrieved rows in a response to a select statement is unpredictable (unless you use an order by clause). this possibly...
3
by: Amit | last post by:
Greetings All. One of the usages that I need is accessing the contents of the container that I am using in level order( which would mean breadth- first search approach for a binary tree) as...
20
by: Patrick Guio | last post by:
Dear all, I have some problem with insertion operator together with namespace. I have a header file foo.h containing declaration of classes, typedefs and insertion operators for the typedefs in...
5
by: John N. | last post by:
Hi All, Here I have a linked list each containing a char and is double linked. Then I have a pointer to an item in that list which is the current insertion point. In this funtion, the user...
1
by: dx | last post by:
Any ideas? I can't find any examples that support this. I'm thinking a solution may be something like inherting arraylist and containing a hashtable. or Inheriting NameObjectCollectionBase...
13
by: bevanward | last post by:
Hi All I am finding unexpected results when inserted into a newly created table that has a field of datatype int identity (1,1). Basically the order I sort on when inserting into the table is...
5
by: Naveen | last post by:
I am trying to write a conatiner which has std::map like methods but preserves the order of insertion. TO achieve this I thought of providing my own function for comparing the keys of the map....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.