Welcome to dbForumz.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Row of data interchaged automatically when import from MS ..

 
   Database Forums (Home) -> Data Warehouse RSS
Next:  What are some methods of getting the "match ..  
Author Message
bala

External


Since: Feb 05, 2008
Posts: 3



(Msg. 1) Posted: Tue Feb 05, 2008 7:31 pm
Post subject: Row of data interchaged automatically when import from MS xl 2003
Archived from groups: microsoft>public>sqlserver>datawarehouse (more info?)

Hi all,

I import MS Excel 2003 spread sheet in MS SQL Server 2000 through MS SQL
Server 2000 Enterprise Manager. In excel two sheets (sheet1 and sheet2) of
data is there. I imported first sheet data in first time in relevant table of
database and done second sheet of data in next time. My excel file have 2000
rows and 100 columns of data. All the data are imported in relevant
attributes cells in good manner. But the first 16 rows are sorted
automatically. I am trying to say that first row data is match with my excel
file. But second row data have gone to 7th row and 7th row have gone to 5th
row like that. Except that 16 rows all other data are matched with my MS
Excel 2003 file. I need the data sequence what I have in my excel file. What
is the problem occurred? How can I solve this?
Actually the problem occurred in first some rows so I found the mistake. If
it comes after 1000 rows how can I predict and rectify?
Please help me. I don't have more knowledge in MS SQL Server 2000.
Thanks,

With Regards,
bala.

 >> Stay informed about: Row of data interchaged automatically when import from MS .. 
Back to top
Login to vote
ML

External


Since: Mar 30, 2006
Posts: 121



