January 22, 2007 at 1:55 pm
Hello,
Say I have a table with records:
1 aaaa
2 bbbb
3 cccc
4 dddd
given dddd, how do I know it's No4 record?
Thanks.
January 22, 2007 at 3:10 pm
You shouldn't care. If you create two indexes one in ascending and one in descending orders. In one index it would be in rec no 1 and one it would be in record no 4. What is the significance of knowing this.
Tom
January 22, 2007 at 3:34 pm
add an identity column before apply any index, you can get the original order with numbers
January 22, 2007 at 3:39 pm
Hi there,
Not 100% sure if I understand quite what you are trying to do but...
A record's position within a table is not necessaraly defined by SQL Server. If you have a clustered index (http://msdn2.microsoft.com/en-us/library/aa933131(SQL.80).aspx) then the order of the records on the disk is defined by the ordering of the index.
If you want to be able to get "4" having been given "dddd" then I would suggest that you add an id column to the table which is defined as an IDENTITY (1, 1) column (see http://msdn2.microsoft.com/en-us/library/aa258255(SQL.80).aspx) you can then SELECT id FROM table WHERE col1 = 'dddd'.
You might also want to look at putting an index over your text column if you have any performance problems.
- James
--
James Moore
Red Gate Software
--
James Moore
Red Gate Software Ltd
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply