question

Olive avatar image
Olive asked

Sql fails to rearrange the data in primary key column in ascending order and hence fails to return the actual max value.

I have a data table in SQL 2000 with a column_name Id(primary key) with int as data-type. When I insert values into it the it automatically gets rearranged in the following order.

Id                    
--                    
                    
1                    
10                    
11                    
2                    
3                    
4                    
5                    
6                    
7                    
8                    
9                    

The issue is when I uses the max(Id) function the value returned is 9 and not 11.

But when I created the same table in some other sql 2000,it worked in the proper way returning the actual max value of 11.Why this happens??Is there any method to change the property of the table so that I could retrieve the correct data?

sql-server-2000aggregates
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Madhivanan avatar image
Madhivanan answered

Looks like the datatype must be a varchar Check the datatype again

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.