(Msg. 2) Posted: Thu Feb 07, 2008 4:52 am
Post subject: RE: Row of data interchaged automatically when import from MS xl 2003 [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Sets are unordered which means there is no inherent order in SQL objects
(tables, views). For instance: the order of inserted rows is not preserved,
and when retrieving rows from the table (or view) the order is not guaranteed
unless the ORDER BY clause is used in the referencing (SELECT) query.

If you need to preserve the order of your data then you must design your own
method of doing so. The usual practice is either to use an existing column to
sort the rowset or add a column (i.e. directly to the source or through
staging) to store the original row order.

In Excel you could just add a column and fill it with numbers designating
the original row order.

Do not rely on the IDENTITY column in a SQL table to preserve the order as
the optimizer is free to choose the way rows are inserted, which means (as
mentioned) before that the order may not be preserved.


ML

---
Matija Lah, SQL Server MVP
http://milambda.blogspot.com/

 >> Stay informed about: Row of data interchaged automatically when import from MS .. 
Back to top
Login to vote
bala

External


Since: Feb 05, 2008
Posts: 3



(Msg. 3) Posted: Thu Feb 07, 2008 7:46 am
Post subject: RE: Row of data interchaged automatically when import from MS xl 2 [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

"ML" wrote:

> Sets are unordered which means there is no inherent order in SQL objects
> (tables, views). For instance: the order of inserted rows is not preserved,
> and when retrieving rows from the table (or view) the order is not guaranteed
> unless the ORDER BY clause is used in the referencing (SELECT) query.
>
> If you need to preserve the order of your data then you must design your own
> method of doing so. The usual practice is either to use an existing column to
> sort the rowset or add a column (i.e. directly to the source or through
> staging) to store the original row order.
>
> In Excel you could just add a column and fill it with numbers designating
> the original row order.
>
> Do not rely on the IDENTITY column in a SQL table to preserve the order as
> the optimizer is free to choose the way rows are inserted, which means (as
> mentioned) before that the order may not be preserved.
>
>
> ML
>
> ---
> Matija Lah, SQL Server MVP
> http://milambda.blogspot.com/

thank you very much. Your answer is very help full to me. I add one column
in both xl and in that sql table and give row no to it. Then import the data
from xl. Now the sequence is very correct with my xl file that is the row
hasn't changed it's order. But I have no permission to add one column in my
sql table. So after imported the data I deleted that column what I have added
extra in sql table then again all rows are changed it's order.
Actually one customized tool has given for entering data to that sql
database. If I entered the data through that tool then the row order may be
correct (what order I has entered) or we can't preserve the row order? please
help me.
 >> Stay informed about: Row of data interchaged automatically when import from MS .. 
Back to top
Login to vote
ML

External


Since: Mar 30, 2006
Posts: 121



(Msg. 4) Posted: Thu Feb 07, 2008 11:06 am
Post subject: RE: Row of data interchaged automatically when import from MS xl 2 [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Look at your data and your data model again. Perhaps there already is a
column (one or more) that you can use to determine the correct order of rows.

Remember: order is guaranteed only if you use the ORDER BY clause.


ML

---
Matija Lah, SQL Server MVP
http://milambda.blogspot.com/
 >> Stay informed about: Row of data interchaged automatically when import from MS .. 
Back to top
Login to vote
Phil

External


Since: Nov 29, 2007
Posts: 12



(Msg. 5) Posted: Thu Feb 07, 2008 3:01 pm
Post subject: Re: Row of data interchaged automatically when import from MS xl 2 [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Maybe I'm missing something here but the use of a clustered index can
enforce ordering on a table as the following demonstrates:

CREATE TABLE OrderTest
(

OrderKey int not null,

SomeOtherJunk varchar(50) not null

)

CREATE CLUSTERED INDEX IX_OrderTest_01 ON OrderTest(OrderKey)

INSERT OrderTest

VALUES(100, 'William')

INSERT OrderTest

VALUES(1, 'Phil')

INSERT OrderTest

VALUES(10, 'Rich')

INSERT OrderTest

VALUES(1000, 'Sam')

SELECT * FROM OrderTest

By using the DESC keyword in the CREATE INDEX statement you can reverse the
ordering.

If you are trying to ensure the sort order of a text field (char, varchar
etc) it gets a little trickier - ordering in the clustered index is also
dependant on things like the collation settings. On my install of SQL for
example, if you change the clustered index above so it applies to the
SomeOtherJunk field, it comes out in the general latin case-insensitive,
accent-sensitive ordering; Phil, Rich, Sam, William
(SQL_Latin1_General_CP1_CI_AS). A different collation may give you different
ordering (although in this case probably not).

--
Phil
http://www.clarity-integration.com
http://www.phil-austin.blogspot.com

"bala" wrote in message

>
>
> "ML" wrote:
>
>> Sets are unordered which means there is no inherent order in SQL objects
>> (tables, views). For instance: the order of inserted rows is not
>> preserved,
>> and when retrieving rows from the table (or view) the order is not
>> guaranteed
>> unless the ORDER BY clause is used in the referencing (SELECT) query.
>>
>> If you need to preserve the order of your data then you must design your
>> own
>> method of doing so. The usual practice is either to use an existing
>> column to
>> sort the rowset or add a column (i.e. directly to the source or through
>> staging) to store the original row order.
>>
>> In Excel you could just add a column and fill it with numbers designating
>> the original row order.
>>
>> Do not rely on the IDENTITY column in a SQL table to preserve the order
>> as
>> the optimizer is free to choose the way rows are inserted, which means
>> (as
>> mentioned) before that the order may not be preserved.
>>
>>
>> ML
>>
>> ---
>> Matija Lah, SQL Server MVP
>> http://milambda.blogspot.com/
>
> thank you very much. Your answer is very help full to me. I add one column
> in both xl and in that sql table and give row no to it. Then import the
> data
> from xl. Now the sequence is very correct with my xl file that is the row
> hasn't changed it's order. But I have no permission to add one column in
> my
> sql table. So after imported the data I deleted that column what I have
> added
> extra in sql table then again all rows are changed it's order.
> Actually one customized tool has given for entering data to that sql
> database. If I entered the data through that tool then the row order may
> be
> correct (what order I has entered) or we can't preserve the row order?
> please
> help me.
 >> Stay informed about: Row of data interchaged automatically when import from MS .. 
Back to top
Login to vote
ML

External


Since: Mar 30, 2006
Posts: 121



(Msg. 6) Posted: Thu Feb 07, 2008 3:01 pm
Post subject: Re: Row of data interchaged automatically when import from MS xl 2 [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

I'm sorry, but what you're saying is a myth.
http://www.sqlmag.com/Articles/ArticleID/92886/92886.html?Ad=1

The *only way* to retrieve a sorted set from a SQL object is to use the
ORDER BY clause. There are no alternatives, although some methods give that
false appearance. In fact, without using an ORDER BY clause the order in
which the rows are returned is completely unpredictable.


ML

---
Matija Lah, SQL Server MVP
http://milambda.blogspot.com/
 >> Stay informed about: Row of data interchaged automatically when import from MS .. 
Back to top
Login to vote
bala

External


Since: Feb 05, 2008
Posts: 3



(Msg. 7) Posted: Thu Feb 07, 2008 7:51 pm
Post subject: RE: Row of data interchaged automatically when import from MS xl 2 [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

"ML" wrote:

> Look at your data and your data model again. Perhaps there already is a
> column (one or more) that you can use to determine the correct order of rows.
>
> Remember: order is guaranteed only if you use the ORDER BY clause.
>
>
> ML
>
> ---
> Matija Lah, SQL Server MVP
> http://milambda.blogspot.com/

Hi,

Thank you so much. Your answer is very very helpful to me. The article which
one you recommend is really superb. Thanks a lot.
 >> Stay informed about: Row of data interchaged automatically when import from MS .. 
Back to top
Login to vote
Phil

External


Since: Nov 29, 2007
Posts: 12



(Msg. 8) Posted: Fri Feb 08, 2008 6:10 am
Post subject: Re: Row of data interchaged automatically when import from MS xl 2 [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Interesting but only really makes sense when read with part II as well:

http://www.sqlmag.com/Article/ArticleID/92887/sql_server_92887.html

"to guarantee consistency, in all cases besides when
NOLOCK or TABLOCK are specified, SQL Server scans the data
in index order by following the linked list."

If this wasn't the case the ASC and DESC keywords would be meaningless. So I
think you're still OK to use a clustered index as long as you're careful to
avoid query hints, even though there are more subtleties under the covers.

Phil.

"ML" wrote in message

> I'm sorry, but what you're saying is a myth.
> http://www.sqlmag.com/Articles/ArticleID/92886/92886.html?Ad=1
>
> The *only way* to retrieve a sorted set from a SQL object is to use the
> ORDER BY clause. There are no alternatives, although some methods give
> that
> false appearance. In fact, without using an ORDER BY clause the order in
> which the rows are returned is completely unpredictable.
>
>
> ML
>
> ---
> Matija Lah, SQL Server MVP
> http://milambda.blogspot.com/
 >> Stay informed about: Row of data interchaged automatically when import from MS .. 
Back to top
Login to vote
Phil

External


Since: Nov 29, 2007
Posts: 12



(Msg. 9) Posted: Fri Feb 08, 2008 6:10 am
Post subject: Re: Row of data interchaged automatically when import from MS xl 2 [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Don't get me wrong btw - if you want to ensure ordering in a_query_use ORDER
BY. The closest you can get to logically ordering a table is by using a
clustered index.

Phil.

"Phil" wrote in message

> Interesting but only really makes sense when read with part II as well:
>
> http://www.sqlmag.com/Article/ArticleID/92887/sql_server_92887.html
>
> "to guarantee consistency, in all cases besides when
> NOLOCK or TABLOCK are specified, SQL Server scans the data
> in index order by following the linked list."
>
> If this wasn't the case the ASC and DESC keywords would be meaningless. So
> I think you're still OK to use a clustered index as long as you're careful
> to avoid query hints, even though there are more subtleties under the
> covers.
>
> Phil.
>
> "ML" wrote in message
>
>> I'm sorry, but what you're saying is a myth.
>> http://www.sqlmag.com/Articles/ArticleID/92886/92886.html?Ad=1
>>
>> The *only way* to retrieve a sorted set from a SQL object is to use the
>> ORDER BY clause. There are no alternatives, although some methods give
>> that
>> false appearance. In fact, without using an ORDER BY clause the order in
>> which the rows are returned is completely unpredictable.
>>
>>
>> ML
>>
>> ---
>> Matija Lah, SQL Server MVP
>> http://milambda.blogspot.com/
>
>
 >> Stay informed about: Row of data interchaged automatically when import from MS .. 
Back to top
Login to vote
ML

External


Since: Mar 30, 2006
Posts: 121



(Msg. 10) Posted: Fri Feb 08, 2008 6:10 am
Post subject: Re: Row of data interchaged automatically when import from MS xl 2 [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Back to top
Login to vote
Display posts from previous:   
   Database Forums (Home) -> Data Warehouse All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]