Avatar of rwheeler23
rwheeler23
Flag for United States of America asked on

MS SQL Tables with no index

I need to convert a cloud based database to an internal MS SQL 2008 database and one issue I have run into is that none of these tables have any indexes declared. Now this causes me concern for several reasons but the one that stands out immediately is that in new code I have written around one of tables requires a set of rows to appear in a certain order. So a simple query was select itemnmbr,itemdesc from my table where categoryid='XX' order by seq. Where what I thought what this would give me is all items that are in category XX sorted by the seq number. However, I quickly discovered that they do not use the seq number field. They are all zeroes. So much to my amazement the correct order is always achieved by simply select itemnmbr,itemdesc from my table where categoryid='XX'  with no order by clause. How is this possible? How can they be adding records to this table through their code and somehow always maintain the proper sort order without the use of an index? Is there some internal SQL database table structure element they are controlling?
Microsoft SQL Server 2008

Avatar of undefined
Last Comment
rwheeler23

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Dave Baldwin

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
Anthony Perkins

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
rwheeler23

ASKER
There is no identity column either. The old website is a collection of very small data tables. The biggest table is about 3000 records and items are grouped into category. All items within any group share common properties and it is these properties that concern me. These properties appear across the top of each page and provide detailed information as to how the item is configured. There are about 60 categories. I have be checking and so far every time I ask for the list they come out in the order desired. I just do not know how that is happening. The good news is on my side there will be a column that puts items in the proper order so the real proof of the pudding will be after I insert all the items into my table, I do a cross comparison with the old table to see if they all came over in the correct order.
SOLUTION
dqmq

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
rwheeler23

ASKER
I agree completely. I was surprised when I saw nothing but zeroes in the seq column. When I first looked at the structure of the table I said, that is the field I need. Then I looked at the data and was surprised. This is a one time transfer. So what I will do is have a copy of the order on the old website and then manually compare the sort order to the new web site. If I find any differences I will update my table.
SOLUTION
DcpKing

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Scott Pletcher

>> you cannot rely on the order unless you stipulate one in an order by clause. <<

That could depend on the specific db being used.  

While the ANSI standard states that for relational dbs, and other relational dbs follow that rule, there is no guarantee that whatever db engine is used to store the original data does not have its own rule that is different.  We don't know if the original db is even relational.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
DcpKing

This is correct, Scott - even something like SQL Server will appear to behave like this in certain circumstances!

rwheeler23: Although knowing the environment for the original developers would be nice, you're constrained to working with your environment - SQL Server - to achieve your goals. I would suggest that you really do need to key and index your tables.

Which version will you be using, BTW? 2012 has a nice addition for the SELECT statement that help when you're supporting a paged display (on a web page, for example).
rwheeler23

ASKER
Sorry for the trady reponse but I have been out of town and out of touch.

http://www.hostmysite.com/

This is were the current MS SQL database resides. I was able to connect to it using an instance of my instance of SQL Sever 2008. I have imported the entire database and will proceed with trying to analyze the table relationships.
rwheeler23

ASKER
All I know is that they did come out in the correct order with no order by clause. I dumped them all into my SQL table this time indexed with a sequence number. Thank you everyone for responding.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.