Friday, March 9, 2012

Keeping Tables Sorted

we have a simple table

Key, Name, Address, City, State, Zip ............ect

I would like to keep this table sorted by Name, theirfore I won't have to sort my results with every querry.

I think I need to add something to my insert to tell my table - "Hay take Jones", open up the prober place and stick him in the proper spot.

Ex: We have Appleby and Robertson in our table now. My insert would tell SQL Server to take Jones, figure our where he belongs (alpha), and stick him in, resulting in.

Appleby
Jones
Robertson

This way I wont have to as the querry to sort stuff every time I reference this table, this will save lots and lots of overhead. and help keep my clients happy with quick(er) response.

thanks in advance -arthurCreate a clustered index for the table using the Name field:

1. In Enterprise Manger right-click the table and select All Tasks->Manage Indexes
2. Click "New..."
3. Select the Name field and give the index a name (e.g., Name). Check the box near the bottom marked "Clustered index". Click OK.

What this does is physically place the records in the table sorted according to the index. This isn't a free lunch however as the time taken to insert a new record will be a bit longer than it was before the index.|||THanks for the quick response, unfortantly, I don't have Enterprise manager (God I miss working for a big guy) Anyway .............., I do have something called SQL ExecMS, which dosn't do much more than allow me to view my table, but gives me a Sql interface, can you put the above into a SQL statement(s) (my forgetfullness of SQL is probably showing by now) Thanks again -arthur|||


CREATE CLUSTERED INDEX [SomeIndexName] ON [dbo].[TableName]([FieldName]) ON [PRIMARY]

No comments:

Post a Comment