Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 MSDE (2000)
 record sequence in table

Author  Topic 

isheikh
Starting Member

25 Posts

Posted - 2004-03-22 : 20:47:47
Hi,

I am using MSDE. I see in my table my record are order Alphabetically. I am wodering is it possible that you have records in your table in the sequences in which they get entered?

Thanks

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2004-03-22 : 20:49:44
A clustered index will do this for you. You should also take a look at the ORDER BY option.

Tara
Go to Top of Page

AjarnMark
SQL Slashing Gunting Master

3246 Posts

Posted - 2004-03-23 : 14:06:21
If you want them in the order they were entered (assuming this means INSERTed) then put the clustered index or ORDER BY on either an IDENTITY* field, or I think better yet would be a datetime field with a default value of getdate() so it automatically gets populated on INSERT (but not UPDATE).

* Warning: The subject of whether to ever use an IDENTITY field is a hotly debated topic in the SQL Server world. If you are interested, you can search the forums here and find threads with hundreds of posts on the subject.

--------------------------------------------------------------
Find more words of wisdom at [url]http://weblogs.sqlteam.com/markc[/url]
Go to Top of Page

isheikh
Starting Member

25 Posts

Posted - 2004-03-25 : 09:14:50
thanks alot for both of your replies
Go to Top of Page

isheikh
Starting Member

25 Posts

Posted - 2004-04-09 : 01:10:49
I went to properties of my table and just to experiment set the order by to "First_name", but it did not work, records I noticed are in my table order by the primary key. I read about the order by clause in the help section it says "order by" tells in what order client side will see the records..in other words in which order they will be retirved....

Thanks
Go to Top of Page

Merkin
Funky Drop Bear Fearing SQL Dude!

4970 Posts

Posted - 2004-04-09 : 01:48:58
Use an order by clause, forget about the physical order of the rows.

Damian
Go to Top of Page

isheikh
Starting Member

25 Posts

Posted - 2004-04-09 : 08:49:43
thanks for your reply, no actually I want the records in my table in the same sequences in which they get inserted, thats why am tryig to set order clause on the table, but it did not work
Go to Top of Page

Merkin
Funky Drop Bear Fearing SQL Dude!

4970 Posts

Posted - 2004-04-09 : 09:19:20
WHy do you need to store the rows in a specific order ? What I am saying is you shouldn't worry about how they are stored, it doesn't matter.

You get the data OUT in the right order with an order by clause.

Damian
Go to Top of Page

AjarnMark
SQL Slashing Gunting Master

3246 Posts

Posted - 2004-04-09 : 17:39:56
I hesitate to bring this up, but I'm convinced that if I don't, someone else will, with fewer caveats, so here goes...

I'm totally in agreement with Damian on this. I only worry about the physical order of records stored in my database when I am optimizing for ultimate performance. The way you dictate the physical order of records in a table is by using a clustered index. But before applying this, you really, really, really need to read up on the idea, especially focusing on the performance impacts on both the insertion/updating as well as retrieval of the data because you could easily cause yourself more headaches than benefit if you set the clustered index wrong for your needs.

And even with a clustered index, I use the ORDER BY clause in my SELECT statements so that I always know what order they're in regardless of tuning work that is done.

--------------------------------------------------------------
Find more words of wisdom at [url]http://weblogs.sqlteam.com/markc[/url]
Go to Top of Page

isheikh
Starting Member

25 Posts

Posted - 2004-04-10 : 14:18:00
The reason I wanted that because sometime I go straight in my database, and it is easier to see what is going on if the records are in order by date instead of all mixed up.

But if you guys think that it is not a good idea and it may create further complications then I will not do that. I do have a order clause in my select statement and it works fine.

Thanks
Go to Top of Page
   

- Advertisement -