Unix Technical Forum

SEO

vBulletin Search Engine Optimization


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > SQL Server Data Warehousing

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-27-2008, 07:10 PM
=?Utf-8?B?YmFsYQ==?=
 
Posts: n/a
Default Row of data interchaged automatically when import from MS xl 2003

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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-27-2008, 07:10 PM
=?Utf-8?B?TUw=?=
 
Posts: n/a
Default RE: Row of data interchaged automatically when import from MS xl 2003

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/
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-27-2008, 07:10 PM
=?Utf-8?B?YmFsYQ==?=
 
Posts: n/a
Default RE: Row of data interchaged automatically when import from MS xl 2



"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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-27-2008, 07:10 PM
Phil
 
Posts: n/a
Default Re: Row of data interchaged automatically when import from MS xl 2

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" <bala@discussions.microsoft.com> wrote in message
news:986BE491-E58E-4AE8-A378-726439EC09E8@microsoft.com...
>
>
> "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.



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-27-2008, 07:10 PM
=?Utf-8?B?TUw=?=
 
Posts: n/a
Default Re: Row of data interchaged automatically when import from MS xl 2

I'm sorry, but what you're saying is a myth.
http://www.sqlmag.com/Articles/Artic...2886.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/
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 02-27-2008, 07:10 PM
=?Utf-8?B?TUw=?=
 
Posts: n/a
Default RE: Row of data interchaged automatically when import from MS xl 2

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/
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 02-27-2008, 07:10 PM
=?Utf-8?B?YmFsYQ==?=
 
Posts: n/a
Default RE: Row of data interchaged automatically when import from MS xl 2



"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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 02-27-2008, 07:10 PM
Phil
 
Posts: n/a
Default Re: Row of data interchaged automatically when import from MS xl 2

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

http://www.sqlmag.com/Article/Articl...ver_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" <ML@discussions.microsoft.com> wrote in message
news:C39708B8-01AE-43D5-93A2-C8E3CC0B1B4F@microsoft.com...
> I'm sorry, but what you're saying is a myth.
> http://www.sqlmag.com/Articles/Artic...2886.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/



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 02-27-2008, 07:10 PM
Phil
 
Posts: n/a
Default Re: Row of data interchaged automatically when import from MS xl 2

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" <phil.austin@clarity-integration.com> wrote in message
news:O8I9FWjaIHA.3400@TK2MSFTNGP03.phx.gbl...
> Interesting but only really makes sense when read with part II as well:
>
> http://www.sqlmag.com/Article/Articl...ver_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" <ML@discussions.microsoft.com> wrote in message
> news:C39708B8-01AE-43D5-93A2-C8E3CC0B1B4F@microsoft.com...
>> I'm sorry, but what you're saying is a myth.
>> http://www.sqlmag.com/Articles/Artic...2886.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/

>
>



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 02-27-2008, 07:10 PM
=?Utf-8?B?TUw=?=
 
Posts: n/a
Default Re: Row of data interchaged automatically when import from MS xl 2

Getting *close* is not getting *there*.


ML

---
Matija Lah, SQL Server MVP
http://milambda.blogspot.com/
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 09:38 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
UnixAdminTalk.com

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588