Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Importing data in exact order

Status
Not open for further replies.

FaStOnE

Programmer
Jan 4, 2002
14
US
I need to import some comma delimited data into a table, BUT I need it to enter in arival order. Currently, I can use or setup the bcp or Bulk Insert and pull the data and it is listed in the Table in random order. What I need is data that is stored in the following format...

REC 1
REC 2
REC 3
REC 4
.
.
.
REC (n)

to arrive in the SAME format, not random like...

REC 1
REC 3
REC 2
REC 4
.
.
.
REC (n)

Any suggestions as to how I can accomplish this?

Thanks!!

Rick
 
The data will be inserted in the order it exists in the import file. However, SQL does not guarantee order in tables. The relational model assumes unordered sets. When you select from a table or view a table there is no guarantee of order unless you use an Order By clause.

You can force the order by creating a clustered index on the column(s) you want to order by. A clustered index is created on the data pages so the physical order of the data is the same as the index order.

You can also use the Order By clause on a Select statment to order the result set. Terry L. Broadbent - DBA
Computing Links:
faq183-874 contains "Suggestions for Getting Quick and Appropriate Answers" to your questions.
 
Terry,

Thanks for the info. The import data that I need to bring in does NOT have a column that I can specify an index order on. So, I can't index on anything specific. I have to read the original data in the CSV file in the order it already exists. I just find that it would be easier to maintain sort, modify, etc... if I pull it into a SQL Table then push it back out.

Is there a way to "ORDER BY" with say a "Natural" order?

Rick
 
How would you define "natural order?" You can only order by columns or derivatives of column data.

If the data you import has no column to order by you could add an identity column to the table. This would allow you to sort in the import order. You would import to all table columns except the identity column. Terry L. Broadbent - DBA
Computing Links:
faq183-874 contains "Suggestions for Getting Quick and Appropriate Answers" to your questions.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top